mirror of
https://github.com/kmc7468/arkvault.git
synced 2025-12-16 06:58:46 +00:00
/api/client/[id]/key, /api/mek/share Endpoint 추가
This commit is contained in:
20
src/routes/api/client/[id]/key/+server.ts
Normal file
20
src/routes/api/client/[id]/key/+server.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { error, json } from "@sveltejs/kit";
|
||||
import { z } from "zod";
|
||||
import { authorize } from "$lib/server/modules/auth";
|
||||
import { getUserClientEncPubKey } from "$lib/server/services/client";
|
||||
import type { RequestHandler } from "./$types";
|
||||
|
||||
export const GET: RequestHandler = async ({ cookies, params }) => {
|
||||
const { userId } = await authorize(cookies, "activeClient");
|
||||
|
||||
const zodRes = z
|
||||
.object({
|
||||
id: z.coerce.number().int().positive(),
|
||||
})
|
||||
.safeParse(params);
|
||||
if (!zodRes.success) error(400, "Invalid path parameters");
|
||||
const { id } = zodRes.data;
|
||||
|
||||
const { encPubKey } = await getUserClientEncPubKey(userId, id);
|
||||
return json({ encPubKey });
|
||||
};
|
||||
30
src/routes/api/mek/share/+server.ts
Normal file
30
src/routes/api/mek/share/+server.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { text } from "@sveltejs/kit";
|
||||
import { z } from "zod";
|
||||
import { authorize } from "$lib/server/modules/auth";
|
||||
import { parseSignedRequest } from "$lib/server/modules/crypto";
|
||||
import { shareMeksForNewClient } from "$lib/server/services/mek";
|
||||
import type { RequestHandler } from "./$types";
|
||||
|
||||
export const POST: RequestHandler = async ({ request, cookies }) => {
|
||||
const { userId, clientId } = await authorize(cookies, "activeClient");
|
||||
const { targetId, meks } = await parseSignedRequest(
|
||||
clientId,
|
||||
await request.json(),
|
||||
z.object({
|
||||
targetId: z.number().int().positive(),
|
||||
meks: z.array(
|
||||
z.object({
|
||||
version: z.number().int().positive(),
|
||||
mek: z.string().base64().nonempty(),
|
||||
}),
|
||||
),
|
||||
}),
|
||||
);
|
||||
|
||||
await shareMeksForNewClient(
|
||||
userId,
|
||||
targetId,
|
||||
meks.map(({ version, mek }) => ({ version, encMek: mek })),
|
||||
);
|
||||
return text("MEK shared", { headers: { "Content-Type": "text/plain" } });
|
||||
};
|
||||
Reference in New Issue
Block a user