Save uploaded data unchanged if Chub conversion fails for any reason

Avoid non-resolving promise in /characters/chats readline if chat file is empty
This commit is contained in:
ceruleandeep 2024-09-20 08:57:48 +10:00
parent 1819604f31
commit 457475baf1
2 changed files with 7 additions and 1 deletions

View File

@ -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,

View File

@ -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