fix: custom option

This commit is contained in:
Gabe Yuan
2024-04-18 09:48:07 +08:00
parent 130f1deed1
commit 2ae5d01d5c
2 changed files with 4 additions and 4 deletions

View File

@@ -266,7 +266,7 @@ export const apiTranslate = async ({
isSame = to === res.from;
const { customOption } = apiSetting;
if (customOption.trim()) {
if (customOption?.trim()) {
try {
const opt = JSON.parse(customOption);
const textPattern = opt.resPattern?.text;

View File

@@ -278,13 +278,13 @@ const genCloudflareAI = ({ text, from, to, url, key }) => {
return [url, init];
};
const genCustom = ({ text, from, to, url, key, customOption = "" }) => {
const genCustom = ({ text, from, to, url, key, customOption }) => {
const replaceInput = (str) =>
str
.replaceAll(INPUT_PLACE_URL, url)
.replaceAll(INPUT_PLACE_FROM, from)
.replaceAll(INPUT_PLACE_TO, to)
.replaceAll(INPUT_PLACE_TEXT, text)
.replaceAll(INPUT_PLACE_TEXT, text.replaceAll(`"`, `\n`))
.replaceAll(INPUT_PLACE_KEY, key);
const data = {
text,
@@ -303,7 +303,7 @@ const genCustom = ({ text, from, to, url, key, customOption = "" }) => {
}
url = replaceInput(url);
if (customOption.trim()) {
if (customOption?.trim()) {
try {
const opt = JSON.parse(replaceInput(customOption));
opt.url && (url = opt.url);