삭제된 파일의 캐시가 존재하는 경우 캐시 페이지의 로딩이 끝나지 않는 버그 수정

This commit is contained in:
static
2026-01-01 21:41:53 +09:00
parent 182ec18a2b
commit 841c57e8fc
16 changed files with 98 additions and 59 deletions

View File

@@ -1,9 +1,9 @@
import * as IndexedDB from "$lib/indexedDB";
import { trpc, isTRPCClientError } from "$trpc/client";
import { FilesystemCache, decryptFileMetadata, decryptCategoryMetadata } from "./internal.svelte";
import type { CategoryInfo } from "./types";
import type { MaybeCategoryInfo } from "./types";
const cache = new FilesystemCache<CategoryId, CategoryInfo, Partial<CategoryInfo>>();
const cache = new FilesystemCache<CategoryId, MaybeCategoryInfo, Partial<MaybeCategoryInfo>>();
const fetchFromIndexedDB = async (id: CategoryId) => {
const [category, subCategories] = await Promise.all([
@@ -29,10 +29,15 @@ const fetchFromIndexedDB = async (id: CategoryId) => {
: undefined;
if (id === "root") {
return { id, subCategories };
return {
id,
exists: true as const,
subCategories,
};
} else if (category) {
return {
id,
exists: true as const,
name: category.name,
subCategories,
files: files!.filter((file) => !!file),
@@ -68,10 +73,15 @@ const fetchFromServer = async (id: CategoryId, masterKey: CryptoKey) => {
]);
if (id === "root") {
return { id, subCategories };
return {
id,
exists: true as const,
subCategories,
};
} else {
return {
id,
exists: true as const,
subCategories,
files,
...(await decryptCategoryMetadata(metadata!, masterKey)),
@@ -79,9 +89,8 @@ const fetchFromServer = async (id: CategoryId, masterKey: CryptoKey) => {
}
} catch (e) {
if (isTRPCClientError(e) && e.data?.code === "NOT_FOUND") {
cache.delete(id);
await IndexedDB.deleteCategoryInfo(id as number);
return;
return { id, exists: false as const };
}
throw e;
}

View File

@@ -2,9 +2,9 @@ import * as IndexedDB from "$lib/indexedDB";
import { monotonicResolve } from "$lib/utils";
import { trpc, isTRPCClientError } from "$trpc/client";
import { FilesystemCache, decryptDirectoryMetadata, decryptFileMetadata } from "./internal.svelte";
import type { DirectoryInfo } from "./types";
import type { MaybeDirectoryInfo } from "./types";
const cache = new FilesystemCache<DirectoryId, DirectoryInfo>();
const cache = new FilesystemCache<DirectoryId, MaybeDirectoryInfo>();
const fetchFromIndexedDB = async (id: DirectoryId) => {
const [directory, subDirectories, files] = await Promise.all([
@@ -14,9 +14,21 @@ const fetchFromIndexedDB = async (id: DirectoryId) => {
]);
if (id === "root") {
return { id, subDirectories, files };
return {
id,
exists: true as const,
subDirectories,
files,
};
} else if (directory) {
return { id, parentId: directory.parentId, name: directory.name, subDirectories, files };
return {
id,
exists: true as const,
parentId: directory.parentId,
name: directory.name,
subDirectories,
files,
};
}
};
@@ -44,10 +56,16 @@ const fetchFromServer = async (id: DirectoryId, masterKey: CryptoKey) => {
]);
if (id === "root") {
return { id, subDirectories, files };
return {
id,
exists: true as const,
subDirectories,
files,
};
} else {
return {
id,
exists: true as const,
parentId: metadata!.parent,
subDirectories,
files,
@@ -56,9 +74,8 @@ const fetchFromServer = async (id: DirectoryId, masterKey: CryptoKey) => {
}
} catch (e) {
if (isTRPCClientError(e) && e.data?.code === "NOT_FOUND") {
cache.delete(id);
await IndexedDB.deleteDirectoryInfo(id as number);
return;
return { id, exists: false as const };
}
throw e;
}

View File

@@ -2,9 +2,9 @@ import * as IndexedDB from "$lib/indexedDB";
import { monotonicResolve } from "$lib/utils";
import { trpc, isTRPCClientError } from "$trpc/client";
import { FilesystemCache, decryptFileMetadata, decryptCategoryMetadata } from "./internal.svelte";
import type { FileInfo } from "./types";
import type { MaybeFileInfo } from "./types";
const cache = new FilesystemCache<number, FileInfo>();
const cache = new FilesystemCache<number, MaybeFileInfo>();
const fetchFromIndexedDB = async (id: number) => {
const file = await IndexedDB.getFileInfo(id);
@@ -20,6 +20,7 @@ const fetchFromIndexedDB = async (id: number) => {
if (file) {
return {
id,
exists: true as const,
parentId: file.parentId,
contentType: file.contentType,
name: file.name,
@@ -44,6 +45,7 @@ const fetchFromServer = async (id: number, masterKey: CryptoKey) => {
return {
id,
exists: true as const,
parentId: metadata.parent,
contentType: metadata.contentType,
contentIv: metadata.contentIv,
@@ -52,9 +54,8 @@ const fetchFromServer = async (id: number, masterKey: CryptoKey) => {
};
} catch (e) {
if (isTRPCClientError(e) && e.data?.code === "NOT_FOUND") {
cache.delete(id);
await IndexedDB.deleteFileInfo(id);
return;
return { id, exists: false as const };
}
throw e;
}

View File

@@ -30,10 +30,6 @@ export class FilesystemCache<K, V extends RV, RV = V> {
return info ?? promise;
}
delete(key: K) {
this.map.delete(key);
}
}
export const decryptDirectoryMetadata = async (

View File

@@ -1,4 +1,5 @@
export type DataKey = { key: CryptoKey; version: Date };
type AllUndefined<T> = { [K in keyof T]?: undefined };
interface LocalDirectoryInfo {
id: number;
@@ -20,6 +21,9 @@ interface RootDirectoryInfo {
export type DirectoryInfo = LocalDirectoryInfo | RootDirectoryInfo;
export type SubDirectoryInfo = Omit<LocalDirectoryInfo, "parentId" | "subDirectories" | "files">;
export type MaybeDirectoryInfo =
| (DirectoryInfo & { exists: true })
| ({ id: DirectoryId; exists: false } & AllUndefined<Omit<DirectoryInfo, "id">>);
export interface FileInfo {
id: number;
@@ -35,6 +39,9 @@ export interface FileInfo {
export type SummarizedFileInfo = Omit<FileInfo, "parentId" | "contentIv" | "categories">;
export type CategoryFileInfo = SummarizedFileInfo & { isRecursive: boolean };
export type MaybeFileInfo =
| (FileInfo & { exists: true })
| ({ id: number; exists: false } & AllUndefined<Omit<FileInfo, "id">>);
interface LocalCategoryInfo {
id: number;
@@ -59,3 +66,6 @@ export type SubCategoryInfo = Omit<
LocalCategoryInfo,
"subCategories" | "files" | "isFileRecursive"
>;
export type MaybeCategoryInfo =
| (CategoryInfo & { exists: true })
| ({ id: CategoryId; exists: false } & AllUndefined<Omit<CategoryInfo, "id">>);