Save uploaded data unchanged if Chub conversion fails for any reason Avoid non-resolving promise in /characters/chats readline if chat file is empty

457475baf1bfc971e00858dd350acd393dca4312

ceruleandeep <deep@cerulean.navy>

2 files changed, +7 -1Showing whitespace changes
src/endpoints/characters.js+6 -0
@@ -1027,6 +1027,12 @@ router.post('/chats', jsonParser, async function (request, response) {
1027 const stats = fs.statSync(pathToFile);1027 const stats = fs.statSync(pathToFile);
1028 const fileSizeInKB = `${(stats.size / 1024).toFixed(2)}kb`;1028 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
1030 const rl = readline.createInterface({1036 const rl = readline.createInterface({
1031 input: fileStream,1037 input: fileStream,
1032 crlfDelay: Infinity,1038 crlfDelay: Infinity,
src/endpoints/chats.js+1 -1
@@ -435,7 +435,7 @@ router.post('/import', urlencodedParser, function (request, response) {
435435
436 // Do a tiny bit of work to import Chub Chat data436 // Do a tiny bit of work to import Chub Chat data
437 // Processing the entire file is so fast that it's not worth checking if it's a Chub chat first437 // Processing the entire file is so fast that it's not worth checking if it's a Chub chat first
438 let flattenedChat;438 let flattenedChat = data;
439 try {439 try {
440 // flattening is unlikely to break, but it's not worth failing to440 // flattening is unlikely to break, but it's not worth failing to
441 // import normal chats in an attempt to import a Chub chat441 // import normal chats in an attempt to import a Chub chat