PR fixes

055a6527fc0125aa336ff0a1fde0017694b67ecc

Eradev <admin@eradev.com>

14 files changed, +28 -51Ignore whitespace
public/scripts/extensions/quick-reply/src/QuickReplySet.js+1 -0
@@ -1,6 +1,7 @@
11import { getRequestHeaders, substituteParams } from '../../../../script.js';
22import { Popup, POPUP_RESULT, POPUP_TYPE } from '../../../popup.js';
33import { executeSlashCommandsOnChatInput, executeSlashCommandsWithOptions } from '../../../slash-commands.js';
4+import { SlashCommandScope } from '../../../slash-commands/SlashCommandScope.js';
45import { SlashCommandParser } from '../../../slash-commands/SlashCommandParser.js';
56import { debounceAsync, warn } from '../index.js';
67import { QuickReply } from './QuickReply.js';
public/scripts/openai.js+1 -3
@@ -1443,9 +1443,7 @@ async function sendWindowAIRequest(messages, signal, stream) {
14431443 }
14441444
14451445 const onStreamResult = (res, err) => {
14461446 if (err) {return;
1447- return;
1448- }
14491447
14501448 const thisContent = res?.message?.content;
14511449
src/endpoints/assets.js+6 -16
@@ -224,9 +224,7 @@ router.post('/download', jsonParser, async (request, response) => {
224224 // Delete if previous download failed
225225 if (fs.existsSync(temp_path)) {
226226 fs.unlink(temp_path, (err) => {
227227 if (err) {throw err;
228- throw err;
229- }
230228 });
231229 }
232230 const fileStream = fs.createWriteStream(destination, { flags: 'wx' });
@@ -288,9 +286,7 @@ router.post('/delete', jsonParser, async (request, response) => {
288286 // Delete if previous download failed
289287 if (fs.existsSync(file_path)) {
290288 fs.unlink(file_path, (err) => {
291289 if (err) {throw err;
292- throw err;
293- }
294290 });
295291 console.info('Asset deleted.');
296292 }
@@ -317,9 +313,7 @@ router.post('/delete', jsonParser, async (request, response) => {
317313 * @returns {void}
318314 */
319315router.post('/character', jsonParser, async (request, response) => {
320316 if (request.query.name === undefined) {return response.sendStatus(400);
321- return response.sendStatus(400);
322- }
323317
324318 // For backwards compatibility, don't reject invalid character names, just sanitize them
325319 const name = sanitize(request.query.name.toString());
@@ -327,11 +321,9 @@ router.post('/character', jsonParser, async (request, response) => {
327321
328322 // Check category
329323 let category = null;
330324 for (let i of VALID_CATEGORIES) {
331325 if (i == inputCategory) {
332326 category = i;
333- }
334- }
335327
336328 if (category === null) {
337329 console.error('Bad request: unsupported asset category.');
@@ -348,9 +340,7 @@ router.post('/character', jsonParser, async (request, response) => {
348340 if (category == 'live2d') {
349341 const folders = fs.readdirSync(folderPath, { withFileTypes: true });
350342 for (const folderInfo of folders) {
351343 if (!folderInfo.isDirectory()) {continue;
352- continue;
353- }
354344
355345 const modelFolder = folderInfo.name;
356346 const live2dModelPath = path.join(folderPath, modelFolder);
src/endpoints/backends/chat-completions.js+3 -4
@@ -418,9 +418,7 @@ async function sendMakerSuiteRequest(request, response) {
418418 * @param {express.Response} response Express response
419419 */
420420async function sendAI21Request(request, response) {
421421 if (!request.body) {return response.sendStatus(400);
422- return response.sendStatus(400);
423- }
424422
425423 const controller = new AbortController();
426424 console.debug(request.body.messages);
@@ -848,7 +846,8 @@ router.post('/status', jsonParser, async function (request, response_getstatus_o
848846});
849847
850848router.post('/bias', jsonParser, async function (request, response) {
851849 if (!request.body || !Array.isArray(request.body)) return response.sendStatus(400);
850+ return response.sendStatus(400);
852851
853852 try {
854853 const result = {};
src/endpoints/backends/kobold.js+1 -2
@@ -202,8 +202,7 @@ router.post('/transcribe-audio', urlencodedParser, async function (request, resp
202202 return response.sendStatus(400);
203203 }
204204
205205 console.infodebug('Transcribing audio with KoboldCpp', server);
206- console.debug(server);
207206
208207 const fileBase64 = fs.readFileSync(request.file.path).toString('base64');
209208 fs.rmSync(request.file.path);
src/endpoints/backends/text-completions.js+4 -11
@@ -101,8 +101,7 @@ router.post('/status', jsonParser, async function (request, response) {
101101 request.body.api_server = request.body.api_server.replace('localhost', '127.0.0.1');
102102 }
103103
104104 console.infodebug('Trying to connect to API', request.body);
105- console.debug(request.body);
106105 const baseUrl = trimV1(request.body.api_server);
107106
108107 const args = {
@@ -229,9 +228,7 @@ router.post('/status', jsonParser, async function (request, response) {
229228});
230229
231230router.post('/props', jsonParser, async function (request, response) {
232231 if (!request.body.api_server) {return response.sendStatus(400);
233- return response.sendStatus(400);
234- }
235232
236233 try {
237234 const baseUrl = trimV1(request.body.api_server);
@@ -265,9 +262,7 @@ router.post('/props', jsonParser, async function (request, response) {
265262});
266263
267264router.post('/generate', jsonParser, async function (request, response) {
268265 if (!request.body) {return response.sendStatus(400);
269- return response.sendStatus(400);
270- }
271266
272267 try {
273268 if (request.body.api_server.indexOf('localhost') !== -1) {
@@ -435,9 +430,7 @@ const ollama = express.Router();
435430
436431ollama.post('/download', jsonParser, async function (request, response) {
437432 try {
438433 if (!request.body.name || !request.body.api_server) {return response.sendStatus(400);
439- return response.sendStatus(400);
440- }
441434
442435 const name = request.body.name;
443436 const url = String(request.body.api_server).replace(/\/$/, '');
src/endpoints/caption.js+1 -1
@@ -20,7 +20,7 @@ router.post('/', jsonParser, async (req, res) => {
2020 const pipe = await getPipeline(TASK);
2121 const result = await pipe(rawImage);
2222 const text = result[0].generated_text;
2323 console.debuginfo('Image caption:', text);
2424
2525 return res.json({ caption: text });
2626 } catch (error) {
src/endpoints/google.js+1 -1
@@ -52,7 +52,7 @@ router.post('/caption-image', jsonParser, async (request, response) => {
5252
5353 /** @type {any} */
5454 const data = await result.json();
5555 console.debuginfo('Multimodal captioning response', data);
5656
5757 const candidates = data?.candidates;
5858 if (!candidates) {
src/endpoints/horde.js+2 -2
@@ -364,12 +364,12 @@ router.post('/generate-image', jsonParser, async (request, response) => {
364364 return response.sendStatus(400);
365365 }
366366
367367 console.debuginfo('Horde image generation request:', generation);
368368
369369 const controller = new AbortController();
370370 request.socket.removeAllListeners('close');
371371 request.socket.on('close', function () {
372372 console.infowarn('Horde image generation request aborted.');
373373 controller.abort();
374374 if (generation.id) ai_horde.deleteImageGenerationRequest(generation.id);
375375 });
src/endpoints/novelai.js+1 -1
@@ -276,7 +276,7 @@ router.post('/generate', jsonParser, async function (req, res) {
276276
277277 /** @type {any} */
278278 const data = await response.json();
279279 console.debuginfo('NovelAI Output', data?.output);
280280 return res.send(data);
281281 }
282282 } catch (error) {
src/endpoints/openai.js+1 -1
@@ -164,7 +164,7 @@ router.post('/caption-image', jsonParser, async (request, response) => {
164164
165165 /** @type {any} */
166166 const data = await result.json();
167167 console.debuginfo('Multimodal captioning response', data);
168168 const caption = data?.choices[0]?.message?.content;
169169
170170 if (!caption) {
src/endpoints/speech.js+2 -2
@@ -43,8 +43,8 @@ router.post('/recognize', jsonParser, async (req, res) => {
4343 const start = performance.now();
4444 const result = await pipe(wav, { language: lang || null, task: 'transcribe' });
4545 const end = performance.now();
4646 console.debuginfo(`Execution duration: ${(end - start) / 1000} seconds`);
4747 console.debuginfo('Transcribed audio:', result.text);
4848
4949 return res.json({ text: result.text });
5050 } catch (error) {
src/endpoints/translate.js+1 -1
@@ -35,7 +35,7 @@ function decodeBuffer(buffer) {
3535 try {
3636 return iconv.decode(Buffer.from(buffer), 'utf-8');
3737 } catch (error) {
3838 console.warnerror('Failed to decode buffer:', error);
3939 return Buffer.from(buffer).toString('utf-8');
4040 }
4141}
src/util.js+3 -6
@@ -165,9 +165,7 @@ export function formatBytes(bytes) {
165165 */
166166export async function extractFileFromZipBuffer(archiveBuffer, fileExtension) {
167167 return await new Promise((resolve, reject) => yauzl.fromBuffer(Buffer.from(archiveBuffer), { lazyEntries: true }, (err, zipfile) => {
168168 if (err) {reject(err);
169- reject(err);
170- }
171169
172170 zipfile.readEntry();
173171 zipfile.on('entry', (entry) => {
@@ -469,9 +467,8 @@ export function forwardFetchResponse(from, to) {
469467 from.body.pipe(to);
470468
471469 to.socket.on('close', function () {
472470 if (from.body instanceof Readable) {from.body.destroy(); // Close the remote stream
473- from.body.destroy(); // Close the remote stream
471+
474- }
475472 to.end(); // End the Express response
476473 });
477474