| 110 | 110 | }); |
| 111 | 111 | |
| 112 | 112 | router.post('/yandex', jsonParser, async (request, response) => { |
| 113 | | - const chunks = request.body.chunks; |
| 113 | + try { |
| 114 | 114 | const langchunks = request.body.langchunks; |
| 115 | + const lang = request.body.lang; |
| 115 | 116 | |
| 116 | 117 | if (!chunks || !lang) { |
| 117 | 118 | return response.sendStatus(400); |
| 118 | 119 | } |
| 119 | 120 | |
| 120 | 121 | // reconstruct original text to log |
| 121 | 122 | let inputText = ''; |
| 122 | 123 | |
| 123 | 124 | const params = new URLSearchParams(); |
| 124 | 125 | for (const chunk of chunks) { |
| 125 | 126 | params.append('text', chunk); |
| 126 | 127 | inputText += chunk; |
| 127 | 128 | } |
| 128 | 129 | params.append('lang', lang); |
| 129 | 130 | const ucid = uuidv4().replaceAll('-', ''); |
| 130 | 131 | |
| 131 | 132 | console.log('Input text: ' + inputText); |
| 132 | 133 | |
| 133 | | - try { |
| 134 | 134 | const result = await fetch(`https://translate.yandex.net/api/v1/tr.json/translate?ucid=${ucid}&srv=android&format=text`, { |
| 135 | 135 | method: 'POST', |
| 136 | 136 | body: params, |