refactor: Split config files

This commit is contained in:
Gabe
2025-09-01 18:56:48 +08:00
parent c4fba1c905
commit 2bfb27f346
17 changed files with 821 additions and 863 deletions

View File

@@ -1,5 +1,5 @@
import queryString from "query-string";
import { URL_BAIDU_TRANSAPI, DEFAULT_USER_AGENT } from "../config";
import { DEFAULT_USER_AGENT } from "../config";
export const genBaidu = async ({ text, from, to }) => {
const data = {
@@ -9,6 +9,7 @@ export const genBaidu = async ({ text, from, to }) => {
source: "txt",
};
const input = "https://fanyi.baidu.com/transapi";
const init = {
headers: {
// Origin: "https://fanyi.baidu.com",
@@ -19,5 +20,5 @@ export const genBaidu = async ({ text, from, to }) => {
body: queryString.stringify(data),
};
return [URL_BAIDU_TRANSAPI, init];
return [input, init];
};

View File

@@ -1,5 +1,3 @@
import { URL_DEEPLFREE_TRAN } from "../config";
let id = 1e4 * Math.round(1e4 * Math.random());
export const genDeeplFree = ({ text, from, to }) => {
@@ -37,6 +35,7 @@ export const genDeeplFree = ({ text, from, to }) => {
(id + 3) % 13 === 0 || (id + 5) % 29 === 0 ? 'method" : "' : 'method": "'
);
const input = "https://www2.deepl.com/jsonrpc";
const init = {
headers: {
"Content-Type": "application/json",
@@ -54,5 +53,5 @@ export const genDeeplFree = ({ text, from, to }) => {
body,
};
return [URL_DEEPLFREE_TRAN, init];
return [input, init];
};

View File

@@ -3,7 +3,6 @@ import { fetchData } from "../libs/fetch";
import {
URL_CACHE_TRAN,
KV_SALT_SYNC,
URL_GOOGLE_TRAN,
OPT_LANGS_BAIDU,
OPT_LANGS_TENCENT,
OPT_LANGS_SPECIAL,
@@ -54,7 +53,7 @@ export const apiGoogleLangdetect = async (text) => {
tl: "zh-CN",
q: text,
};
const input = `${URL_GOOGLE_TRAN}?${queryString.stringify(params)}`;
const input = `https://translate.googleapis.com/translate_a/single?${queryString.stringify(params)}`;
const init = {
headers: {
"Content-type": "application/json",

View File

@@ -26,9 +26,6 @@ import {
OPT_TRANS_CUSTOMIZE_3,
OPT_TRANS_CUSTOMIZE_4,
OPT_TRANS_CUSTOMIZE_5,
URL_MICROSOFT_TRAN,
URL_TENCENT_TRANSMART,
URL_VOLCENGINE_TRAN,
INPUT_PLACE_URL,
INPUT_PLACE_FROM,
INPUT_PLACE_TO,
@@ -107,7 +104,7 @@ const genMicrosoft = async ({ text, from, to }) => {
to,
"api-version": "3.0",
};
const input = `${URL_MICROSOFT_TRAN}?${queryString.stringify(params)}`;
const input = `https://api-edge.cognitive.microsofttranslator.com/translate?${queryString.stringify(params)}`;
const init = {
headers: {
"Content-type": "application/json",
@@ -199,6 +196,7 @@ const genTencent = ({ text, from, to }) => {
},
};
const input = "https://transmart.qq.com/api/imt";
const init = {
headers: {
"Content-Type": "application/json",
@@ -210,7 +208,7 @@ const genTencent = ({ text, from, to }) => {
body: JSON.stringify(data),
};
return [URL_TENCENT_TRANSMART, init];
return [input, init];
};
const genVolcengine = ({ text, from, to }) => {
@@ -220,6 +218,7 @@ const genVolcengine = ({ text, from, to }) => {
text: text,
};
const input = "https://translate.volcengine.com/crx/translate/v1";
const init = {
headers: {
"Content-type": "application/json",
@@ -228,7 +227,7 @@ const genVolcengine = ({ text, from, to }) => {
body: JSON.stringify(data),
};
return [URL_VOLCENGINE_TRAN, init];
return [input, init];
};
const genOpenAI = ({