fix: deeplfree api
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
import queryString from "query-string";
|
|
||||||
import { DEFAULT_USER_AGENT } from "../config";
|
import { DEFAULT_USER_AGENT } from "../config";
|
||||||
|
|
||||||
export const genBaidu = async ({ texts, from, to }) => {
|
export const genBaidu = ({ texts, from, to }) => {
|
||||||
const data = {
|
const data = {
|
||||||
from,
|
from,
|
||||||
to,
|
to,
|
||||||
@@ -9,16 +8,12 @@ export const genBaidu = async ({ texts, from, to }) => {
|
|||||||
source: "txt",
|
source: "txt",
|
||||||
};
|
};
|
||||||
|
|
||||||
const input = "https://fanyi.baidu.com/transapi";
|
const url = "https://fanyi.baidu.com/transapi";
|
||||||
const init = {
|
const headers = {
|
||||||
headers: {
|
// Origin: "https://fanyi.baidu.com",
|
||||||
// Origin: "https://fanyi.baidu.com",
|
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
|
||||||
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
|
"User-Agent": DEFAULT_USER_AGENT,
|
||||||
"User-Agent": DEFAULT_USER_AGENT,
|
|
||||||
},
|
|
||||||
method: "POST",
|
|
||||||
body: queryString.stringify(data),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return [input, init];
|
return { url, data, headers };
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,7 +7,9 @@ export const genDeeplFree = ({ texts, from, to }) => {
|
|||||||
timestamp = timestamp + (iCount - (timestamp % iCount));
|
timestamp = timestamp + (iCount - (timestamp % iCount));
|
||||||
id++;
|
id++;
|
||||||
|
|
||||||
let body = JSON.stringify({
|
const url = "https://www2.deepl.com/jsonrpc";
|
||||||
|
|
||||||
|
const data = {
|
||||||
jsonrpc: "2.0",
|
jsonrpc: "2.0",
|
||||||
method: "LMT_handle_texts",
|
method: "LMT_handle_texts",
|
||||||
params: {
|
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 };
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import {
|
|||||||
// INPUT_PLACE_TEXT,
|
// INPUT_PLACE_TEXT,
|
||||||
INPUT_PLACE_KEY,
|
INPUT_PLACE_KEY,
|
||||||
INPUT_PLACE_MODEL,
|
INPUT_PLACE_MODEL,
|
||||||
|
DEFAULT_USER_AGENT,
|
||||||
} from "../config";
|
} from "../config";
|
||||||
import { msAuth } from "../libs/auth";
|
import { msAuth } from "../libs/auth";
|
||||||
import { genDeeplFree } from "./deepl";
|
import { genDeeplFree } from "./deepl";
|
||||||
@@ -227,8 +228,7 @@ const genTencent = ({ texts, from, to }) => {
|
|||||||
const url = "https://transmart.qq.com/api/imt";
|
const url = "https://transmart.qq.com/api/imt";
|
||||||
const headers = {
|
const headers = {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"user-agent":
|
"user-agent": DEFAULT_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",
|
|
||||||
referer: "https://transmart.qq.com/zh-CN/index",
|
referer: "https://transmart.qq.com/zh-CN/index",
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -551,7 +551,17 @@ const genInit = ({
|
|||||||
headers,
|
headers,
|
||||||
};
|
};
|
||||||
if (method !== "GET" && method !== "HEAD" && data) {
|
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];
|
return [url, init, userMsg];
|
||||||
|
|||||||
Reference in New Issue
Block a user