Fix incorrect message counter

e0e60a1d007edb870c64a69c7cc8a0b1fa1f71c0

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

1 files changed, +4 -4Ignore whitespace
src/endpoints/chats.js+4 -4
@@ -73,7 +73,7 @@ function formatBytes(bytes) {
73function getPreviewMessage(messages) {73function getPreviewMessage(messages) {
74 const strlen = 300;74 const strlen = 300;
75 const lastMessage = messages[messages.length - 1]?.mes;75 const lastMessage = messages[messages.length - 1]?.mes;
76 76
77 if (!lastMessage) {77 if (!lastMessage) {
78 return '';78 return '';
79 }79 }
@@ -609,13 +609,13 @@ router.post('/search', jsonParser, function (request, response) {
609 }609 }
610610
611 const results = [];611 const results = [];
612 612
613 // Search logic613 // Search logic
614 for (const chatFile of chatFiles) {614 for (const chatFile of chatFiles) {
615 const data = fs.readFileSync(chatFile.path, 'utf8');615 const data = fs.readFileSync(chatFile.path, 'utf8');
616 const messages = data.split('\n')616 const messages = data.split('\n')
617 .map(line => { try { return JSON.parse(line); } catch (_) { return null; } })617 .map(line => { try { return JSON.parse(line); } catch (_) { return null; } })
618 .filter(x => x);618 .filter(x => x && typeof x.mes === 'string');
619619
620 if (messages.length === 0) {620 if (messages.length === 0) {
621 continue;621 continue;
@@ -662,4 +662,4 @@ router.post('/search', jsonParser, function (request, response) {
662 console.error('Chat search error:', error);662 console.error('Chat search error:', error);
663 return response.status(500).json({ error: 'Search failed' });663 return response.status(500).json({ error: 'Search failed' });
664 }664 }
665});
665 \ No newline at end of file \ No newline at end of file
665});