mirror of
https://github.com/kmc7468/arkvault.git
synced 2025-12-15 22:38:47 +00:00
47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
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 ({ locals, params }) => {
|
|
const { userId } = await authorize(locals, "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 {
|
|
parentId,
|
|
mekVersion,
|
|
encDek,
|
|
dekVersion,
|
|
contentType,
|
|
encContentIv,
|
|
encName,
|
|
encCreatedAt,
|
|
encLastModifiedAt,
|
|
} = await getFileInformation(userId, id);
|
|
return json(
|
|
fileInfoResponse.parse({
|
|
parent: parentId,
|
|
mekVersion,
|
|
dek: encDek,
|
|
dekVersion: dekVersion.toISOString(),
|
|
contentType: contentType,
|
|
contentIv: encContentIv,
|
|
name: encName.ciphertext,
|
|
nameIv: encName.iv,
|
|
createdAt: encCreatedAt?.ciphertext,
|
|
createdAtIv: encCreatedAt?.iv,
|
|
lastModifiedAt: encLastModifiedAt.ciphertext,
|
|
lastModifiedAtIv: encLastModifiedAt.iv,
|
|
} satisfies FileInfoResponse),
|
|
);
|
|
};
|