Support multiple chats per group. Fix A/N metadata not saving for groups.

This commit is contained in:
SillyLossy
2023-05-02 16:01:23 +03:00
parent dce309f0d9
commit 28627e7e51
6 changed files with 296 additions and 174 deletions

View File

@ -1381,22 +1381,19 @@ app.post("/getallchatsofcharacter", jsonParser, function (request, response) {
lastLine = line;
});
rl.on('close', () => {
ii--;
if (lastLine) {
let jsonData = json5.parse(lastLine);
if (jsonData.name !== undefined) {
if (jsonData.name !== undefined || jsonData.character_name !== undefined) {
chatData[i] = {};
chatData[i]['file_name'] = file;
chatData[i]['mes'] = jsonData['mes'];
ii--;
if (ii === 0) {
console.log('ii count went to zero, responding with chatData');
response.send(chatData);
}
} else {
console.log('just returning from getallchatsofcharacter');
return;
chatData[i]['mes'] = jsonData['mes'] || '[The chat is empty]';
}
}
if (ii === 0) {
console.log('ii count went to zero, responding with chatData');
response.send(chatData);
}
console.log('successfully closing getallchatsofcharacter');
rl.close();
});
@ -1794,6 +1791,22 @@ app.post('/getgroupchat', jsonParser, (request, response) => {
}
});
app.post('/deletegroupchat', jsonParser, (request, response) => {
if (!request.body || !request.body.id) {
return response.sendStatus(400);
}
const id = request.body.id;
const pathToFile = path.join(directories.groupChats, `${id}.jsonl`);
if (fs.existsSync(pathToFile)) {
fs.rmSync(pathToFile);
return response.send({ ok: true });
}
return response.send({ error: true });
});
app.post('/savegroupchat', jsonParser, (request, response) => {
if (!request.body || !request.body.id) {
return response.sendStatus(400);