From 2ae5d01d5cbccaafb597187a39c32767558e09ab Mon Sep 17 00:00:00 2001 From: Gabe Yuan Date: Thu, 18 Apr 2024 09:48:07 +0800 Subject: [PATCH] fix: custom option --- src/apis/index.js | 2 +- src/libs/req.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/apis/index.js b/src/apis/index.js index d6c5828..85d9573 100644 --- a/src/apis/index.js +++ b/src/apis/index.js @@ -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; diff --git a/src/libs/req.js b/src/libs/req.js index 0b54a3c..b4af67a 100644 --- a/src/libs/req.js +++ b/src/libs/req.js @@ -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);