mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-02-01 11:56:48 +01:00
Use crypto UUID if available
This commit is contained in:
parent
a20b2a566d
commit
d1ed983106
@ -2,7 +2,7 @@ const fetch = require('node-fetch').default;
|
|||||||
const https = require('https');
|
const https = require('https');
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const { readSecret, SECRET_KEYS } = require('./secrets');
|
const { readSecret, SECRET_KEYS } = require('./secrets');
|
||||||
const { getConfigValue } = require('../util');
|
const { getConfigValue, uuidv4 } = require('../util');
|
||||||
const { jsonParser } = require('../express-common');
|
const { jsonParser } = require('../express-common');
|
||||||
|
|
||||||
const DEEPLX_URL_DEFAULT = 'http://127.0.0.1:1188/translate';
|
const DEEPLX_URL_DEFAULT = 'http://127.0.0.1:1188/translate';
|
||||||
@ -103,7 +103,6 @@ router.post('/google', jsonParser, async (request, response) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
router.post('/yandex', jsonParser, async (request, response) => {
|
router.post('/yandex', jsonParser, async (request, response) => {
|
||||||
|
|
||||||
const chunks = request.body.chunks;
|
const chunks = request.body.chunks;
|
||||||
const lang = request.body.lang;
|
const lang = request.body.lang;
|
||||||
|
|
||||||
@ -120,7 +119,7 @@ router.post('/yandex', jsonParser, async (request, response) => {
|
|||||||
inputText += chunk;
|
inputText += chunk;
|
||||||
}
|
}
|
||||||
params.append('lang', lang);
|
params.append('lang', lang);
|
||||||
const ucid = crypto.randomUUID().replaceAll('-', '');
|
const ucid = uuidv4().replaceAll('-', '');
|
||||||
|
|
||||||
console.log('Input text: ' + inputText);
|
console.log('Input text: ' + inputText);
|
||||||
|
|
||||||
@ -135,9 +134,9 @@ router.post('/yandex', jsonParser, async (request, response) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!result.ok) {
|
if (!result.ok) {
|
||||||
const error = await result.message();
|
const error = await result.text();
|
||||||
console.log('Yandex error: ', result.code, error);
|
console.log('Yandex error: ', result.statusText, error);
|
||||||
return response.sendStatus(result.code);
|
return response.sendStatus(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
const json = await result.json();
|
const json = await result.json();
|
||||||
|
@ -293,7 +293,14 @@ const color = {
|
|||||||
white: (mess) => color.byNum(mess, 37),
|
white: (mess) => color.byNum(mess, 37),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a random UUIDv4 string.
|
||||||
|
* @returns {string} A UUIDv4 string
|
||||||
|
*/
|
||||||
function uuidv4() {
|
function uuidv4() {
|
||||||
|
if ('randomUUID' in crypto) {
|
||||||
|
return crypto.randomUUID();
|
||||||
|
}
|
||||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
||||||
const r = Math.random() * 16 | 0;
|
const r = Math.random() * 16 | 0;
|
||||||
const v = c === 'x' ? r : (r & 0x3 | 0x8);
|
const v = c === 'x' ? r : (r & 0x3 | 0x8);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user