파일 시스템 관련 상태와 변경 로직을 도메인 모듈로 통합하여 캐시가 자동으로 갱신되도록 개선하고 오류를 토스트로 표시하도록 변경

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
staticandClaude Opus 5.5 committed 2026-10-12 00:22:25 +09:00
1 parent 2ce73aa331
commit 4e82c5e556
67 files changed
+1091 -1082

No files matched your search

+2 -1
View File
@@ -1,6 +1,7 @@
/* eslint-disable svelte/prefer-svelte-reactivity -- Lookup tables of reactive entries */
import { LRUCache } from "lru-cache";
import { deleteDirectory, deleteFile, readFile, writeFile } from "#lib/client/storage/opfs.js";
import type { SummarizedFileInfo } from "#lib/modules/filesystem/index.js";
import type { SummarizedFileInfo } from "#lib/features/filesystem/index.js";
import { decryptChunk, encodeToBase64 } from "#lib/shared/crypto/index.js";
export interface Thumbnail {
+10 -10
View File
@@ -63,8 +63,8 @@ export const requestClientRegistration = async () => {
answerSig: await answerChallenge(challenge, clientKeys),
});
return true;
} catch {
// TODO: Error Handling
} catch (e) {
console.error(e);
return false;
}
};
@@ -95,9 +95,9 @@ export const registerInitialMasterKeyAndHmacSecret = async (
});
} catch (e) {
if (isTRPCClientError(e) && (e.data?.code === "FORBIDDEN" || e.data?.code === "CONFLICT")) {
return true;
return true; // Already registered by another client
}
// TODO: Error Handling
console.error(e);
return false;
}
@@ -107,8 +107,8 @@ export const registerInitialMasterKeyAndHmacSecret = async (
hsk: hmacSecretWrapped,
});
return true;
} catch {
// TODO: Error Handling
} catch (e) {
console.error(e);
return false;
}
};
@@ -117,8 +117,8 @@ export const downloadHmacSecrets = async () => {
let hmacSecretsWrapped;
try {
hmacSecretsWrapped = await trpc.hsk.list.query();
} catch {
// TODO: Error Handling
} catch (e) {
console.error(e);
return false;
}
@@ -143,8 +143,8 @@ export const downloadMasterKeys = async () => {
let masterKeysWrapped;
try {
masterKeysWrapped = await trpc.mek.list.query();
} catch {
// TODO: Error Handling
} catch (e) {
console.error(e);
return false;
}
+49
View File
@@ -0,0 +1,49 @@
import { isTRPCClientError } from "#trpc/client.js";
export interface Toast {
id: number;
message: string;
}
const TOAST_DURATION = 3000;
let toasts: Toast[] = $state([]);
let nextId = 0;
export const getToasts = () => toasts;
export const showToast = (message: string) => {
const toast = { id: nextId++, message };
toasts.push(toast);
setTimeout(() => {
toasts = toasts.filter(({ id }) => id !== toast.id);
}, TOAST_DURATION);
};
const getErrorMessage = (e: unknown, fallbackMessage: string) => {
if (isTRPCClientError(e)) {
switch (e.data?.code) {
case "NOT_FOUND":
return "대상을 찾을 수 없어요. 이미 삭제되었을 수 있어요.";
case undefined:
return "서버에 연결할 수 없어요.";
}
}
return fallbackMessage;
};
export const showErrorToast = (e: unknown, fallbackMessage: string) => {
console.error(e);
showToast(getErrorMessage(e, fallbackMessage));
};
// Runs the action and shows the error to the user if it fails. Returns whether it succeeded.
export const tryAction = async (action: () => Promise<unknown>, errorMessage: string) => {
try {
await action();
return true;
} catch (e) {
showErrorToast(e, errorMessage);
return false;
}
};