use deepl authorization header.

This commit is contained in:
piuvas 2025-12-22 11:08:28 -03:00
parent 20e8998e57
commit d75c176207
No known key found for this signature in database

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,
});