From 1a16957519f75b5eab2ae08dbe5ae422a7c48dc5 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Mon, 23 Dec 2024 21:51:33 +0200 Subject: [PATCH] Construct Lingva URL using url-join --- src/endpoints/translate.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/endpoints/translate.js b/src/endpoints/translate.js index 370e24229..9bfadb57f 100644 --- a/src/endpoints/translate.js +++ b/src/endpoints/translate.js @@ -4,6 +4,7 @@ import fetch from 'node-fetch'; import express from 'express'; import { translate as bingTranslate } from 'bing-translate-api'; import iconv from 'iconv-lite'; +import urlJoin from 'url-join'; import { readSecret, SECRET_KEYS } from './secrets.js'; import { getConfigValue, uuidv4 } from '../util.js'; @@ -220,7 +221,7 @@ router.post('/lingva', jsonParser, async (request, response) => { console.log('Input text: ' + text); try { - const url = `${baseUrl}/auto/${lang}/${encodeURIComponent(text)}`; + const url = urlJoin(baseUrl, 'auto', lang, encodeURIComponent(text)); const result = await fetch(url); if (!result.ok) {