Fix imported chats not deleting itself after upload

This commit is contained in:
Cohee 2024-06-26 23:25:00 +03:00
parent 5b002c6e46
commit b80b2d9a74
1 changed files with 5 additions and 2 deletions

View File

@ -346,9 +346,11 @@ router.post('/import', urlencodedParser, function (request, response) {
} }
try { try {
const data = fs.readFileSync(path.join(request.file.destination, request.file.filename), 'utf8'); const pathToUpload = path.join(request.file.destination, request.file.filename);
const data = fs.readFileSync(pathToUpload, 'utf8');
if (format === 'json') { if (format === 'json') {
fs.unlinkSync(pathToUpload);
const jsonData = JSON.parse(data); const jsonData = JSON.parse(data);
if (jsonData.histories !== undefined) { if (jsonData.histories !== undefined) {
// CAI Tools format // CAI Tools format
@ -387,7 +389,8 @@ router.post('/import', urlencodedParser, function (request, response) {
if (jsonData.user_name !== undefined || jsonData.name !== undefined) { if (jsonData.user_name !== undefined || jsonData.name !== undefined) {
const fileName = `${characterName} - ${humanizedISO8601DateTime()} imported.jsonl`; const fileName = `${characterName} - ${humanizedISO8601DateTime()} imported.jsonl`;
const filePath = path.join(request.user.directories.chats, avatarUrl, fileName); const filePath = path.join(request.user.directories.chats, avatarUrl, fileName);
fs.copyFileSync(path.join(request.file.destination, request.file.filename), filePath); fs.copyFileSync(pathToUpload, filePath);
fs.unlinkSync(pathToUpload);
response.send({ res: true }); response.send({ res: true });
} else { } else {
console.log('Incorrect chat format .jsonl'); console.log('Incorrect chat format .jsonl');