mirror of
https://github.com/kmc7468/arkvault.git
synced 2025-12-14 22:08:45 +00:00
/api/category/[id]/file/list Endpoint에서, recursive 쿼리 파라미터의 값을 false로 설정해도 재귀적으로 검색되던 버그 수정
This commit is contained in:
@@ -281,7 +281,7 @@ const fetchCategoryInfoFromServer = async (
|
|||||||
const { dataKey } = await unwrapDataKey(metadata!.dek, masterKey);
|
const { dataKey } = await unwrapDataKey(metadata!.dek, masterKey);
|
||||||
const name = await decryptString(metadata!.name, metadata!.nameIv, dataKey);
|
const name = await decryptString(metadata!.name, metadata!.nameIv, dataKey);
|
||||||
|
|
||||||
res = await callGetApi(`/api/category/${id}/file/list?recursive=true`);
|
res = await callGetApi(`/api/category/${id}/file/list?recurse=true`);
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
throw new Error("Failed to fetch category files");
|
throw new Error("Failed to fetch category files");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -294,7 +294,7 @@ export const getAllFilesByParent = async (userId: number, parentId: DirectoryId)
|
|||||||
export const getAllFilesByCategory = async (
|
export const getAllFilesByCategory = async (
|
||||||
userId: number,
|
userId: number,
|
||||||
categoryId: number,
|
categoryId: number,
|
||||||
recursive: boolean,
|
recurse: boolean,
|
||||||
) => {
|
) => {
|
||||||
const files = await db
|
const files = await db
|
||||||
.withRecursive("cte", (db) =>
|
.withRecursive("cte", (db) =>
|
||||||
@@ -304,7 +304,7 @@ export const getAllFilesByCategory = async (
|
|||||||
.select(["id", "parent_id", "user_id", "file_category.file_id"])
|
.select(["id", "parent_id", "user_id", "file_category.file_id"])
|
||||||
.select(sql<number>`0`.as("depth"))
|
.select(sql<number>`0`.as("depth"))
|
||||||
.where("id", "=", categoryId)
|
.where("id", "=", categoryId)
|
||||||
.$if(recursive, (qb) =>
|
.$if(recurse, (qb) =>
|
||||||
qb.unionAll((db) =>
|
qb.unionAll((db) =>
|
||||||
db
|
db
|
||||||
.selectFrom("category")
|
.selectFrom("category")
|
||||||
|
|||||||
@@ -66,13 +66,13 @@ export const addCategoryFile = async (userId: number, categoryId: number, fileId
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getCategoryFiles = async (userId: number, categoryId: number, recursive: boolean) => {
|
export const getCategoryFiles = async (userId: number, categoryId: number, recurse: boolean) => {
|
||||||
const category = await getCategory(userId, categoryId);
|
const category = await getCategory(userId, categoryId);
|
||||||
if (!category) {
|
if (!category) {
|
||||||
error(404, "Invalid category id");
|
error(404, "Invalid category id");
|
||||||
}
|
}
|
||||||
|
|
||||||
const files = await getAllFilesByCategory(userId, categoryId, recursive);
|
const files = await getAllFilesByCategory(userId, categoryId, recurse);
|
||||||
return { files };
|
return { files };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -13,12 +13,17 @@ export const GET: RequestHandler = async ({ locals, url, params }) => {
|
|||||||
const { id } = paramsZodRes.data;
|
const { id } = paramsZodRes.data;
|
||||||
|
|
||||||
const queryZodRes = z
|
const queryZodRes = z
|
||||||
.object({ recursive: z.coerce.boolean().nullable() })
|
.object({
|
||||||
.safeParse({ recursive: url.searchParams.get("recursive") });
|
recurse: z
|
||||||
|
.enum(["true", "false"])
|
||||||
|
.transform((value) => value === "true")
|
||||||
|
.nullable(),
|
||||||
|
})
|
||||||
|
.safeParse({ recurse: url.searchParams.get("recurse") });
|
||||||
if (!queryZodRes.success) error(400, "Invalid query parameters");
|
if (!queryZodRes.success) error(400, "Invalid query parameters");
|
||||||
const { recursive } = queryZodRes.data;
|
const { recurse } = queryZodRes.data;
|
||||||
|
|
||||||
const { files } = await getCategoryFiles(userId, id, recursive ?? false);
|
const { files } = await getCategoryFiles(userId, id, recurse ?? false);
|
||||||
return json(
|
return json(
|
||||||
categoryFileListResponse.parse({
|
categoryFileListResponse.parse({
|
||||||
files: files.map(({ id, isRecursive }) => ({ file: id, isRecursive })),
|
files: files.map(({ id, isRecursive }) => ({ file: id, isRecursive })),
|
||||||
|
|||||||
Reference in New Issue
Block a user