mirror of
https://github.com/kmc7468/arkvault.git
synced 2025-12-16 06:58:46 +00:00
파일/디렉터리 목록 캐싱 추가
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
import { error } from "@sveltejs/kit";
|
||||
import { z } from "zod";
|
||||
import { callGetApi } from "$lib/hooks";
|
||||
import type { DirectoryInfoResponse, FileInfoResponse } from "$lib/server/schemas";
|
||||
import type { PageLoad } from "./$types";
|
||||
|
||||
export const load: PageLoad = async ({ params, fetch }) => {
|
||||
export const load: PageLoad = async ({ params }) => {
|
||||
const zodRes = z
|
||||
.object({
|
||||
id: z.coerce.number().int().positive().optional(),
|
||||
@@ -13,36 +11,7 @@ export const load: PageLoad = async ({ params, fetch }) => {
|
||||
if (!zodRes.success) error(404, "Not found");
|
||||
const { id } = zodRes.data;
|
||||
|
||||
const directoryId = id ? id : ("root" as const);
|
||||
const res = await callGetApi(`/api/directory/${directoryId}`, fetch);
|
||||
if (!res.ok) error(404, "Not found");
|
||||
|
||||
const directoryInfo: DirectoryInfoResponse = await res.json();
|
||||
const subDirectoryInfos = await Promise.all(
|
||||
directoryInfo.subDirectories.map(async (subDirectoryId) => {
|
||||
const res = await callGetApi(`/api/directory/${subDirectoryId}`, fetch);
|
||||
if (!res.ok) error(500, "Internal server error");
|
||||
return {
|
||||
...((await res.json()) as DirectoryInfoResponse),
|
||||
id: subDirectoryId,
|
||||
};
|
||||
}),
|
||||
);
|
||||
const fileInfos = await Promise.all(
|
||||
directoryInfo.files.map(async (fileId) => {
|
||||
const res = await callGetApi(`/api/file/${fileId}`, fetch);
|
||||
if (!res.ok) error(500, "Internal server error");
|
||||
return {
|
||||
...((await res.json()) as FileInfoResponse),
|
||||
id: fileId,
|
||||
};
|
||||
}),
|
||||
);
|
||||
|
||||
return {
|
||||
id: directoryId,
|
||||
metadata: directoryInfo.metadata,
|
||||
subDirectories: subDirectoryInfos,
|
||||
files: fileInfos,
|
||||
id: id ? id : ("root" as const),
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user