mirror of
https://github.com/kmc7468/arkvault.git
synced 2025-12-16 06:58:46 +00:00
/api/mek/list, /api/mek/register Endpoint 구현
This commit is contained in:
14
src/routes/api/mek/list/+server.ts
Normal file
14
src/routes/api/mek/list/+server.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { error, json } from "@sveltejs/kit";
|
||||
import { authenticate } 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 { meks } = await getClientMekList(userId, clientId);
|
||||
return json({ meks });
|
||||
};
|
||||
35
src/routes/api/mek/register/+server.ts
Normal file
35
src/routes/api/mek/register/+server.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { error, text } from "@sveltejs/kit";
|
||||
import { z } from "zod";
|
||||
import { authenticate } from "$lib/server/modules/auth";
|
||||
import { registerNewActiveMek } from "$lib/server/services/mek";
|
||||
import type { RequestHandler } from "@sveltejs/kit";
|
||||
|
||||
export const POST: RequestHandler = async ({ request, cookies }) => {
|
||||
const zodRes = z
|
||||
.object({
|
||||
meks: z.array(
|
||||
z.object({
|
||||
clientId: z.number(),
|
||||
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 { meks } = zodRes.data;
|
||||
await registerNewActiveMek(
|
||||
userId,
|
||||
clientId,
|
||||
meks.map(({ clientId, mek }) => ({
|
||||
clientId,
|
||||
encMek: mek.trim(),
|
||||
})),
|
||||
);
|
||||
return text("MEK registered", { headers: { "Content-Type": "text/plain" } });
|
||||
};
|
||||
Reference in New Issue
Block a user