Update server/index.js
Browse files- server/index.js +11 -11
server/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import fetch from 'node-fetch';
|
|
| 9 |
import rateLimit from 'express-rate-limit';
|
| 10 |
import fs from 'fs';
|
| 11 |
import { registerFeedbackRoutes } from './handleFeedback.js';
|
| 12 |
-
import { abortActiveStream, handleWsMessage } from './wsHandler.js';
|
| 13 |
import { sessionStore, initStoreConfig } from './sessionStore.js';
|
| 14 |
import { SUPABASE_URL, SUPABASE_ANON_KEY } from './config.js';
|
| 15 |
import { safeSend } from './helpers.js';
|
|
@@ -411,12 +411,12 @@ app.get('/api/db/chats', async (req, res) => {
|
|
| 411 |
})),
|
| 412 |
});
|
| 413 |
}
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
} catch (err) {
|
| 421 |
console.error('db chats list error', err);
|
| 422 |
res.status(500).json({ error: 'db:chats_list_failed' });
|
|
@@ -436,7 +436,7 @@ app.post('/api/db/chats', async (req, res) => {
|
|
| 436 |
if (Object.keys(patch).length) {
|
| 437 |
created = await sessionStore.updateUserSession(resolved.user.id, resolved.accessToken, created.id, patch);
|
| 438 |
}
|
| 439 |
-
res.status(201).json({ item: created });
|
| 440 |
} catch (err) {
|
| 441 |
console.error('db chat create error', err);
|
| 442 |
res.status(500).json({ error: 'db:chat_create_failed' });
|
|
@@ -449,7 +449,7 @@ app.get('/api/db/chats/:sessionId', async (req, res) => {
|
|
| 449 |
try {
|
| 450 |
const session = await sessionStore.getUserSessionResolved(resolved.user.id, req.params.sessionId);
|
| 451 |
if (!session) return res.status(404).json({ error: 'db:chat_not_found' });
|
| 452 |
-
res.json({ item: session });
|
| 453 |
} catch (err) {
|
| 454 |
console.error('db chat get error', err);
|
| 455 |
res.status(500).json({ error: 'db:chat_get_failed' });
|
|
@@ -473,7 +473,7 @@ app.patch('/api/db/chats/:sessionId', async (req, res) => {
|
|
| 473 |
patch
|
| 474 |
);
|
| 475 |
if (!updated) return res.status(404).json({ error: 'db:chat_not_found' });
|
| 476 |
-
res.json({ item: updated });
|
| 477 |
} catch (err) {
|
| 478 |
console.error('db chat patch error', err);
|
| 479 |
res.status(500).json({ error: 'db:chat_update_failed' });
|
|
@@ -726,7 +726,7 @@ app.get('/api/db/export', async (req, res) => {
|
|
| 726 |
const chats = [];
|
| 727 |
for (const listedSession of listed) {
|
| 728 |
const full = await sessionStore.getUserSessionResolved(resolved.user.id, listedSession.id);
|
| 729 |
-
if (full) chats.push(full);
|
| 730 |
}
|
| 731 |
|
| 732 |
const mediaResult = await mediaStore.listAll(resolved.owner, { view: 'all' });
|
|
|
|
| 9 |
import rateLimit from 'express-rate-limit';
|
| 10 |
import fs from 'fs';
|
| 11 |
import { registerFeedbackRoutes } from './handleFeedback.js';
|
| 12 |
+
import { abortActiveStream, handleWsMessage, serializeSessionForClient } from './wsHandler.js';
|
| 13 |
import { sessionStore, initStoreConfig } from './sessionStore.js';
|
| 14 |
import { SUPABASE_URL, SUPABASE_ANON_KEY } from './config.js';
|
| 15 |
import { safeSend } from './helpers.js';
|
|
|
|
| 411 |
})),
|
| 412 |
});
|
| 413 |
}
|
| 414 |
+
const items = [];
|
| 415 |
+
for (const listedSession of listed) {
|
| 416 |
+
const full = await sessionStore.getUserSessionResolved(resolved.user.id, listedSession.id);
|
| 417 |
+
if (full) items.push(serializeSessionForClient(full));
|
| 418 |
+
}
|
| 419 |
+
res.json({ items });
|
| 420 |
} catch (err) {
|
| 421 |
console.error('db chats list error', err);
|
| 422 |
res.status(500).json({ error: 'db:chats_list_failed' });
|
|
|
|
| 436 |
if (Object.keys(patch).length) {
|
| 437 |
created = await sessionStore.updateUserSession(resolved.user.id, resolved.accessToken, created.id, patch);
|
| 438 |
}
|
| 439 |
+
res.status(201).json({ item: serializeSessionForClient(created) });
|
| 440 |
} catch (err) {
|
| 441 |
console.error('db chat create error', err);
|
| 442 |
res.status(500).json({ error: 'db:chat_create_failed' });
|
|
|
|
| 449 |
try {
|
| 450 |
const session = await sessionStore.getUserSessionResolved(resolved.user.id, req.params.sessionId);
|
| 451 |
if (!session) return res.status(404).json({ error: 'db:chat_not_found' });
|
| 452 |
+
res.json({ item: serializeSessionForClient(session) });
|
| 453 |
} catch (err) {
|
| 454 |
console.error('db chat get error', err);
|
| 455 |
res.status(500).json({ error: 'db:chat_get_failed' });
|
|
|
|
| 473 |
patch
|
| 474 |
);
|
| 475 |
if (!updated) return res.status(404).json({ error: 'db:chat_not_found' });
|
| 476 |
+
res.json({ item: serializeSessionForClient(updated) });
|
| 477 |
} catch (err) {
|
| 478 |
console.error('db chat patch error', err);
|
| 479 |
res.status(500).json({ error: 'db:chat_update_failed' });
|
|
|
|
| 726 |
const chats = [];
|
| 727 |
for (const listedSession of listed) {
|
| 728 |
const full = await sessionStore.getUserSessionResolved(resolved.user.id, listedSession.id);
|
| 729 |
+
if (full) chats.push(serializeSessionForClient(full));
|
| 730 |
}
|
| 731 |
|
| 732 |
const mediaResult = await mediaStore.listAll(resolved.owner, { view: 'all' });
|