Translate: Add DeepL support (#2721)

Co-authored-by: v <vendicated@riseup.net>
This commit is contained in:
Ashton 2024-08-01 07:10:27 -05:00 committed by GitHub
parent 2382294e8b
commit f8b01c1a31
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 277 additions and 37 deletions

View file

@ -0,0 +1,29 @@
/*
* 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) };
}
}