merge: use deepl authorization header. (!1255)

View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/1255

Approved-by: dakkar <dakkar@thenautilus.net>
Approved-by: Charlotte <timo.herngreen@gmail.com>
This commit is contained in:
dakkar 2025-12-23 10:51:46 +00:00
commit 8bb68cbf69

View file

@ -142,17 +142,18 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
// DeepL/DeepLX handling
if (this.serverSettings.deeplAuthKey || deeplFreeInstance) {
const params = new URLSearchParams();
if (this.serverSettings.deeplAuthKey) params.append('auth_key', this.serverSettings.deeplAuthKey);
params.append('text', note.text);
params.append('target_lang', targetLang);
const headers: Record<string, string> = {
'Content-Type': 'application/x-www-form-urlencoded',
Accept: 'application/json, */*',
};
if (this.serverSettings.deeplAuthKey) headers['Authorization'] = `DeepL-Auth-Key ${this.serverSettings.deeplAuthKey}`;
const endpoint = deeplFreeInstance ?? ( this.serverSettings.deeplIsPro ? 'https://api.deepl.com/v2/translate' : 'https://api-free.deepl.com/v2/translate' );
const res = await this.httpRequestService.send(endpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Accept: 'application/json, */*',
},
headers,
body: params.toString(),
timeout: this.serverSettings.translationTimeout,
});