Add default URL for Lingva translator

This commit is contained in:
Cohee
2024-12-23 21:34:16 +02:00
parent c4a92c95e6
commit 8394b97600

View File

@ -11,6 +11,7 @@ import { jsonParser } from '../express-common.js';
const DEEPLX_URL_DEFAULT = 'http://127.0.0.1:1188/translate';
const ONERING_URL_DEFAULT = 'http://127.0.0.1:4990/translate';
const LINGVA_DEFAULT = 'https://lingva.ml/api/v1';
export const router = express.Router();
@ -189,7 +190,12 @@ router.post('/yandex', jsonParser, async (request, response) => {
router.post('/lingva', jsonParser, async (request, response) => {
try {
const baseUrl = readSecret(request.user.directories, SECRET_KEYS.LINGVA_URL);
const secretUrl = readSecret(request.user.directories, SECRET_KEYS.LINGVA_URL);
const baseUrl = secretUrl || LINGVA_DEFAULT;
if (!secretUrl && baseUrl === ONERING_URL_DEFAULT) {
console.log('Lingva URL is using default value.', LINGVA_DEFAULT);
}
if (!baseUrl) {
console.log('Lingva URL is not configured.');
@ -307,6 +313,10 @@ router.post('/onering', jsonParser, async (request, response) => {
console.log('OneRing URL is using default value.', ONERING_URL_DEFAULT);
}
if (request.body.lang === 'pt-BR' || request.body.lang === 'pt-PT') {
request.body.lang = 'pt';
}
const text = request.body.text;
const from_lang = request.body.from_lang;
const to_lang = request.body.to_lang;