Add check for existing chats directory before reading files
| @@ -1010,6 +1010,11 @@ router.post('/chats', jsonParser, async function (request, response) { | ||
| 1010 | 1010 | |
| 1011 | 1011 | try { |
| 1012 | 1012 | const chatsDirectory = path.join(request.user.directories.chats, characterDirectory); |
| 1013 | + | |
| 1014 | + if (!fs.existsSync(chatsDirectory)) { | |
| 1015 | + return response.send({ error: true }); | |
| 1016 | + } | |
| 1017 | + | |
| 1013 | 1018 | const files = fs.readdirSync(chatsDirectory); |
| 1014 | 1019 | const jsonFiles = files.filter(file => path.extname(file) === '.jsonl'); |
| 1015 | 1020 | |