Spaces:
Running
Running
File size: 823 Bytes
64b910e |
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 |
import { base } from "$app/paths";
import { authCondition } from "$lib/server/auth.js";
import { collections } from "$lib/server/database.js";
import { models } from "$lib/server/models";
import { redirect } from "@sveltejs/kit";
export async function load({ params, locals, parent }) {
const model = models.find(({ id }) => id === params.model);
const data = await parent();
if (!model || model.unlisted) {
throw redirect(302, `${base}/`);
}
if (locals.user?._id ?? locals.sessionId) {
await collections.settings.updateOne(
authCondition(locals),
{
$set: {
activeModel: model.id,
updatedAt: new Date(),
},
$setOnInsert: {
createdAt: new Date(),
},
},
{
upsert: true,
}
);
}
return {
settings: {
...data.settings,
activeModel: model.id,
},
};
}
|