Add root chat files to /recent

621b27063a794976b5d0a18db5ad0c92e812f750

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

1 files changed, +12 -1Showing whitespace changes
src/endpoints/chats.js+12 -1
@@ -958,7 +958,18 @@ router.post('/recent', async function (request, response) {
958 }958 }
959 };959 };
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
963 const max = parseInt(request.body.max ?? Number.MAX_SAFE_INTEGER);974 const max = parseInt(request.body.max ?? Number.MAX_SAFE_INTEGER);
964 const recentChats = allChatFiles.sort((a, b) => b.mtime - a.mtime).slice(0, max);975 const recentChats = allChatFiles.sort((a, b) => b.mtime - a.mtime).slice(0, max);