Add root chat files to /recent

621b27063a794976b5d0a18db5ad0c92e812f750

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +12 -1Ignore whitespace
src/endpoints/chats.js+12 -1
@@ -958,7 +958,18 @@ router.post('/recent', async function (request, response) {
958958 }
959959 };
960960
961- await Promise.allSettled([getCharacterChatFiles(), getGroupChatFiles()]);
961+ const getRootChatFiles = async () => {
962+ const dirents = await fs.promises.readdir(request.user.directories.chats, { withFileTypes: true });
963+ const chatFiles = dirents.filter(e => e.isFile() && path.extname(e.name) === '.jsonl').map(e => e.name);
964+
965+ for (const file of chatFiles) {
966+ const filePath = path.join(request.user.directories.chats, file);
967+ const stats = await fs.promises.stat(filePath);
968+ allChatFiles.push({ filePath, mtime: stats.mtimeMs });
969+ }
970+ };
971+
972+ await Promise.allSettled([getCharacterChatFiles(), getGroupChatFiles(), getRootChatFiles()]);
962973
963974 const max = parseInt(request.body.max ?? Number.MAX_SAFE_INTEGER);
964975 const recentChats = allChatFiles.sort((a, b) => b.mtime - a.mtime).slice(0, max);