mirror of
https://github.com/kmc7468/arkvault.git
synced 2026-02-04 16:16:55 +00:00
기존에 제작된 모달들을 ActionModal 컴포넌트 기반으로 재구성
This commit is contained in:
34
src/routes/(main)/category/[[id]]/service.svelte.ts
Normal file
34
src/routes/(main)/category/[[id]]/service.svelte.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { getContext, setContext } from "svelte";
|
||||
import { callPostApi } from "$lib/hooks";
|
||||
import { encryptString } from "$lib/modules/crypto";
|
||||
import type { SelectedCategory } from "$lib/molecules/Categories";
|
||||
import type { CategoryRenameRequest } from "$lib/server/schemas";
|
||||
|
||||
export { requestCategoryCreation, requestFileRemovalFromCategory } from "$lib/services/category";
|
||||
|
||||
export const createContext = () => {
|
||||
const context = $state({
|
||||
selectedCategory: undefined as SelectedCategory | undefined,
|
||||
});
|
||||
return setContext("context", context);
|
||||
};
|
||||
|
||||
export const useContext = () => {
|
||||
return getContext<ReturnType<typeof createContext>>("context");
|
||||
};
|
||||
|
||||
export const requestCategoryRename = async (category: SelectedCategory, newName: string) => {
|
||||
const newNameEncrypted = await encryptString(newName, category.dataKey);
|
||||
|
||||
const res = await callPostApi<CategoryRenameRequest>(`/api/category/${category.id}/rename`, {
|
||||
dekVersion: category.dataKeyVersion.toISOString(),
|
||||
name: newNameEncrypted.ciphertext,
|
||||
nameIv: newNameEncrypted.iv,
|
||||
});
|
||||
return res.ok;
|
||||
};
|
||||
|
||||
export const requestCategoryDeletion = async (category: SelectedCategory) => {
|
||||
const res = await callPostApi(`/api/category/${category.id}/delete`);
|
||||
return res.ok;
|
||||
};
|
||||
Reference in New Issue
Block a user