Spaces:
Running
Running
File size: 1,492 Bytes
a5f3fbf e18e7a5 a5f3fbf 9e91fc2 5290cbb 0e4a83d a5f3fbf 9e91fc2 a5f3fbf 60ddb23 9e91fc2 7ae6b59 9e91fc2 5290cbb a5f3fbf 5290cbb 9e91fc2 5290cbb 9e91fc2 5290cbb 60ddb23 e18e7a5 9e91fc2 a5f3fbf 6041b51 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
import { collections } from "$lib/server/database";
import { models } from "$lib/server/models";
import { authCondition } from "$lib/server/auth";
import type { Conversation } from "$lib/types/Conversation";
import { CONV_NUM_PER_PAGE } from "$lib/constants/pagination";
export async function GET({ locals, url }) {
const p = parseInt(url.searchParams.get("p") ?? "0");
if (locals.user?._id || locals.sessionId) {
const convs = await collections.conversations
.find({
...authCondition(locals),
})
.project<Pick<Conversation, "_id" | "title" | "updatedAt" | "model" | "assistantId">>({
title: 1,
updatedAt: 1,
model: 1,
assistantId: 1,
})
.sort({ updatedAt: -1 })
.skip(p * CONV_NUM_PER_PAGE)
.limit(CONV_NUM_PER_PAGE)
.toArray();
if (convs.length === 0) {
return Response.json([]);
}
const res = convs.map((conv) => ({
_id: conv._id,
id: conv._id, // legacy param iOS
title: conv.title,
updatedAt: conv.updatedAt,
model: conv.model,
modelId: conv.model, // legacy param iOS
assistantId: conv.assistantId,
modelTools: models.find((m) => m.id == conv.model)?.tools ?? false,
}));
return Response.json(res);
} else {
return Response.json({ message: "Must have session cookie" }, { status: 401 });
}
}
export async function DELETE({ locals }) {
if (locals.user?._id || locals.sessionId) {
await collections.conversations.deleteMany({
...authCondition(locals),
});
}
return new Response();
}
|