fix: custom option
This commit is contained in:
@@ -266,7 +266,7 @@ export const apiTranslate = async ({
|
|||||||
isSame = to === res.from;
|
isSame = to === res.from;
|
||||||
|
|
||||||
const { customOption } = apiSetting;
|
const { customOption } = apiSetting;
|
||||||
if (customOption.trim()) {
|
if (customOption?.trim()) {
|
||||||
try {
|
try {
|
||||||
const opt = JSON.parse(customOption);
|
const opt = JSON.parse(customOption);
|
||||||
const textPattern = opt.resPattern?.text;
|
const textPattern = opt.resPattern?.text;
|
||||||
|
|||||||
@@ -278,13 +278,13 @@ const genCloudflareAI = ({ text, from, to, url, key }) => {
|
|||||||
return [url, init];
|
return [url, init];
|
||||||
};
|
};
|
||||||
|
|
||||||
const genCustom = ({ text, from, to, url, key, customOption = "" }) => {
|
const genCustom = ({ text, from, to, url, key, customOption }) => {
|
||||||
const replaceInput = (str) =>
|
const replaceInput = (str) =>
|
||||||
str
|
str
|
||||||
.replaceAll(INPUT_PLACE_URL, url)
|
.replaceAll(INPUT_PLACE_URL, url)
|
||||||
.replaceAll(INPUT_PLACE_FROM, from)
|
.replaceAll(INPUT_PLACE_FROM, from)
|
||||||
.replaceAll(INPUT_PLACE_TO, to)
|
.replaceAll(INPUT_PLACE_TO, to)
|
||||||
.replaceAll(INPUT_PLACE_TEXT, text)
|
.replaceAll(INPUT_PLACE_TEXT, text.replaceAll(`"`, `\n`))
|
||||||
.replaceAll(INPUT_PLACE_KEY, key);
|
.replaceAll(INPUT_PLACE_KEY, key);
|
||||||
const data = {
|
const data = {
|
||||||
text,
|
text,
|
||||||
@@ -303,7 +303,7 @@ const genCustom = ({ text, from, to, url, key, customOption = "" }) => {
|
|||||||
}
|
}
|
||||||
url = replaceInput(url);
|
url = replaceInput(url);
|
||||||
|
|
||||||
if (customOption.trim()) {
|
if (customOption?.trim()) {
|
||||||
try {
|
try {
|
||||||
const opt = JSON.parse(replaceInput(customOption));
|
const opt = JSON.parse(replaceInput(customOption));
|
||||||
opt.url && (url = opt.url);
|
opt.url && (url = opt.url);
|
||||||
|
|||||||
Reference in New Issue
Block a user