Don't crash the server on trying to display corrupted past chat

This commit is contained in:
Cohee 2023-08-08 17:56:13 +03:00
parent 5ac375097b
commit 9a7654598e
1 changed files with 4 additions and 2 deletions

View File

@ -1986,14 +1986,16 @@ app.post("/getallchatsofcharacter", jsonParser, function (request, response) {
ii--;
if (lastLine) {
let jsonData = json5.parse(lastLine);
if (jsonData.name !== undefined || jsonData.character_name !== undefined) {
let jsonData = tryParse(lastLine);
if (jsonData && (jsonData.name !== undefined || jsonData.character_name !== undefined)) {
chatData[i] = {};
chatData[i]['file_name'] = file;
chatData[i]['file_size'] = fileSizeInKB;
chatData[i]['chat_items'] = itemCounter - 1;
chatData[i]['mes'] = jsonData['mes'] || '[The chat is empty]';
chatData[i]['last_mes'] = jsonData['send_date'] || Date.now();
} else {
console.log('Found an invalid or corrupted chat file: ' + fullPathAndFile);
}
}
if (ii === 0) {