Add extension in /api/chats/delete if missing
| @@ -529,6 +529,11 @@ router.post('/rename', validateAvatarUrlMiddleware, async function (request, res | ||
| 529 | 529 | }); |
| 530 | 530 | |
| 531 | 531 | router.post('/delete', validateAvatarUrlMiddleware, function (request, response) { |
| 532 | + try { | |
| 533 | + if (!path.extname(request.body.chatfile)) { | |
| 534 | + request.body.chatfile += '.jsonl'; | |
| 535 | + } | |
| 536 | + | |
| 532 | 537 | const dirName = String(request.body.avatar_url).replace('.png', ''); |
| 533 | 538 | const fileName = String(request.body.chatfile); |
| 534 | 539 | const filePath = path.join(request.user.directories.chats, dirName, sanitize(fileName)); |
| @@ -542,6 +547,10 @@ router.post('/delete', validateAvatarUrlMiddleware, function (request, response) | ||
| 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) { |