29 lines
849 B
TypeScript
29 lines
849 B
TypeScript
/*
|
|
* Vencord, a Discord client mod
|
|
* Copyright (c) 2024 Vendicated and contributors
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
*/
|
|
|
|
import { IpcMainInvokeEvent } from "electron";
|
|
|
|
export async function makeDeeplTranslateRequest(_: IpcMainInvokeEvent, pro: boolean, apiKey: string, payload: string) {
|
|
const url = pro
|
|
? "https://api.deepl.com/v2/translate"
|
|
: "https://api-free.deepl.com/v2/translate";
|
|
|
|
try {
|
|
const res = await fetch(url, {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
"Authorization": `DeepL-Auth-Key ${apiKey}`
|
|
},
|
|
body: payload
|
|
});
|
|
|
|
const data = await res.text();
|
|
return { status: res.status, data };
|
|
} catch (e) {
|
|
return { status: -1, data: String(e) };
|
|
}
|
|
}
|