Merge pull request #2878 from ceruleandeep/feature/fixHangOnEmptyChatFile Save uploaded data unchanged if Chub conversion fails for any reason

6d32cd6bf095ffc9a3a9b31731d7cb97318a67f8

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

Signed
2 files changed, +7 -1Ignore whitespace
src/endpoints/characters.js+6 -0
@@ -1027,6 +1027,12 @@ router.post('/chats', jsonParser, async function (request, response) {
10271027 const stats = fs.statSync(pathToFile);
10281028 const fileSizeInKB = `${(stats.size / 1024).toFixed(2)}kb`;
10291029
1030+ if (stats.size === 0) {
1031+ console.log(`Found an empty chat file: ${pathToFile}`);
1032+ res({});
1033+ return;
1034+ }
1035+
10301036 const rl = readline.createInterface({
10311037 input: fileStream,
10321038 crlfDelay: Infinity,
src/endpoints/chats.js+1 -1
@@ -435,7 +435,7 @@ router.post('/import', urlencodedParser, function (request, response) {
435435
436436 // Do a tiny bit of work to import Chub Chat data
437437 // Processing the entire file is so fast that it's not worth checking if it's a Chub chat first
438438 let flattenedChat = data;
439439 try {
440440 // flattening is unlikely to break, but it's not worth failing to
441441 // import normal chats in an attempt to import a Chub chat