mirror of
https://github.com/kmc7468/arkvault.git
synced 2025-12-16 06:58:46 +00:00
디렉터리 페이지 레이아웃 구현 및 디렉터리 생성 구현
This commit is contained in:
35
src/routes/(main)/directory/[[id]]/+page.server.ts
Normal file
35
src/routes/(main)/directory/[[id]]/+page.server.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { error } from "@sveltejs/kit";
|
||||
import { z } from "zod";
|
||||
import type { DirectroyInfoResponse } from "$lib/server/schemas";
|
||||
import type { PageServerLoad } from "./$types";
|
||||
|
||||
export const load: PageServerLoad = async ({ params, fetch }) => {
|
||||
const zodRes = z
|
||||
.object({
|
||||
id: z.coerce.number().int().positive().optional(),
|
||||
})
|
||||
.safeParse(params);
|
||||
if (!zodRes.success) error(404, "Not found");
|
||||
const { id } = zodRes.data;
|
||||
|
||||
const directoryId = id ? id : ("root" as const);
|
||||
const res = await fetch(`/api/directory/${directoryId}`);
|
||||
if (!res.ok) error(404, "Not found");
|
||||
|
||||
const directoryInfo: DirectroyInfoResponse = await res.json();
|
||||
const subDirectoryInfos = await Promise.all(
|
||||
directoryInfo.subDirectories.map(async (subDirectoryId) => {
|
||||
const res = await fetch(`/api/directory/${subDirectoryId}`);
|
||||
if (!res.ok) error(500, "Internal server error");
|
||||
return (await res.json()) as DirectroyInfoResponse;
|
||||
}),
|
||||
);
|
||||
const fileInfos = directoryInfo.files; // TODO
|
||||
|
||||
return {
|
||||
id: directoryId,
|
||||
metadata: directoryInfo.metadata,
|
||||
subDirectories: subDirectoryInfos,
|
||||
files: fileInfos,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user