aboutsummaryrefslogtreecommitdiffstats
path: root/names/server.js
diff options
context:
space:
mode:
Diffstat (limited to 'names/server.js')
-rw-r--r--names/server.js8
1 files changed, 5 insertions, 3 deletions
diff --git a/names/server.js b/names/server.js
index aff4e54..77d758c 100644
--- a/names/server.js
+++ b/names/server.js
@@ -28,7 +28,7 @@ import { mnemonicToSeedSync } from '@scure/bip39';
import { lnBackend } from '../bridge/ln.js';
import { ArkManager } from '../src/ark/manager.js';
import { fetchPreview } from './preview.js';
-import { translate, languages } from './translate.js';
+import { translate, translateDeepl, languages } from './translate.js';
import { decodeAddress } from '../src/ark/proto.js';
import { decodeNoffer } from '../src/noffer.js';
import { decodeBolt11 } from '../src/ark/lightning.js';
@@ -904,7 +904,7 @@ const json = (body, status = 200) => {
headers: {
'content-type': 'application/json',
'access-control-allow-origin': '*',
- 'access-control-allow-headers': 'content-type,authorization',
+ 'access-control-allow-headers': 'content-type,authorization,x-deepl-key',
'access-control-allow-methods': 'GET,POST,DELETE,OPTIONS',
},
});
@@ -1056,7 +1056,9 @@ Bun.serve({
let body = null;
try { body = await req.json(); } catch {}
if (!body || typeof body.text !== 'string' || typeof body.target !== 'string') return json({ error: 'bad request' }, 400);
- try { return json(await translate(body.text, body.target, body.source)); }
+ // a reader's own DeepL key rides in a header: passed on, never kept or logged
+ const dk = (req.headers.get('x-deepl-key') || '').trim();
+ try { return json(dk ? await translateDeepl(body.text, body.target, dk) : await translate(body.text, body.target, body.source)); }
catch (e) { return json({ error: e.message || 'translation failed' }, e.status || 503); }
}