mirror of
https://github.com/kmc7468/arkvault.git
synced 2025-12-16 06:58:46 +00:00
파일/폴더 삭제 및 이름 변경 구현 완료
This commit is contained in:
@@ -9,20 +9,30 @@ import {
|
||||
decryptString,
|
||||
} from "$lib/modules/crypto";
|
||||
import type {
|
||||
DirectoryRenameRequest,
|
||||
DirectoryInfoResponse,
|
||||
DirectoryCreateRequest,
|
||||
FileRenameRequest,
|
||||
FileUploadRequest,
|
||||
} from "$lib/server/schemas";
|
||||
import type { MasterKey } from "$lib/stores";
|
||||
|
||||
export { decryptFileMetadata } from "$lib/services/file";
|
||||
|
||||
export interface SelectedDirectoryEntry {
|
||||
type: "directory" | "file";
|
||||
id: number;
|
||||
dataKey: CryptoKey;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export const decryptDirectoryMetadata = async (
|
||||
metadata: NonNullable<DirectoryInfoResponse["metadata"]>,
|
||||
masterKey: CryptoKey,
|
||||
) => {
|
||||
const { dataKey } = await unwrapDataKey(metadata.dek, masterKey);
|
||||
return {
|
||||
dataKey,
|
||||
name: await decryptString(metadata.name, metadata.nameIv, dataKey),
|
||||
};
|
||||
};
|
||||
@@ -71,3 +81,26 @@ export const requestFileUpload = async (
|
||||
xhr.open("POST", "/api/file/upload");
|
||||
xhr.send(form);
|
||||
};
|
||||
|
||||
export const requestDirectoryEntryRename = async (
|
||||
entry: SelectedDirectoryEntry,
|
||||
newName: string,
|
||||
) => {
|
||||
const newNameEncrypted = await encryptString(newName, entry.dataKey);
|
||||
|
||||
if (entry.type === "directory") {
|
||||
await callPostApi<DirectoryRenameRequest>(`/api/directory/${entry.id}/rename`, {
|
||||
name: newNameEncrypted.ciphertext,
|
||||
nameIv: newNameEncrypted.iv,
|
||||
});
|
||||
} else {
|
||||
await callPostApi<FileRenameRequest>(`/api/file/${entry.id}/rename`, {
|
||||
name: newNameEncrypted.ciphertext,
|
||||
nameIv: newNameEncrypted.iv,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const requestDirectoryEntryDeletion = async (entry: SelectedDirectoryEntry) => {
|
||||
await callPostApi(`/api/${entry.type}/${entry.id}/delete`);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user