Spaces:
Runtime error
Runtime error
File size: 657 Bytes
1b66f8d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import type { RequestHandler } from './$types';
import { collections } from '$lib/server/database';
import { ObjectId } from 'mongodb';
export const POST: RequestHandler = async (input) => {
const res = await collections.conversations.insertOne({
_id: new ObjectId(),
title:
'Untitled ' +
((await collections.conversations.countDocuments({ sessionId: input.locals.sessionId })) + 1),
messages: [],
createdAt: new Date(),
updatedAt: new Date(),
sessionId: input.locals.sessionId
});
return new Response(
JSON.stringify({
conversationId: res.insertedId.toString()
}),
{ headers: { 'Content-Type': 'application/json' } }
);
};
|