mirror of
https://github.com/kmc7468/arkvault.git
synced 2025-12-16 15:08:46 +00:00
/api/hsk/list, /api/hsk/register/initial Endpoint 구현
This commit is contained in:
@@ -16,8 +16,18 @@ export const POST: RequestHandler = async ({ locals, request }) => {
|
||||
|
||||
const zodRes = fileUploadRequest.safeParse(JSON.parse(metadata));
|
||||
if (!zodRes.success) error(400, "Invalid request body");
|
||||
const { parentId, mekVersion, dek, dekVersion, contentType, contentIv, name, nameIv } =
|
||||
zodRes.data;
|
||||
const {
|
||||
parentId,
|
||||
mekVersion,
|
||||
dek,
|
||||
dekVersion,
|
||||
hskVersion,
|
||||
contentHmac,
|
||||
contentType,
|
||||
contentIv,
|
||||
name,
|
||||
nameIv,
|
||||
} = zodRes.data;
|
||||
|
||||
await uploadFile(
|
||||
{
|
||||
@@ -26,6 +36,8 @@ export const POST: RequestHandler = async ({ locals, request }) => {
|
||||
mekVersion,
|
||||
encDek: dek,
|
||||
dekVersion: new Date(dekVersion),
|
||||
hskVersion,
|
||||
contentHmac,
|
||||
contentType,
|
||||
encContentIv: contentIv,
|
||||
encName: name,
|
||||
|
||||
20
src/routes/api/hsk/list/+server.ts
Normal file
20
src/routes/api/hsk/list/+server.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { json } from "@sveltejs/kit";
|
||||
import { authorize } from "$lib/server/modules/auth";
|
||||
import { hmacSecretListResponse, type HmacSecretListResponse } from "$lib/server/schemas";
|
||||
import { getHskList } from "$lib/server/services/hsk";
|
||||
import type { RequestHandler } from "./$types";
|
||||
|
||||
export const GET: RequestHandler = async ({ locals }) => {
|
||||
const { userId } = await authorize(locals, "activeClient");
|
||||
const { encHsks } = await getHskList(userId);
|
||||
return json(
|
||||
hmacSecretListResponse.parse({
|
||||
hsks: encHsks.map(({ version, state, mekVersion, encHsk }) => ({
|
||||
version,
|
||||
state,
|
||||
mekVersion,
|
||||
hsk: encHsk,
|
||||
})),
|
||||
} satisfies HmacSecretListResponse),
|
||||
);
|
||||
};
|
||||
16
src/routes/api/hsk/register/initial/+server.ts
Normal file
16
src/routes/api/hsk/register/initial/+server.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { error, text } from "@sveltejs/kit";
|
||||
import { authorize } from "$lib/server/modules/auth";
|
||||
import { initialHmacSecretRegisterRequest } from "$lib/server/schemas";
|
||||
import { registerInitialActiveHsk } from "$lib/server/services/hsk";
|
||||
import type { RequestHandler } from "./$types";
|
||||
|
||||
export const POST: RequestHandler = async ({ locals, request }) => {
|
||||
const { userId, clientId } = await authorize(locals, "activeClient");
|
||||
|
||||
const zodRes = initialHmacSecretRegisterRequest.safeParse(await request.json());
|
||||
if (!zodRes.success) error(400, "Invalid request body");
|
||||
const { mekVersion, hsk } = zodRes.data;
|
||||
|
||||
await registerInitialActiveHsk(userId, clientId, mekVersion, hsk);
|
||||
return text("HSK registered", { headers: { "Content-Type": "text/plain" } });
|
||||
};
|
||||
Reference in New Issue
Block a user