commit 4523fe00afc6fdf62aca42704743bdd8b9d92fa3
parent f48dd2be1aedaacd76391cfede2c05a67c7e2173
Author: notamitgamer-bot <bot@users.noreply.github.com>
Date: Sat, 29 Aug 2026 01:36:46 +0000
Add /api/export/messages?chatId= per-chat endpoint
Plain JSON response (not SSE) with all messages for a single chat.
Paired with /api/export/chats, this lets the client's resync loop
fetch one chat at a time and update a real done/total percentage
after each chat completes, using the true totalMessages count from
the manifest.
Diffstat:
1 file changed, 18 insertions(+), 0 deletions(-)
diff --git a/src/routes/api.js b/src/routes/api.js
@@ -173,6 +173,24 @@ router.get('/api/export/chats', verifyApiToken, async (req, res) => {
}
});
+// Plain JSON (not SSE) — all messages for a single chat. Called once per
+// chat by the client's resync loop so progress can be updated after each
+// chat finishes, instead of waiting on one all-chats blob.
+router.get('/api/export/messages', verifyApiToken, async (req, res) => {
+ if (!isCacheReady()) return res.status(503).json({ error: 'Cache still warming, retry shortly' });
+
+ const { chatId } = req.query;
+ if (!chatId) return res.status(400).json({ error: 'Missing chatId' });
+
+ try {
+ const msgMap = messagesCache.get(chatId);
+ const messages = msgMap ? Array.from(msgMap.values()) : [];
+ res.json({ chatId, messages });
+ } catch (err) {
+ res.status(500).json({ error: err.message });
+ }
+});
+
// --- API: Standard Actions ---
router.post('/api/rename', verifyApiToken, async (req, res) => {
if (!isCacheReady()) return res.status(503).json({ error: 'Cache still warming, retry shortly' });