클라이언트가 시작될 때 삭제된 파일이나 디렉터리 정보를 IndexedDB에서 삭제하도록 개선

This commit is contained in:
static
2025-01-17 13:02:21 +09:00
parent 7aa6ba0eab
commit 620d174e9b
3 changed files with 54 additions and 4 deletions

View File

@@ -4,9 +4,11 @@ import {
getDirectoryInfos as getDirectoryInfosFromIndexedDB,
getDirectoryInfo as getDirectoryInfoFromIndexedDB,
storeDirectoryInfo,
deleteDirectoryInfo,
getFileInfos as getFileInfosFromIndexedDB,
getFileInfo as getFileInfoFromIndexedDB,
storeFileInfo,
deleteFileInfo,
type DirectoryId,
} from "$lib/indexedDB";
import { unwrapDataKey, decryptString } from "$lib/modules/crypto";
@@ -72,7 +74,13 @@ const fetchDirectoryInfoFromServer = async (
masterKey: CryptoKey,
) => {
const res = await callGetApi(`/api/directory/${id}`);
if (!res.ok) throw new Error("Failed to fetch directory information"); // TODO: Handle 404
if (res.status === 404) {
info.set(null);
await deleteDirectoryInfo(id as number);
} else if (!res.ok) {
throw new Error("Failed to fetch directory information");
}
const {
metadata,
subDirectories: subDirectoryIds,
@@ -138,10 +146,16 @@ const fetchFileInfoFromServer = async (
masterKey: CryptoKey,
) => {
const res = await callGetApi(`/api/file/${id}`);
if (!res.ok) throw new Error("Failed to fetch file information"); // TODO: Handle 404
const metadata: FileInfoResponse = await res.json();
if (res.status === 404) {
info.set(null);
await deleteFileInfo(id);
} else if (!res.ok) {
throw new Error("Failed to fetch file information");
}
const metadata: FileInfoResponse = await res.json();
const { dataKey } = await unwrapDataKey(metadata.dek, masterKey);
const name = await decryptString(metadata.name, metadata.nameIv, dataKey);
const createdAt =
metadata.createdAt && metadata.createdAtIv