From e0e60a1d007edb870c64a69c7cc8a0b1fa1f71c0 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Thu, 31 Oct 2024 20:07:23 +0200 Subject: [PATCH] Fix incorrect message counter --- src/endpoints/chats.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/endpoints/chats.js b/src/endpoints/chats.js index a458f6674..6cc165b0f 100644 --- a/src/endpoints/chats.js +++ b/src/endpoints/chats.js @@ -73,7 +73,7 @@ function formatBytes(bytes) { function getPreviewMessage(messages) { const strlen = 300; const lastMessage = messages[messages.length - 1]?.mes; - + if (!lastMessage) { return ''; } @@ -609,13 +609,13 @@ router.post('/search', jsonParser, function (request, response) { } const results = []; - + // Search logic for (const chatFile of chatFiles) { const data = fs.readFileSync(chatFile.path, 'utf8'); const messages = data.split('\n') .map(line => { try { return JSON.parse(line); } catch (_) { return null; } }) - .filter(x => x); + .filter(x => x && typeof x.mes === 'string'); if (messages.length === 0) { continue; @@ -662,4 +662,4 @@ router.post('/search', jsonParser, function (request, response) { console.error('Chat search error:', error); return response.status(500).json({ error: 'Search failed' }); } -}); \ No newline at end of file +});