From b80b2d9a748a435edf3d3a5732884f8a395a51ef Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Wed, 26 Jun 2024 23:25:00 +0300 Subject: [PATCH] Fix imported chats not deleting itself after upload --- src/endpoints/chats.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/endpoints/chats.js b/src/endpoints/chats.js index b6f675c04..2be1eb4e0 100644 --- a/src/endpoints/chats.js +++ b/src/endpoints/chats.js @@ -346,9 +346,11 @@ router.post('/import', urlencodedParser, function (request, response) { } 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') { + fs.unlinkSync(pathToUpload); const jsonData = JSON.parse(data); if (jsonData.histories !== undefined) { // CAI Tools format @@ -387,7 +389,8 @@ router.post('/import', urlencodedParser, function (request, response) { if (jsonData.user_name !== undefined || jsonData.name !== undefined) { const fileName = `${characterName} - ${humanizedISO8601DateTime()} imported.jsonl`; 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 }); } else { console.log('Incorrect chat format .jsonl');