From 457475baf1bfc971e00858dd350acd393dca4312 Mon Sep 17 00:00:00 2001 From: ceruleandeep Date: Fri, 20 Sep 2024 08:57:48 +1000 Subject: [PATCH] Save uploaded data unchanged if Chub conversion fails for any reason Avoid non-resolving promise in /characters/chats readline if chat file is empty --- src/endpoints/characters.js | 6 ++++++ src/endpoints/chats.js | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/endpoints/characters.js b/src/endpoints/characters.js index 9324b4b87..3082e0f54 100644 --- a/src/endpoints/characters.js +++ b/src/endpoints/characters.js @@ -1027,6 +1027,12 @@ router.post('/chats', jsonParser, async function (request, response) { const stats = fs.statSync(pathToFile); const fileSizeInKB = `${(stats.size / 1024).toFixed(2)}kb`; + if (stats.size === 0) { + console.log(`Found an empty chat file: ${pathToFile}`); + res({}); + return; + } + const rl = readline.createInterface({ input: fileStream, crlfDelay: Infinity, diff --git a/src/endpoints/chats.js b/src/endpoints/chats.js index 24ffc39be..0621e585b 100644 --- a/src/endpoints/chats.js +++ b/src/endpoints/chats.js @@ -435,7 +435,7 @@ router.post('/import', urlencodedParser, function (request, response) { // Do a tiny bit of work to import Chub Chat data // Processing the entire file is so fast that it's not worth checking if it's a Chub chat first - let flattenedChat; + let flattenedChat = data; try { // flattening is unlikely to break, but it's not worth failing to // import normal chats in an attempt to import a Chub chat