mirror of
https://github.com/kmc7468/arkvault.git
synced 2026-02-03 23:56:53 +00:00
카테고리 관련 API 요청을 TanStack Query로 마이그레이션 (WiP)
This commit is contained in:
@@ -1,14 +1,16 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { untrack, type Component } from "svelte";
|
import type { Component } from "svelte";
|
||||||
import type { SvelteHTMLElements } from "svelte/elements";
|
import type { SvelteHTMLElements } from "svelte/elements";
|
||||||
import { get, type Writable } from "svelte/store";
|
import { derived } from "svelte/store";
|
||||||
import type { CategoryInfo } from "$lib/modules/filesystem";
|
import type { CategoryId } from "$lib/indexedDB";
|
||||||
|
import { getCategoryInfo, type SubCategoryInfo } from "$lib/modules/filesystem2";
|
||||||
import { SortBy, sortEntries } from "$lib/modules/util";
|
import { SortBy, sortEntries } from "$lib/modules/util";
|
||||||
|
import { masterKeyStore } from "$lib/stores";
|
||||||
import Category from "./Category.svelte";
|
import Category from "./Category.svelte";
|
||||||
import type { SelectedCategory } from "./service";
|
import type { SelectedCategory } from "./service";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
categories: Writable<CategoryInfo | null>[];
|
categoryIds: CategoryId[];
|
||||||
categoryMenuIcon?: Component<SvelteHTMLElements["svg"]>;
|
categoryMenuIcon?: Component<SvelteHTMLElements["svg"]>;
|
||||||
onCategoryClick: (category: SelectedCategory) => void;
|
onCategoryClick: (category: SelectedCategory) => void;
|
||||||
onCategoryMenuClick?: (category: SelectedCategory) => void;
|
onCategoryMenuClick?: (category: SelectedCategory) => void;
|
||||||
@@ -16,42 +18,33 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
let {
|
let {
|
||||||
categories,
|
categoryIds,
|
||||||
categoryMenuIcon,
|
categoryMenuIcon,
|
||||||
onCategoryClick,
|
onCategoryClick,
|
||||||
onCategoryMenuClick,
|
onCategoryMenuClick,
|
||||||
sortBy = SortBy.NAME_ASC,
|
sortBy = SortBy.NAME_ASC,
|
||||||
}: Props = $props();
|
}: Props = $props();
|
||||||
|
|
||||||
let categoriesWithName: { name?: string; info: Writable<CategoryInfo | null> }[] = $state([]);
|
let categories = $derived(
|
||||||
|
derived(
|
||||||
$effect(() => {
|
categoryIds.map((id) => getCategoryInfo(id, $masterKeyStore?.get(1)?.key!)),
|
||||||
categoriesWithName = categories.map((category) => ({
|
(infos) => {
|
||||||
name: get(category)?.name,
|
const categories = infos
|
||||||
info: category,
|
.filter(($info) => $info.status === "success")
|
||||||
}));
|
.map(($info) => ({
|
||||||
|
name: $info.data.name,
|
||||||
const sort = () => {
|
info: $info.data as SubCategoryInfo,
|
||||||
sortEntries(categoriesWithName, sortBy);
|
}));
|
||||||
};
|
sortEntries(categories, sortBy);
|
||||||
return untrack(() => {
|
return categories;
|
||||||
sort();
|
},
|
||||||
|
),
|
||||||
const unsubscribes = categoriesWithName.map((category) =>
|
);
|
||||||
category.info.subscribe((value) => {
|
|
||||||
if (category.name === value?.name) return;
|
|
||||||
category.name = value?.name;
|
|
||||||
sort();
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
return () => unsubscribes.forEach((unsubscribe) => unsubscribe());
|
|
||||||
});
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if categoriesWithName.length > 0}
|
{#if $categories.length > 0}
|
||||||
<div class="space-y-1">
|
<div class="space-y-1">
|
||||||
{#each categoriesWithName as { info }}
|
{#each $categories as { info }}
|
||||||
<Category
|
<Category
|
||||||
{info}
|
{info}
|
||||||
menuIcon={categoryMenuIcon}
|
menuIcon={categoryMenuIcon}
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { Component } from "svelte";
|
import type { Component } from "svelte";
|
||||||
import type { SvelteHTMLElements } from "svelte/elements";
|
import type { SvelteHTMLElements } from "svelte/elements";
|
||||||
import type { Writable } from "svelte/store";
|
|
||||||
import { ActionEntryButton } from "$lib/components/atoms";
|
import { ActionEntryButton } from "$lib/components/atoms";
|
||||||
import { CategoryLabel } from "$lib/components/molecules";
|
import { CategoryLabel } from "$lib/components/molecules";
|
||||||
import type { CategoryInfo } from "$lib/modules/filesystem";
|
import type { SubCategoryInfo } from "$lib/modules/filesystem2";
|
||||||
import type { SelectedCategory } from "./service";
|
import type { SelectedCategory } from "./service";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
info: Writable<CategoryInfo | null>;
|
info: SubCategoryInfo;
|
||||||
menuIcon?: Component<SvelteHTMLElements["svg"]>;
|
menuIcon?: Component<SvelteHTMLElements["svg"]>;
|
||||||
onclick: (category: SelectedCategory) => void;
|
onclick: (category: SelectedCategory) => void;
|
||||||
onMenuClick?: (category: SelectedCategory) => void;
|
onMenuClick?: (category: SelectedCategory) => void;
|
||||||
@@ -17,27 +16,25 @@
|
|||||||
let { info, menuIcon, onclick, onMenuClick }: Props = $props();
|
let { info, menuIcon, onclick, onMenuClick }: Props = $props();
|
||||||
|
|
||||||
const openCategory = () => {
|
const openCategory = () => {
|
||||||
const { id, dataKey, dataKeyVersion, name } = $info as CategoryInfo;
|
const { id, dataKey, dataKeyVersion, name } = info;
|
||||||
if (!dataKey || !dataKeyVersion) return; // TODO: Error handling
|
if (!dataKey || !dataKeyVersion) return; // TODO: Error handling
|
||||||
|
|
||||||
onclick({ id, dataKey, dataKeyVersion, name });
|
onclick({ id, dataKey, dataKeyVersion, name });
|
||||||
};
|
};
|
||||||
|
|
||||||
const openMenu = () => {
|
const openMenu = () => {
|
||||||
const { id, dataKey, dataKeyVersion, name } = $info as CategoryInfo;
|
const { id, dataKey, dataKeyVersion, name } = info;
|
||||||
if (!dataKey || !dataKeyVersion) return; // TODO: Error handling
|
if (!dataKey || !dataKeyVersion) return; // TODO: Error handling
|
||||||
|
|
||||||
onMenuClick!({ id, dataKey, dataKeyVersion, name });
|
onMenuClick!({ id, dataKey, dataKeyVersion, name });
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if $info}
|
<ActionEntryButton
|
||||||
<ActionEntryButton
|
class="h-12"
|
||||||
class="h-12"
|
onclick={openCategory}
|
||||||
onclick={openCategory}
|
actionButtonIcon={menuIcon}
|
||||||
actionButtonIcon={menuIcon}
|
onActionButtonClick={openMenu}
|
||||||
onActionButtonClick={openMenu}
|
>
|
||||||
>
|
<CategoryLabel name={info.name} />
|
||||||
<CategoryLabel name={$info.name!} />
|
</ActionEntryButton>
|
||||||
</ActionEntryButton>
|
|
||||||
{/if}
|
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { Component } from "svelte";
|
import type { Component } from "svelte";
|
||||||
import type { ClassValue, SvelteHTMLElements } from "svelte/elements";
|
import type { ClassValue, SvelteHTMLElements } from "svelte/elements";
|
||||||
import type { Writable } from "svelte/store";
|
|
||||||
import { Categories, IconEntryButton, type SelectedCategory } from "$lib/components/molecules";
|
import { Categories, IconEntryButton, type SelectedCategory } from "$lib/components/molecules";
|
||||||
import { getCategoryInfo, type CategoryInfo } from "$lib/modules/filesystem";
|
import type { CategoryInfo } from "$lib/modules/filesystem2";
|
||||||
import { masterKeyStore } from "$lib/stores";
|
|
||||||
|
|
||||||
import IconAddCircle from "~icons/material-symbols/add-circle";
|
import IconAddCircle from "~icons/material-symbols/add-circle";
|
||||||
|
|
||||||
@@ -27,14 +25,6 @@
|
|||||||
subCategoryCreatePosition = "bottom",
|
subCategoryCreatePosition = "bottom",
|
||||||
subCategoryMenuIcon,
|
subCategoryMenuIcon,
|
||||||
}: Props = $props();
|
}: Props = $props();
|
||||||
|
|
||||||
let subCategories: Writable<CategoryInfo | null>[] = $state([]);
|
|
||||||
|
|
||||||
$effect(() => {
|
|
||||||
subCategories = info.subCategoryIds.map((id) =>
|
|
||||||
getCategoryInfo(id, $masterKeyStore?.get(1)?.key!),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class={["space-y-1", className]}>
|
<div class={["space-y-1", className]}>
|
||||||
@@ -55,7 +45,7 @@
|
|||||||
{/if}
|
{/if}
|
||||||
{#key info}
|
{#key info}
|
||||||
<Categories
|
<Categories
|
||||||
categories={subCategories}
|
categoryIds={info.subCategoryIds}
|
||||||
categoryMenuIcon={subCategoryMenuIcon}
|
categoryMenuIcon={subCategoryMenuIcon}
|
||||||
onCategoryClick={onSubCategoryClick}
|
onCategoryClick={onSubCategoryClick}
|
||||||
onCategoryMenuClick={onSubCategoryMenuClick}
|
onCategoryMenuClick={onSubCategoryMenuClick}
|
||||||
|
|||||||
@@ -2,8 +2,7 @@
|
|||||||
import { derived } from "svelte/store";
|
import { derived } from "svelte/store";
|
||||||
import { CheckBox } from "$lib/components/atoms";
|
import { CheckBox } from "$lib/components/atoms";
|
||||||
import { SubCategories, type SelectedCategory } from "$lib/components/molecules";
|
import { SubCategories, type SelectedCategory } from "$lib/components/molecules";
|
||||||
import type { CategoryInfo } from "$lib/modules/filesystem";
|
import { getFileInfo, type CategoryInfo } from "$lib/modules/filesystem2";
|
||||||
import { getFileInfo } from "$lib/modules/filesystem2";
|
|
||||||
import { SortBy, sortEntries } from "$lib/modules/util";
|
import { SortBy, sortEntries } from "$lib/modules/util";
|
||||||
import { masterKeyStore } from "$lib/stores";
|
import { masterKeyStore } from "$lib/stores";
|
||||||
import File from "./File.svelte";
|
import File from "./File.svelte";
|
||||||
@@ -19,7 +18,7 @@
|
|||||||
onSubCategoryCreateClick: () => void;
|
onSubCategoryCreateClick: () => void;
|
||||||
onSubCategoryMenuClick: (subCategory: SelectedCategory) => void;
|
onSubCategoryMenuClick: (subCategory: SelectedCategory) => void;
|
||||||
sortBy?: SortBy;
|
sortBy?: SortBy;
|
||||||
isFileRecursive: boolean;
|
isFileRecursive?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
let {
|
let {
|
||||||
@@ -81,9 +80,11 @@
|
|||||||
<div class="space-y-4 bg-white p-4">
|
<div class="space-y-4 bg-white p-4">
|
||||||
<div class="flex items-center justify-between">
|
<div class="flex items-center justify-between">
|
||||||
<p class="text-lg font-bold text-gray-800">파일</p>
|
<p class="text-lg font-bold text-gray-800">파일</p>
|
||||||
<CheckBox bind:checked={isFileRecursive}>
|
{#if isFileRecursive !== undefined}
|
||||||
<p class="font-medium">하위 카테고리의 파일</p>
|
<CheckBox bind:checked={isFileRecursive}>
|
||||||
</CheckBox>
|
<p class="font-medium">하위 카테고리의 파일</p>
|
||||||
|
</CheckBox>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
<div class="space-y-1">
|
<div class="space-y-1">
|
||||||
{#key info}
|
{#key info}
|
||||||
|
|||||||
@@ -106,7 +106,10 @@ export const storeCategoryInfo = async (categoryInfo: CategoryInfo) => {
|
|||||||
await filesystem.category.put(categoryInfo);
|
await filesystem.category.put(categoryInfo);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const updateCategoryInfo = async (id: number, changes: { isFileRecursive?: boolean }) => {
|
export const updateCategoryInfo = async (
|
||||||
|
id: number,
|
||||||
|
changes: { name?: string; isFileRecursive?: boolean },
|
||||||
|
) => {
|
||||||
await filesystem.category.update(id, changes);
|
await filesystem.category.update(id, changes);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,151 +0,0 @@
|
|||||||
import { get, writable, type Writable } from "svelte/store";
|
|
||||||
import { callGetApi } from "$lib/hooks";
|
|
||||||
import {
|
|
||||||
getCategoryInfos as getCategoryInfosFromIndexedDB,
|
|
||||||
getCategoryInfo as getCategoryInfoFromIndexedDB,
|
|
||||||
storeCategoryInfo,
|
|
||||||
updateCategoryInfo as updateCategoryInfoInIndexedDB,
|
|
||||||
deleteCategoryInfo,
|
|
||||||
type CategoryId,
|
|
||||||
} from "$lib/indexedDB";
|
|
||||||
import { unwrapDataKey, decryptString } from "$lib/modules/crypto";
|
|
||||||
import type { CategoryInfoResponse, CategoryFileListResponse } from "$lib/server/schemas";
|
|
||||||
|
|
||||||
export type CategoryInfo =
|
|
||||||
| {
|
|
||||||
id: "root";
|
|
||||||
dataKey?: undefined;
|
|
||||||
dataKeyVersion?: undefined;
|
|
||||||
name?: undefined;
|
|
||||||
subCategoryIds: number[];
|
|
||||||
files?: undefined;
|
|
||||||
isFileRecursive?: undefined;
|
|
||||||
}
|
|
||||||
| {
|
|
||||||
id: number;
|
|
||||||
dataKey?: CryptoKey;
|
|
||||||
dataKeyVersion?: Date;
|
|
||||||
name: string;
|
|
||||||
subCategoryIds: number[];
|
|
||||||
files: { id: number; isRecursive: boolean }[];
|
|
||||||
isFileRecursive: boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
const categoryInfoStore = new Map<CategoryId, Writable<CategoryInfo | null>>();
|
|
||||||
|
|
||||||
const fetchCategoryInfoFromIndexedDB = async (
|
|
||||||
id: CategoryId,
|
|
||||||
info: Writable<CategoryInfo | null>,
|
|
||||||
) => {
|
|
||||||
if (get(info)) return;
|
|
||||||
|
|
||||||
const [category, subCategories] = await Promise.all([
|
|
||||||
id !== "root" ? getCategoryInfoFromIndexedDB(id) : undefined,
|
|
||||||
getCategoryInfosFromIndexedDB(id),
|
|
||||||
]);
|
|
||||||
const subCategoryIds = subCategories.map(({ id }) => id);
|
|
||||||
|
|
||||||
if (id === "root") {
|
|
||||||
info.set({ id, subCategoryIds });
|
|
||||||
} else {
|
|
||||||
if (!category) return;
|
|
||||||
info.set({
|
|
||||||
id,
|
|
||||||
name: category.name,
|
|
||||||
subCategoryIds,
|
|
||||||
files: category.files,
|
|
||||||
isFileRecursive: category.isFileRecursive,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const fetchCategoryInfoFromServer = async (
|
|
||||||
id: CategoryId,
|
|
||||||
info: Writable<CategoryInfo | null>,
|
|
||||||
masterKey: CryptoKey,
|
|
||||||
) => {
|
|
||||||
let res = await callGetApi(`/api/category/${id}`);
|
|
||||||
if (res.status === 404) {
|
|
||||||
info.set(null);
|
|
||||||
await deleteCategoryInfo(id as number);
|
|
||||||
return;
|
|
||||||
} else if (!res.ok) {
|
|
||||||
throw new Error("Failed to fetch category information");
|
|
||||||
}
|
|
||||||
|
|
||||||
const { metadata, subCategories }: CategoryInfoResponse = await res.json();
|
|
||||||
|
|
||||||
if (id === "root") {
|
|
||||||
info.set({ id, subCategoryIds: subCategories });
|
|
||||||
} else {
|
|
||||||
const { dataKey } = await unwrapDataKey(metadata!.dek, masterKey);
|
|
||||||
const name = await decryptString(metadata!.name, metadata!.nameIv, dataKey);
|
|
||||||
|
|
||||||
res = await callGetApi(`/api/category/${id}/file/list?recurse=true`);
|
|
||||||
if (!res.ok) {
|
|
||||||
throw new Error("Failed to fetch category files");
|
|
||||||
}
|
|
||||||
|
|
||||||
const { files }: CategoryFileListResponse = await res.json();
|
|
||||||
const filesMapped = files.map(({ file, isRecursive }) => ({ id: file, isRecursive }));
|
|
||||||
let isFileRecursive: boolean | undefined = undefined;
|
|
||||||
|
|
||||||
info.update((value) => {
|
|
||||||
const newValue = {
|
|
||||||
isFileRecursive: false,
|
|
||||||
...value,
|
|
||||||
id,
|
|
||||||
dataKey,
|
|
||||||
dataKeyVersion: new Date(metadata!.dekVersion),
|
|
||||||
name,
|
|
||||||
subCategoryIds: subCategories,
|
|
||||||
files: filesMapped,
|
|
||||||
};
|
|
||||||
isFileRecursive = newValue.isFileRecursive;
|
|
||||||
return newValue;
|
|
||||||
});
|
|
||||||
await storeCategoryInfo({
|
|
||||||
id,
|
|
||||||
parentId: metadata!.parent,
|
|
||||||
name,
|
|
||||||
files: filesMapped,
|
|
||||||
isFileRecursive: isFileRecursive!,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const fetchCategoryInfo = async (
|
|
||||||
id: CategoryId,
|
|
||||||
info: Writable<CategoryInfo | null>,
|
|
||||||
masterKey: CryptoKey,
|
|
||||||
) => {
|
|
||||||
await fetchCategoryInfoFromIndexedDB(id, info);
|
|
||||||
await fetchCategoryInfoFromServer(id, info, masterKey);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getCategoryInfo = (categoryId: CategoryId, masterKey: CryptoKey) => {
|
|
||||||
// TODO: MEK rotation
|
|
||||||
|
|
||||||
let info = categoryInfoStore.get(categoryId);
|
|
||||||
if (!info) {
|
|
||||||
info = writable(null);
|
|
||||||
categoryInfoStore.set(categoryId, info);
|
|
||||||
}
|
|
||||||
|
|
||||||
fetchCategoryInfo(categoryId, info, masterKey); // Intended
|
|
||||||
return info;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const updateCategoryInfo = async (
|
|
||||||
categoryId: number,
|
|
||||||
changes: { isFileRecursive?: boolean },
|
|
||||||
) => {
|
|
||||||
await updateCategoryInfoInIndexedDB(categoryId, changes);
|
|
||||||
categoryInfoStore.get(categoryId)?.update((value) => {
|
|
||||||
if (!value) return value;
|
|
||||||
if (changes.isFileRecursive !== undefined) {
|
|
||||||
value.isFileRecursive = changes.isFileRecursive;
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
294
src/lib/modules/filesystem2/category.ts
Normal file
294
src/lib/modules/filesystem2/category.ts
Normal file
@@ -0,0 +1,294 @@
|
|||||||
|
import { useQueryClient, createQuery, createMutation } from "@tanstack/svelte-query";
|
||||||
|
import { callGetApi, callPostApi } from "$lib/hooks";
|
||||||
|
import {
|
||||||
|
getCategoryInfos as getCategoryInfosFromIndexedDB,
|
||||||
|
getCategoryInfo as getCategoryInfoFromIndexedDB,
|
||||||
|
storeCategoryInfo,
|
||||||
|
updateCategoryInfo,
|
||||||
|
deleteCategoryInfo,
|
||||||
|
type CategoryId,
|
||||||
|
} from "$lib/indexedDB";
|
||||||
|
import {
|
||||||
|
generateDataKey,
|
||||||
|
wrapDataKey,
|
||||||
|
unwrapDataKey,
|
||||||
|
encryptString,
|
||||||
|
decryptString,
|
||||||
|
} from "$lib/modules/crypto";
|
||||||
|
import type {
|
||||||
|
CategoryInfoResponse,
|
||||||
|
CategoryFileListResponse,
|
||||||
|
CategoryRenameRequest,
|
||||||
|
CategoryCreateRequest,
|
||||||
|
CategoryCreateResponse,
|
||||||
|
} from "$lib/server/schemas";
|
||||||
|
import type { MasterKey } from "$lib/stores";
|
||||||
|
|
||||||
|
export type CategoryInfo =
|
||||||
|
| {
|
||||||
|
id: "root";
|
||||||
|
dataKey?: undefined;
|
||||||
|
dataKeyVersion?: undefined;
|
||||||
|
name?: undefined;
|
||||||
|
subCategoryIds: number[];
|
||||||
|
files?: undefined;
|
||||||
|
isFileRecursive?: undefined;
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
id: number;
|
||||||
|
dataKey?: CryptoKey;
|
||||||
|
dataKeyVersion?: Date;
|
||||||
|
name: string;
|
||||||
|
subCategoryIds: number[];
|
||||||
|
files: { id: number; isRecursive: boolean }[];
|
||||||
|
isFileRecursive: boolean;
|
||||||
|
};
|
||||||
|
export type SubCategoryInfo = CategoryInfo & { id: number };
|
||||||
|
|
||||||
|
let temporaryIdCounter = -1;
|
||||||
|
|
||||||
|
const getInitialCategoryInfo = async (id: CategoryId) => {
|
||||||
|
const [category, subCategories] = await Promise.all([
|
||||||
|
id !== "root" ? getCategoryInfoFromIndexedDB(id) : undefined,
|
||||||
|
getCategoryInfosFromIndexedDB(id),
|
||||||
|
]);
|
||||||
|
const subCategoryIds = subCategories.map(({ id }) => id);
|
||||||
|
|
||||||
|
if (id === "root") {
|
||||||
|
return { id, subCategoryIds };
|
||||||
|
} else if (category) {
|
||||||
|
return {
|
||||||
|
id,
|
||||||
|
name: category.name,
|
||||||
|
subCategoryIds,
|
||||||
|
files: category.files,
|
||||||
|
isFileRecursive: category.isFileRecursive,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getCategoryInfo = (id: CategoryId, masterKey: CryptoKey) => {
|
||||||
|
return createQuery<CategoryInfo>({
|
||||||
|
queryKey: ["category", id],
|
||||||
|
queryFn: async ({ client, signal }) => {
|
||||||
|
if (!client.getQueryData<CategoryInfo>(["category", id])) {
|
||||||
|
const initialInfo = await getInitialCategoryInfo(id);
|
||||||
|
if (initialInfo) {
|
||||||
|
setTimeout(() => client.invalidateQueries({ queryKey: ["category", id] }), 0);
|
||||||
|
return initialInfo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const res = await callGetApi(`/api/category/${id}`, { signal }); // TODO: 404
|
||||||
|
const { metadata, subCategories }: CategoryInfoResponse = await res.json();
|
||||||
|
|
||||||
|
if (id === "root") {
|
||||||
|
return { id, subCategoryIds: subCategories };
|
||||||
|
} else {
|
||||||
|
const { dataKey } = await unwrapDataKey(metadata!.dek, masterKey);
|
||||||
|
const name = await decryptString(metadata!.name, metadata!.nameIv, dataKey);
|
||||||
|
|
||||||
|
const res = await callGetApi(`/api/category/${id}/file/list?recurse=true`); // TODO: Error Handling
|
||||||
|
const { files }: CategoryFileListResponse = await res.json();
|
||||||
|
const filesMapped = files.map(({ file, isRecursive }) => ({ id: file, isRecursive }));
|
||||||
|
|
||||||
|
const prevInfo = client.getQueryData<CategoryInfo>(["category", id]);
|
||||||
|
await storeCategoryInfo({
|
||||||
|
id,
|
||||||
|
parentId: metadata!.parent,
|
||||||
|
name,
|
||||||
|
files: filesMapped,
|
||||||
|
isFileRecursive: prevInfo?.isFileRecursive ?? false,
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
id,
|
||||||
|
dataKey,
|
||||||
|
dataKeyVersion: new Date(metadata!.dekVersion),
|
||||||
|
name,
|
||||||
|
subCategoryIds: subCategories,
|
||||||
|
files: filesMapped,
|
||||||
|
isFileRecursive: prevInfo?.isFileRecursive ?? false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
staleTime: Infinity,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export type CategoryInfoStore = ReturnType<typeof getCategoryInfo>;
|
||||||
|
|
||||||
|
export const useCategoryCreation = (parentId: CategoryId, masterKey: MasterKey) => {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
return createMutation<void, Error, { name: string }, { tempId: number }>({
|
||||||
|
mutationFn: async ({ name }) => {
|
||||||
|
const { dataKey, dataKeyVersion } = await generateDataKey();
|
||||||
|
const nameEncrypted = await encryptString(name, dataKey);
|
||||||
|
|
||||||
|
const res = await callPostApi<CategoryCreateRequest>("/api/category/create", {
|
||||||
|
parent: parentId,
|
||||||
|
mekVersion: masterKey.version,
|
||||||
|
dek: await wrapDataKey(dataKey, masterKey.key),
|
||||||
|
dekVersion: dataKeyVersion.toISOString(),
|
||||||
|
name: nameEncrypted.ciphertext,
|
||||||
|
nameIv: nameEncrypted.iv,
|
||||||
|
});
|
||||||
|
if (!res.ok) throw new Error("Failed to create category");
|
||||||
|
|
||||||
|
const { category: id }: CategoryCreateResponse = await res.json();
|
||||||
|
queryClient.setQueryData<CategoryInfo>(["category", id], {
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
dataKey,
|
||||||
|
dataKeyVersion,
|
||||||
|
subCategoryIds: [],
|
||||||
|
files: [],
|
||||||
|
isFileRecursive: false,
|
||||||
|
});
|
||||||
|
await storeCategoryInfo({ id, parentId, name, files: [], isFileRecursive: false });
|
||||||
|
},
|
||||||
|
onMutate: async ({ name }) => {
|
||||||
|
const tempId = temporaryIdCounter--;
|
||||||
|
queryClient.setQueryData<CategoryInfo>(["category", tempId], {
|
||||||
|
id: tempId,
|
||||||
|
name,
|
||||||
|
subCategoryIds: [],
|
||||||
|
files: [],
|
||||||
|
isFileRecursive: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
await queryClient.cancelQueries({ queryKey: ["category", parentId] });
|
||||||
|
queryClient.setQueryData<CategoryInfo>(["category", parentId], (prevParentInfo) => {
|
||||||
|
if (!prevParentInfo) return;
|
||||||
|
return {
|
||||||
|
...prevParentInfo,
|
||||||
|
subCategoryIds: [...prevParentInfo.subCategoryIds, tempId],
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
return { tempId };
|
||||||
|
},
|
||||||
|
onError: (_error, _variables, context) => {
|
||||||
|
if (context) {
|
||||||
|
queryClient.setQueryData<CategoryInfo>(["category", parentId], (prevParentInfo) => {
|
||||||
|
if (!prevParentInfo) return;
|
||||||
|
return {
|
||||||
|
...prevParentInfo,
|
||||||
|
subCategoryIds: prevParentInfo.subCategoryIds.filter((id) => id !== context.tempId),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onSettled: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["category", parentId] });
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useCategoryRename = () => {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
return createMutation<
|
||||||
|
void,
|
||||||
|
Error,
|
||||||
|
{
|
||||||
|
id: number;
|
||||||
|
dataKey: CryptoKey;
|
||||||
|
dataKeyVersion: Date;
|
||||||
|
newName: string;
|
||||||
|
},
|
||||||
|
{ oldName: string | undefined }
|
||||||
|
>({
|
||||||
|
mutationFn: async ({ id, dataKey, dataKeyVersion, newName }) => {
|
||||||
|
const newNameEncrypted = await encryptString(newName, dataKey);
|
||||||
|
const res = await callPostApi<CategoryRenameRequest>(`/api/category/${id}/rename`, {
|
||||||
|
dekVersion: dataKeyVersion.toISOString(),
|
||||||
|
name: newNameEncrypted.ciphertext,
|
||||||
|
nameIv: newNameEncrypted.iv,
|
||||||
|
});
|
||||||
|
if (!res.ok) throw new Error("Failed to rename category");
|
||||||
|
|
||||||
|
await updateCategoryInfo(id, { name: newName });
|
||||||
|
},
|
||||||
|
onMutate: async ({ id, newName }) => {
|
||||||
|
await queryClient.cancelQueries({ queryKey: ["category", id] });
|
||||||
|
|
||||||
|
const prevInfo = queryClient.getQueryData<SubCategoryInfo>(["category", id]);
|
||||||
|
if (prevInfo) {
|
||||||
|
queryClient.setQueryData<CategoryInfo>(["category", id], {
|
||||||
|
...prevInfo,
|
||||||
|
name: newName,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return { oldName: prevInfo?.name };
|
||||||
|
},
|
||||||
|
onError: (_error, { id }, context) => {
|
||||||
|
if (context?.oldName) {
|
||||||
|
queryClient.setQueryData<SubCategoryInfo>(["category", id], (prevInfo) => {
|
||||||
|
if (!prevInfo) return;
|
||||||
|
return { ...prevInfo, name: context.oldName! };
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onSettled: (_data, _error, { id }) => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["category", id] });
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useCategoryDeletion = (parentId: CategoryId) => {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
return createMutation<void, Error, { id: number }, {}>({
|
||||||
|
mutationFn: async ({ id }) => {
|
||||||
|
const res = await callPostApi(`/api/category/${id}/delete`);
|
||||||
|
if (!res.ok) throw new Error("Failed to delete category");
|
||||||
|
|
||||||
|
await deleteCategoryInfo(id);
|
||||||
|
|
||||||
|
// TODO: Update FileInfo
|
||||||
|
},
|
||||||
|
onMutate: async ({ id }) => {
|
||||||
|
await queryClient.cancelQueries({ queryKey: ["category", parentId] });
|
||||||
|
queryClient.setQueryData<CategoryInfo>(["category", parentId], (prevParentInfo) => {
|
||||||
|
if (!prevParentInfo) return;
|
||||||
|
return {
|
||||||
|
...prevParentInfo,
|
||||||
|
subCategoryIds: prevParentInfo.subCategoryIds.filter((categoryId) => categoryId !== id),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
return {};
|
||||||
|
},
|
||||||
|
onError: (_error, { id }, context) => {
|
||||||
|
if (context) {
|
||||||
|
queryClient.setQueryData<CategoryInfo>(["category", parentId], (prevParentInfo) => {
|
||||||
|
if (!prevParentInfo) return;
|
||||||
|
return {
|
||||||
|
...prevParentInfo,
|
||||||
|
subCategoryIds: [...prevParentInfo.subCategoryIds, id],
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onSettled: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["category", parentId] });
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useCategoryFileRecursionToggle = () => {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
return createMutation<void, Error, { id: number; isFileRecursive: boolean }, {}>({
|
||||||
|
mutationFn: async ({ id, isFileRecursive }) => {
|
||||||
|
await updateCategoryInfo(id, { isFileRecursive });
|
||||||
|
},
|
||||||
|
onMutate: async ({ id, isFileRecursive }) => {
|
||||||
|
const prevInfo = queryClient.getQueryData<SubCategoryInfo>(["category", id]);
|
||||||
|
if (prevInfo) {
|
||||||
|
queryClient.setQueryData<CategoryInfo>(["category", id], {
|
||||||
|
...prevInfo,
|
||||||
|
isFileRecursive,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -1,2 +1,3 @@
|
|||||||
|
export * from "./category";
|
||||||
export * from "./directory";
|
export * from "./directory";
|
||||||
export * from "./file";
|
export * from "./file";
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ interface Category {
|
|||||||
export type NewCategory = Omit<Category, "id">;
|
export type NewCategory = Omit<Category, "id">;
|
||||||
|
|
||||||
export const registerCategory = async (params: NewCategory) => {
|
export const registerCategory = async (params: NewCategory) => {
|
||||||
await db.transaction().execute(async (trx) => {
|
return await db.transaction().execute(async (trx) => {
|
||||||
const mek = await trx
|
const mek = await trx
|
||||||
.selectFrom("master_encryption_key")
|
.selectFrom("master_encryption_key")
|
||||||
.select("version")
|
.select("version")
|
||||||
@@ -51,6 +51,7 @@ export const registerCategory = async (params: NewCategory) => {
|
|||||||
new_name: params.encName,
|
new_name: params.encName,
|
||||||
})
|
})
|
||||||
.execute();
|
.execute();
|
||||||
|
return { id: categoryId };
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -53,3 +53,8 @@ export const categoryCreateRequest = z.object({
|
|||||||
nameIv: z.string().base64().nonempty(),
|
nameIv: z.string().base64().nonempty(),
|
||||||
});
|
});
|
||||||
export type CategoryCreateRequest = z.input<typeof categoryCreateRequest>;
|
export type CategoryCreateRequest = z.input<typeof categoryCreateRequest>;
|
||||||
|
|
||||||
|
export const categoryCreateResponse = z.object({
|
||||||
|
category: z.number().int().positive(),
|
||||||
|
});
|
||||||
|
export type CategoryCreateResponse = z.output<typeof categoryCreateResponse>;
|
||||||
|
|||||||
@@ -123,7 +123,8 @@ export const createCategory = async (params: NewCategory) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await registerCategory(params);
|
const { id } = await registerCategory(params);
|
||||||
|
return { id };
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof IntegrityError && e.message === "Inactive MEK version") {
|
if (e instanceof IntegrityError && e.message === "Inactive MEK version") {
|
||||||
error(400, "Inactive MEK version");
|
error(400, "Inactive MEK version");
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
import { goto } from "$app/navigation";
|
import { goto } from "$app/navigation";
|
||||||
import { FullscreenDiv } from "$lib/components/atoms";
|
import { FullscreenDiv } from "$lib/components/atoms";
|
||||||
import { Categories, IconEntryButton, TopBar } from "$lib/components/molecules";
|
import { Categories, IconEntryButton, TopBar } from "$lib/components/molecules";
|
||||||
import { getCategoryInfo, type CategoryInfo } from "$lib/modules/filesystem";
|
import { getCategoryInfo, type CategoryInfo } from "$lib/modules/filesystem2";
|
||||||
import { getFileInfo } from "$lib/modules/filesystem2";
|
import { getFileInfo } from "$lib/modules/filesystem2";
|
||||||
import { captureVideoThumbnail } from "$lib/modules/thumbnail";
|
import { captureVideoThumbnail } from "$lib/modules/thumbnail";
|
||||||
import { fileDownloadStatusStore, isFileDownloading, masterKeyStore } from "$lib/stores";
|
import { fileDownloadStatusStore, isFileDownloading, masterKeyStore } from "$lib/stores";
|
||||||
@@ -25,7 +25,6 @@
|
|||||||
let { data } = $props();
|
let { data } = $props();
|
||||||
|
|
||||||
let info = $derived(getFileInfo(data.id, $masterKeyStore?.get(1)?.key!));
|
let info = $derived(getFileInfo(data.id, $masterKeyStore?.get(1)?.key!));
|
||||||
let categories: Writable<CategoryInfo | null>[] = $state([]);
|
|
||||||
|
|
||||||
let isAddToCategoryBottomSheetOpen = $state(false);
|
let isAddToCategoryBottomSheetOpen = $state(false);
|
||||||
|
|
||||||
@@ -86,11 +85,6 @@
|
|||||||
viewerType = undefined;
|
viewerType = undefined;
|
||||||
});
|
});
|
||||||
|
|
||||||
$effect(() => {
|
|
||||||
categories =
|
|
||||||
$info.data?.categoryIds.map((id) => getCategoryInfo(id, $masterKeyStore?.get(1)?.key!)) ?? [];
|
|
||||||
});
|
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
if ($info.data?.dataKey && $info.data?.contentIv) {
|
if ($info.data?.dataKey && $info.data?.contentIv) {
|
||||||
const contentType = $info.data.contentType;
|
const contentType = $info.data.contentType;
|
||||||
@@ -170,7 +164,7 @@
|
|||||||
<p class="text-lg font-bold">카테고리</p>
|
<p class="text-lg font-bold">카테고리</p>
|
||||||
<div class="space-y-1">
|
<div class="space-y-1">
|
||||||
<Categories
|
<Categories
|
||||||
{categories}
|
categoryIds={$info.data?.categoryIds ?? []}
|
||||||
categoryMenuIcon={IconClose}
|
categoryMenuIcon={IconClose}
|
||||||
onCategoryClick={({ id }) => goto(`/category/${id}`)}
|
onCategoryClick={({ id }) => goto(`/category/${id}`)}
|
||||||
onCategoryMenuClick={({ id }) => removeFromCategory(id)}
|
onCategoryMenuClick={({ id }) => removeFromCategory(id)}
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { Writable } from "svelte/store";
|
|
||||||
import { BottomDiv, BottomSheet, Button, FullscreenDiv } from "$lib/components/atoms";
|
import { BottomDiv, BottomSheet, Button, FullscreenDiv } from "$lib/components/atoms";
|
||||||
import { SubCategories } from "$lib/components/molecules";
|
import { SubCategories } from "$lib/components/molecules";
|
||||||
import { CategoryCreateModal } from "$lib/components/organisms";
|
import { CategoryCreateModal } from "$lib/components/organisms";
|
||||||
import { getCategoryInfo, type CategoryInfo } from "$lib/modules/filesystem";
|
import { getCategoryInfo, type CategoryInfoStore } from "$lib/modules/filesystem2";
|
||||||
import { masterKeyStore } from "$lib/stores";
|
import { masterKeyStore } from "$lib/stores";
|
||||||
import { requestCategoryCreation } from "./service";
|
import { requestCategoryCreation } from "./service";
|
||||||
|
|
||||||
@@ -14,7 +13,7 @@
|
|||||||
|
|
||||||
let { onAddToCategoryClick, isOpen = $bindable() }: Props = $props();
|
let { onAddToCategoryClick, isOpen = $bindable() }: Props = $props();
|
||||||
|
|
||||||
let category: Writable<CategoryInfo | null> | undefined = $state();
|
let category: CategoryInfoStore | undefined = $state();
|
||||||
|
|
||||||
let isCategoryCreateModalOpen = $state(false);
|
let isCategoryCreateModalOpen = $state(false);
|
||||||
|
|
||||||
@@ -25,20 +24,20 @@
|
|||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if $category}
|
{#if $category?.status === "success"}
|
||||||
<BottomSheet bind:isOpen class="flex flex-col">
|
<BottomSheet bind:isOpen class="flex flex-col">
|
||||||
<FullscreenDiv>
|
<FullscreenDiv>
|
||||||
<SubCategories
|
<SubCategories
|
||||||
class="py-4"
|
class="py-4"
|
||||||
info={$category}
|
info={$category.data}
|
||||||
onSubCategoryClick={({ id }) =>
|
onSubCategoryClick={({ id }) =>
|
||||||
(category = getCategoryInfo(id, $masterKeyStore?.get(1)?.key!))}
|
(category = getCategoryInfo(id, $masterKeyStore?.get(1)?.key!))}
|
||||||
onSubCategoryCreateClick={() => (isCategoryCreateModalOpen = true)}
|
onSubCategoryCreateClick={() => (isCategoryCreateModalOpen = true)}
|
||||||
subCategoryCreatePosition="top"
|
subCategoryCreatePosition="top"
|
||||||
/>
|
/>
|
||||||
{#if $category.id !== "root"}
|
{#if $category.data.id !== "root"}
|
||||||
<BottomDiv>
|
<BottomDiv>
|
||||||
<Button onclick={() => onAddToCategoryClick($category.id)} class="w-full">
|
<Button onclick={() => onAddToCategoryClick($category.data.id as number)} class="w-full">
|
||||||
이 카테고리에 추가하기
|
이 카테고리에 추가하기
|
||||||
</Button>
|
</Button>
|
||||||
</BottomDiv>
|
</BottomDiv>
|
||||||
@@ -50,8 +49,8 @@
|
|||||||
<CategoryCreateModal
|
<CategoryCreateModal
|
||||||
bind:isOpen={isCategoryCreateModalOpen}
|
bind:isOpen={isCategoryCreateModalOpen}
|
||||||
onCreateClick={async (name: string) => {
|
onCreateClick={async (name: string) => {
|
||||||
if (await requestCategoryCreation(name, $category!.id, $masterKeyStore?.get(1)!)) {
|
if (await requestCategoryCreation(name, $category!.data!.id, $masterKeyStore?.get(1)!)) {
|
||||||
category = getCategoryInfo($category!.id, $masterKeyStore?.get(1)?.key!); // TODO: FIXME
|
category = getCategoryInfo($category!.data!.id, $masterKeyStore?.get(1)?.key!); // TODO: FIXME
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { Writable } from "svelte/store";
|
|
||||||
import { goto } from "$app/navigation";
|
import { goto } from "$app/navigation";
|
||||||
import { TopBar } from "$lib/components/molecules";
|
import { TopBar } from "$lib/components/molecules";
|
||||||
import { Category, CategoryCreateModal } from "$lib/components/organisms";
|
import { Category, CategoryCreateModal } from "$lib/components/organisms";
|
||||||
import { getCategoryInfo, updateCategoryInfo, type CategoryInfo } from "$lib/modules/filesystem";
|
import { getCategoryInfo, useCategoryFileRecursionToggle } from "$lib/modules/filesystem2";
|
||||||
import { masterKeyStore } from "$lib/stores";
|
import { masterKeyStore } from "$lib/stores";
|
||||||
import CategoryDeleteModal from "./CategoryDeleteModal.svelte";
|
import CategoryDeleteModal from "./CategoryDeleteModal.svelte";
|
||||||
import CategoryMenuBottomSheet from "./CategoryMenuBottomSheet.svelte";
|
import CategoryMenuBottomSheet from "./CategoryMenuBottomSheet.svelte";
|
||||||
@@ -19,9 +18,9 @@
|
|||||||
let { data } = $props();
|
let { data } = $props();
|
||||||
let context = createContext();
|
let context = createContext();
|
||||||
|
|
||||||
let info: Writable<CategoryInfo | null> | undefined = $state();
|
let info = $derived(getCategoryInfo(data.id, $masterKeyStore?.get(1)?.key!));
|
||||||
|
let toggleFileRecursion = useCategoryFileRecursionToggle();
|
||||||
let isFileRecursive: boolean | undefined = $state();
|
let isFileRecursive = $derived($info.data?.isFileRecursive);
|
||||||
|
|
||||||
let isCategoryCreateModalOpen = $state(false);
|
let isCategoryCreateModalOpen = $state(false);
|
||||||
let isCategoryMenuBottomSheetOpen = $state(false);
|
let isCategoryMenuBottomSheetOpen = $state(false);
|
||||||
@@ -29,19 +28,8 @@
|
|||||||
let isCategoryDeleteModalOpen = $state(false);
|
let isCategoryDeleteModalOpen = $state(false);
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
info = getCategoryInfo(data.id, $masterKeyStore?.get(1)?.key!);
|
if (isFileRecursive !== undefined && $info.data?.isFileRecursive !== isFileRecursive) {
|
||||||
isFileRecursive = undefined;
|
$toggleFileRecursion.mutate({ id: data.id as number, isFileRecursive });
|
||||||
});
|
|
||||||
|
|
||||||
$effect(() => {
|
|
||||||
if ($info && isFileRecursive === undefined) {
|
|
||||||
isFileRecursive = $info.isFileRecursive ?? false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$effect(() => {
|
|
||||||
if (data.id !== "root" && $info?.isFileRecursive !== isFileRecursive) {
|
|
||||||
updateCategoryInfo(data.id as number, { isFileRecursive });
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
@@ -51,13 +39,13 @@
|
|||||||
</svelte:head>
|
</svelte:head>
|
||||||
|
|
||||||
{#if data.id !== "root"}
|
{#if data.id !== "root"}
|
||||||
<TopBar title={$info?.name} />
|
<TopBar title={$info.data?.name} />
|
||||||
{/if}
|
{/if}
|
||||||
<div class="min-h-full bg-gray-100 pb-[5.5em]">
|
<div class="min-h-full bg-gray-100 pb-[5.5em]">
|
||||||
{#if $info && isFileRecursive !== undefined}
|
{#if $info.status === "success"}
|
||||||
<Category
|
<Category
|
||||||
bind:isFileRecursive
|
bind:isFileRecursive
|
||||||
info={$info}
|
info={$info.data}
|
||||||
onFileClick={({ id }) => goto(`/file/${id}`)}
|
onFileClick={({ id }) => goto(`/file/${id}`)}
|
||||||
onFileRemoveClick={async ({ id }) => {
|
onFileRemoveClick={async ({ id }) => {
|
||||||
await requestFileRemovalFromCategory(id, data.id as number);
|
await requestFileRemovalFromCategory(id, data.id as number);
|
||||||
|
|||||||
@@ -35,6 +35,8 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
|
window.__TANSTACK_QUERY_CLIENT__ = queryClient;
|
||||||
|
|
||||||
const goto = async (url: string) => {
|
const goto = async (url: string) => {
|
||||||
const whitelist = ["/auth/login", "/key", "/client/pending"];
|
const whitelist = ["/auth/login", "/key", "/client/pending"];
|
||||||
if (!whitelist.some((path) => location.pathname.startsWith(path))) {
|
if (!whitelist.some((path) => location.pathname.startsWith(path))) {
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
import { error, text } from "@sveltejs/kit";
|
import { error, json } from "@sveltejs/kit";
|
||||||
import { authorize } from "$lib/server/modules/auth";
|
import { authorize } from "$lib/server/modules/auth";
|
||||||
import { categoryCreateRequest } from "$lib/server/schemas";
|
import {
|
||||||
|
categoryCreateRequest,
|
||||||
|
categoryCreateResponse,
|
||||||
|
type CategoryCreateResponse,
|
||||||
|
} from "$lib/server/schemas";
|
||||||
import { createCategory } from "$lib/server/services/category";
|
import { createCategory } from "$lib/server/services/category";
|
||||||
import type { RequestHandler } from "./$types";
|
import type { RequestHandler } from "./$types";
|
||||||
|
|
||||||
@@ -11,7 +15,7 @@ export const POST: RequestHandler = async ({ locals, request }) => {
|
|||||||
if (!zodRes.success) error(400, "Invalid request body");
|
if (!zodRes.success) error(400, "Invalid request body");
|
||||||
const { parent, mekVersion, dek, dekVersion, name, nameIv } = zodRes.data;
|
const { parent, mekVersion, dek, dekVersion, name, nameIv } = zodRes.data;
|
||||||
|
|
||||||
await createCategory({
|
const { id } = await createCategory({
|
||||||
userId,
|
userId,
|
||||||
parentId: parent,
|
parentId: parent,
|
||||||
mekVersion,
|
mekVersion,
|
||||||
@@ -19,5 +23,5 @@ export const POST: RequestHandler = async ({ locals, request }) => {
|
|||||||
dekVersion: new Date(dekVersion),
|
dekVersion: new Date(dekVersion),
|
||||||
encName: { ciphertext: name, iv: nameIv },
|
encName: { ciphertext: name, iv: nameIv },
|
||||||
});
|
});
|
||||||
return text("Category created", { headers: { "Content-Type": "text/plain" } });
|
return json(categoryCreateResponse.parse({ category: id } satisfies CategoryCreateResponse));
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user