File size: 895 Bytes
5da61b4 1b66f8d 5da61b4 1b66f8d 09edaa6 1b66f8d 5da61b4 9405a81 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 25 26 27 28 29 30 31 32 33 34 |
import type { PageServerLoad } from "./$types";
import { collections } from "$lib/server/database";
import { ObjectId } from "mongodb";
import { error } from "@sveltejs/kit";
export const load: PageServerLoad = async (event) => {
// todo: add validation on params.id
const conversation = await collections.conversations.findOne({
_id: new ObjectId(event.params.id),
sessionId: event.locals.sessionId,
});
if (!conversation) {
const conversationExists =
(await collections.conversations.countDocuments({
_id: new ObjectId(event.params.id),
})) !== 0;
if (conversationExists) {
throw error(
403,
"You don't have access to this conversation. If someone gave you this link, ask them to use the 'share' feature instead."
);
}
throw error(404, "Conversation not found.");
}
return {
messages: conversation.messages,
title: conversation.title,
};
};
|