commit f48dd2be1aedaacd76391cfede2c05a67c7e2173
parent 7c07ebbbadecadfe27a1940876116fa336323921
Author: notamitgamer-bot <bot@users.noreply.github.com>
Date: Sat, 29 Aug 2026 01:36:18 +0000
Add /api/export/chats manifest endpoint
Lightweight chat list with per-chat message counts (no message
bodies), so the client can know the true total message count up
front and show real progress during a full resync, instead of a
percentage that's only based on local processing after one giant
blob has already fully downloaded.
Diffstat:
1 file changed, 23 insertions(+), 0 deletions(-)
diff --git a/src/routes/api.js b/src/routes/api.js
@@ -150,6 +150,29 @@ router.get('/api/sync/stream', verifyApiToken, async (req, res) => {
}
});
+// --- API: Full Resync (used by the client's "Reset" flow) ---
+// Lightweight manifest: chat metadata + per-chat message counts, no message
+// bodies. Lets the client know the true total up front so it can show real
+// download progress instead of a fake/local-only percentage.
+router.get('/api/export/chats', verifyApiToken, async (req, res) => {
+ if (!isCacheReady()) return res.status(503).json({ error: 'Cache still warming, retry shortly' });
+
+ try {
+ const chats = [];
+ let totalMessages = 0;
+
+ chatsCache.forEach((data, id) => {
+ const count = messagesCache.has(id) ? messagesCache.get(id).size : 0;
+ totalMessages += count;
+ chats.push({ ...data, messageCount: count });
+ });
+
+ res.json({ chats, totalMessages });
+ } 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' });