fix: deeplfree api

This commit is contained in:
Gabe
2025-10-01 23:22:14 +08:00
parent d18b31692b
commit 039566ded5
3 changed files with 37 additions and 40 deletions

View File

@@ -1,7 +1,6 @@
import queryString from "query-string";
import { DEFAULT_USER_AGENT } from "../config";
export const genBaidu = async ({ texts, from, to }) => {
export const genBaidu = ({ texts, from, to }) => {
const data = {
from,
to,
@@ -9,16 +8,12 @@ export const genBaidu = async ({ texts, from, to }) => {
source: "txt",
};
const input = "https://fanyi.baidu.com/transapi";
const init = {
headers: {
// Origin: "https://fanyi.baidu.com",
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
"User-Agent": DEFAULT_USER_AGENT,
},
method: "POST",
body: queryString.stringify(data),
const url = "https://fanyi.baidu.com/transapi";
const headers = {
// Origin: "https://fanyi.baidu.com",
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
"User-Agent": DEFAULT_USER_AGENT,
};
return [input, init];
return { url, data, headers };
};

View File

@@ -7,7 +7,9 @@ export const genDeeplFree = ({ texts, from, to }) => {
timestamp = timestamp + (iCount - (timestamp % iCount));
id++;
let body = JSON.stringify({
const url = "https://www2.deepl.com/jsonrpc";
const data = {
jsonrpc: "2.0",
method: "LMT_handle_texts",
params: {
@@ -29,30 +31,20 @@ export const genDeeplFree = ({ texts, from, to }) => {
},
],
},
});
body = body.replace(
'method":"',
(id + 3) % 13 === 0 || (id + 5) % 29 === 0 ? 'method" : "' : 'method": "'
);
const input = "https://www2.deepl.com/jsonrpc";
const init = {
headers: {
"Content-Type": "application/json",
Accept: "*/*",
"x-app-os-name": "iOS",
"x-app-os-version": "16.3.0",
"Accept-Language": "en-US,en;q=0.9",
"Accept-Encoding": "gzip, deflate, br",
"x-app-device": "iPhone13,2",
"User-Agent": "DeepL-iOS/2.9.1 iOS 16.3.0 (iPhone13,2)",
"x-app-build": "510265",
"x-app-version": "2.9.1",
},
method: "POST",
body,
};
return [input, init];
const headers = {
"Content-Type": "application/json",
Accept: "*/*",
"x-app-os-name": "iOS",
"x-app-os-version": "16.3.0",
"Accept-Language": "en-US,en;q=0.9",
"Accept-Encoding": "gzip, deflate, br",
"x-app-device": "iPhone13,2",
"User-Agent": "DeepL-iOS/2.9.1 iOS 16.3.0 (iPhone13,2)",
"x-app-build": "510265",
"x-app-version": "2.9.1",
};
return { url, data, headers };
};

View File

@@ -24,6 +24,7 @@ import {
// INPUT_PLACE_TEXT,
INPUT_PLACE_KEY,
INPUT_PLACE_MODEL,
DEFAULT_USER_AGENT,
} from "../config";
import { msAuth } from "../libs/auth";
import { genDeeplFree } from "./deepl";
@@ -227,8 +228,7 @@ const genTencent = ({ texts, from, to }) => {
const url = "https://transmart.qq.com/api/imt";
const headers = {
"Content-Type": "application/json",
"user-agent":
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36",
"user-agent": DEFAULT_USER_AGENT,
referer: "https://transmart.qq.com/zh-CN/index",
};
@@ -551,7 +551,17 @@ const genInit = ({
headers,
};
if (method !== "GET" && method !== "HEAD" && data) {
Object.assign(init, { body: JSON.stringify(data) });
let body = JSON.stringify(data);
const id = data?.params?.id;
if (id) {
body = body.replace(
'method":"',
(id + 3) % 13 === 0 || (id + 5) % 29 === 0
? 'method" : "'
: 'method": "'
);
}
Object.assign(init, { body });
}
return [url, init, userMsg];