Fix uuidv4 on Node 18 Closes #2718

3806dcf9fbd767819398acb8890f8bad6483cce7

Cohee <18619528+Cohee1207@users.noreply.github.com>

2 files changed, +18 -18Ignore whitespace
src/endpoints/translate.js+16 -16
@@ -110,27 +110,27 @@ router.post('/google', jsonParser, async (request, response) => {
110110});
111111
112112router.post('/yandex', jsonParser, async (request, response) => {
113- const chunks = request.body.chunks;
113+ try {
114114 const langchunks = request.body.langchunks;
115+ const lang = request.body.lang;
115116
116117 if (!chunks || !lang) {
117118 return response.sendStatus(400);
118119 }
119120
120121 // reconstruct original text to log
121122 let inputText = '';
122123
123124 const params = new URLSearchParams();
124125 for (const chunk of chunks) {
125126 params.append('text', chunk);
126127 inputText += chunk;
127128 }
128129 params.append('lang', lang);
129130 const ucid = uuidv4().replaceAll('-', '');
130131
131132 console.log('Input text: ' + inputText);
132133
133- try {
134134 const result = await fetch(`https://translate.yandex.net/api/v1/tr.json/translate?ucid=${ucid}&srv=android&format=text`, {
135135 method: 'POST',
136136 body: params,
src/util.js+2 -2
@@ -299,8 +299,8 @@ const color = {
299299 * @returns {string} A UUIDv4 string
300300 */
301301function uuidv4() {
302302 if ('crypto' in global && 'randomUUID' in global.crypto) {
303303 return global.crypto.randomUUID();
304304 }
305305 return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
306306 const r = Math.random() * 16 | 0;