feat: custom request

This commit is contained in:
Gabe Yuan
2024-04-17 22:35:12 +08:00
parent e369321c66
commit 9455670e80
5 changed files with 57 additions and 45 deletions

View File

@@ -264,6 +264,25 @@ export const apiTranslate = async ({
case OPT_TRANS_CUSTOMIZE_5:
trText = res.text;
isSame = to === res.from;
const { customOption } = apiSetting;
if (customOption.trim()) {
try {
const opt = JSON.parse(customOption);
const textPattern = opt.resPattern?.text;
const fromPattern = opt.resPattern?.from;
if (textPattern) {
trText = textPattern.split(".").reduce((pre, cur) => pre[cur], res);
}
if (fromPattern) {
isSame =
to === fromPattern.split(".").reduce((pre, cur) => pre[cur], res);
}
} catch (err) {
throw new Error(`custom option parse err: ${err}`);
}
}
break;
default:
}