Save uploaded data unchanged if Chub conversion fails for any reason Avoid non-resolving promise in /characters/chats readline if chat file is empty
| @@ -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`; |
| 1029 | 1029 | ||
| 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, |
| @@ -435,7 +435,7 @@ router.post('/import', urlencodedParser, function (request, response) { | |||
| 435 | 435 | ||
| 436 | // Do a tiny bit of work to import Chub Chat data | 436 | // 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 first | 437 | // 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 to | 440 | // flattening is unlikely to break, but it's not worth failing to |
| 441 | // import normal chats in an attempt to import a Chub chat | 441 | // import normal chats in an attempt to import a Chub chat |