| 529 | 529 | }); |
| 530 | 530 | |
| 531 | 531 | router.post('/delete', validateAvatarUrlMiddleware, function (request, response) { |
| 532 | | - const dirName = String(request.body.avatar_url).replace('.png', ''); |
| 532 | + try { |
| 533 | | - const fileName = String(request.body.chatfile); |
| 533 | + if (!path.extname(request.body.chatfile)) { |
| 534 | | - const filePath = path.join(request.user.directories.chats, dirName, sanitize(fileName)); |
| 534 | + request.body.chatfile += '.jsonl'; |
| 535 | | - const chatFileExists = fs.existsSync(filePath); |
| 535 | + } |
| 536 | 536 | |
| 537 | | - if (!chatFileExists) { |
| 537 | + const dirName = String(request.body.avatar_url).replace('.png', ''); |
| 538 | | - console.error(`Chat file not found '${filePath}'`); |
| 538 | + const fileName = String(request.body.chatfile); |
| 539 | | - return response.sendStatus(400); |
| 539 | + const filePath = path.join(request.user.directories.chats, dirName, sanitize(fileName)); |
| 540 | | - } |
| 540 | + const chatFileExists = fs.existsSync(filePath); |
| 541 | + |
| 542 | + if (!chatFileExists) { |
| 543 | + console.error(`Chat file not found '${filePath}'`); |
| 544 | + return response.sendStatus(400); |
| 545 | + } |
| 541 | 546 | |
| 542 | 547 | fs.unlinkSync(filePath); |
| 543 | 548 | console.info(`Deleted chat file: ${filePath}`); |
| 544 | 549 | return response.send('ok'); |
| 550 | + } catch (error) { |
| 551 | + console.error(error); |
| 552 | + return response.sendStatus(500); |
| 553 | + } |
| 545 | 554 | }); |
| 546 | 555 | |
| 547 | 556 | router.post('/export', validateAvatarUrlMiddleware, async function (request, response) { |