chat-ui / src /routes /settings /+page.server.ts
Adrien Denat
Disable models (#187)
b7b2c8c unverified
raw history blame
No virus
1.27 kB
import { base } from "$app/paths";
import { collections } from "$lib/server/database";
import { redirect } from "@sveltejs/kit";
import { z } from "zod";
import { defaultModel, models, validateModel } from "$lib/server/models";
import { authCondition } from "$lib/server/auth";
export const actions = {
default: async function ({ request, locals }) {
const formData = await request.formData();
const { ethicsModalAccepted, ...settings } = z
.object({
shareConversationsWithModelAuthors: z.boolean({ coerce: true }).default(true),
ethicsModalAccepted: z.boolean({ coerce: true }).optional(),
activeModel: validateModel(models),
})
.parse({
shareConversationsWithModelAuthors: formData.get("shareConversationsWithModelAuthors"),
ethicsModalAccepted: formData.get("ethicsModalAccepted"),
activeModel: formData.get("activeModel") ?? defaultModel.id,
});
await collections.settings.updateOne(
authCondition(locals),
{
$set: {
...settings,
...(ethicsModalAccepted && { ethicsModalAcceptedAt: new Date() }),
updatedAt: new Date(),
},
$setOnInsert: {
createdAt: new Date(),
},
},
{
upsert: true,
}
);
throw redirect(303, request.headers.get("referer") || base || "/");
},
};