/api/mek/register/initial Endpoint 추가

This commit is contained in:
static
2024-12-30 00:37:53 +09:00
parent ee752494cd
commit 04780d2493
9 changed files with 145 additions and 35 deletions

View File

@@ -1,14 +1,10 @@
import { error, json } from "@sveltejs/kit";
import { authenticate } from "$lib/server/modules/auth";
import { authorize } from "$lib/server/modules/auth";
import { getClientMekList } from "$lib/server/services/mek";
import type { RequestHandler } from "@sveltejs/kit";
export const GET: RequestHandler = async ({ cookies }) => {
const { userId, clientId } = authenticate(cookies);
if (!clientId) {
error(403, "Forbidden");
}
const { userId, clientId } = await authorize(cookies, "activeClient");
const { meks } = await getClientMekList(userId, clientId);
return json({ meks });
};

View File

@@ -1,6 +1,6 @@
import { error, text } from "@sveltejs/kit";
import { z } from "zod";
import { authenticate } from "$lib/server/modules/auth";
import { authorize } from "$lib/server/modules/auth";
import { registerNewActiveMek } from "$lib/server/services/mek";
import type { RequestHandler } from "@sveltejs/kit";
@@ -17,11 +17,7 @@ export const POST: RequestHandler = async ({ request, cookies }) => {
.safeParse(await request.json());
if (!zodRes.success) error(400, "Invalid request body");
const { userId, clientId } = authenticate(cookies);
if (!clientId) {
error(403, "Forbidden");
}
const { userId, clientId } = await authorize(cookies, "activeClient");
const { meks } = zodRes.data;
await registerNewActiveMek(
userId,
@@ -31,5 +27,6 @@ export const POST: RequestHandler = async ({ request, cookies }) => {
encMek: mek.trim(),
})),
);
return text("MEK registered", { headers: { "Content-Type": "text/plain" } });
};

View File

@@ -0,0 +1,24 @@
import { error, text } from "@sveltejs/kit";
import { z } from "zod";
import { authenticate } from "$lib/server/modules/auth";
import { registerInitialActiveMek } from "$lib/server/services/mek";
import type { RequestHandler } from "@sveltejs/kit";
export const POST: RequestHandler = async ({ request, cookies }) => {
const zodRes = z
.object({
mek: z.string().base64().nonempty(),
})
.safeParse(await request.json());
if (!zodRes.success) error(400, "Invalid request body");
const { userId, clientId } = authenticate(cookies);
if (!clientId) {
error(403, "Forbidden");
}
const { mek } = zodRes.data;
await registerInitialActiveMek(userId, clientId, mek);
return text("MEK registered", { headers: { "Content-Type": "text/plain" } });
};