fix: revert old google translate api

This commit is contained in:
Gabe
2025-06-26 11:13:51 +08:00
parent a6cb5544f8
commit eaa47af269
3 changed files with 26 additions and 23 deletions

View File

@@ -58,16 +58,26 @@ const keyPick = (translator, key = "", cacheMap) => {
};
const genGoogle = ({ text, from, to, url, key }) => {
const body = JSON.stringify([[ [text], from, to ], "wt_lib"]);
const init = {
method: "POST",
headers: {
"Content-Type": "application/json+protobuf",
"X-Goog-API-Key": key,
},
body,
const params = {
client: "gtx",
dt: "t",
dj: 1,
ie: "UTF-8",
sl: from,
tl: to,
q: text,
};
return [url, init];
const input = `${url}?${queryString.stringify(params)}`;
const init = {
headers: {
"Content-type": "application/json",
},
};
if (key) {
init.headers.Authorization = `Bearer ${key}`;
}
return [input, init];
};
const genMicrosoft = async ({ text, from, to }) => {