mirror of
https://github.com/kmc7468/arkvault.git
synced 2025-12-16 15:08:46 +00:00
/api/file/upload, /api/file/[id], /api/file/[id]/download Endpoint 구현
This commit is contained in:
33
src/routes/api/file/[id]/+server.ts
Normal file
33
src/routes/api/file/[id]/+server.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { error, json } from "@sveltejs/kit";
|
||||
import { z } from "zod";
|
||||
import { authorize } from "$lib/server/modules/auth";
|
||||
import { fileInfoResponse, type FileInfoResponse } from "$lib/server/schemas";
|
||||
import { getFileInformation } from "$lib/server/services/file";
|
||||
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 { createdAt, mekVersion, encDek, encContentIv, encName } = await getFileInformation(
|
||||
userId,
|
||||
id,
|
||||
);
|
||||
return json(
|
||||
fileInfoResponse.parse({
|
||||
createdAt,
|
||||
mekVersion,
|
||||
dek: encDek,
|
||||
contentIv: encContentIv,
|
||||
name: encName.ciphertext,
|
||||
nameIv: encName.iv,
|
||||
} satisfies FileInfoResponse),
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user