mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
add bing translate
This commit is contained in:
@@ -2,6 +2,7 @@ const fetch = require('node-fetch').default;
|
||||
const https = require('https');
|
||||
const { readSecret, SECRET_KEYS } = require('./secrets');
|
||||
const { generateRequestUrl, normaliseResponse } = require('google-translate-api-browser');
|
||||
const bingTranslateApi = require('bing-translate-api')
|
||||
|
||||
const DEEPLX_URL_DEFAULT = 'http://127.0.0.1:1188/translate';
|
||||
const ONERING_URL_DEFAULT = 'http://127.0.0.1:4990/translate';
|
||||
@@ -241,6 +242,28 @@ function registerEndpoints(app, jsonParser) {
|
||||
return response.sendStatus(500);
|
||||
}
|
||||
});
|
||||
|
||||
app.post('/api/translate/bing', jsonParser, async (request, response) => {
|
||||
const text = request.body.text;
|
||||
let lang = request.body.lang
|
||||
if (request.body.lang === 'zh-CN') {
|
||||
lang = 'zh-Hans'
|
||||
}
|
||||
|
||||
if (!text || !lang) {
|
||||
return response.sendStatus(400);
|
||||
}
|
||||
|
||||
console.log('Input text: ' + text);
|
||||
|
||||
bingTranslateApi.translate(text, null, lang).then(result => {
|
||||
console.log('Translated text: ' + result.translation);
|
||||
return response.send(result.translation);
|
||||
}).catch(err => {
|
||||
console.log("Translation error: " + err.message);
|
||||
return response.sendStatus(500);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
Reference in New Issue
Block a user