Spaces:
Running
Running
File size: 915 Bytes
df3243b a8a9533 df3243b 4f1e27f df3243b 4f1e27f df3243b 06feee8 df3243b 4f1e27f df3243b 06feee8 df3243b 4f1e27f |
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 |
import { base } from "$app/paths";
import { collections } from "$lib/server/database";
import { redirect } from "@sveltejs/kit";
import { ObjectId } from "mongodb";
import { authCondition } from "$lib/server/auth.js";
export async function load({ params, locals }) {
try {
const assistant = await collections.assistants.findOne({
_id: new ObjectId(params.assistantId),
});
if (!assistant) {
redirect(302, `${base}`);
}
if (locals.user?._id ?? locals.sessionId) {
await collections.settings.updateOne(
authCondition(locals),
{
$set: {
activeModel: assistant._id.toString(),
updatedAt: new Date(),
},
$push: { assistants: assistant._id },
$setOnInsert: {
createdAt: new Date(),
},
},
{
upsert: true,
}
);
}
return {
assistant: JSON.parse(JSON.stringify(assistant)),
};
} catch {
redirect(302, `${base}`);
}
}
|