mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-01-05 21:46:49 +01:00
parent
a0a1847634
commit
3806dcf9fb
@ -110,27 +110,27 @@ router.post('/google', jsonParser, async (request, response) => {
|
||||
});
|
||||
|
||||
router.post('/yandex', jsonParser, async (request, response) => {
|
||||
const chunks = request.body.chunks;
|
||||
const lang = request.body.lang;
|
||||
|
||||
if (!chunks || !lang) {
|
||||
return response.sendStatus(400);
|
||||
}
|
||||
|
||||
// reconstruct original text to log
|
||||
let inputText = '';
|
||||
|
||||
const params = new URLSearchParams();
|
||||
for (const chunk of chunks) {
|
||||
params.append('text', chunk);
|
||||
inputText += chunk;
|
||||
}
|
||||
params.append('lang', lang);
|
||||
const ucid = uuidv4().replaceAll('-', '');
|
||||
|
||||
console.log('Input text: ' + inputText);
|
||||
|
||||
try {
|
||||
const chunks = request.body.chunks;
|
||||
const lang = request.body.lang;
|
||||
|
||||
if (!chunks || !lang) {
|
||||
return response.sendStatus(400);
|
||||
}
|
||||
|
||||
// reconstruct original text to log
|
||||
let inputText = '';
|
||||
|
||||
const params = new URLSearchParams();
|
||||
for (const chunk of chunks) {
|
||||
params.append('text', chunk);
|
||||
inputText += chunk;
|
||||
}
|
||||
params.append('lang', lang);
|
||||
const ucid = uuidv4().replaceAll('-', '');
|
||||
|
||||
console.log('Input text: ' + inputText);
|
||||
|
||||
const result = await fetch(`https://translate.yandex.net/api/v1/tr.json/translate?ucid=${ucid}&srv=android&format=text`, {
|
||||
method: 'POST',
|
||||
body: params,
|
||||
|
@ -299,8 +299,8 @@ const color = {
|
||||
* @returns {string} A UUIDv4 string
|
||||
*/
|
||||
function uuidv4() {
|
||||
if ('randomUUID' in crypto) {
|
||||
return crypto.randomUUID();
|
||||
if ('crypto' in global && 'randomUUID' in global.crypto) {
|
||||
return global.crypto.randomUUID();
|
||||
}
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
||||
const r = Math.random() * 16 | 0;
|
||||
|
Loading…
Reference in New Issue
Block a user