mirror of
https://github.com/kmc7468/arkvault.git
synced 2026-11-04 08:10:28 +09:00
컴포넌트를 도메인과 무관한 UI 컴포넌트와 도메인 컴포넌트로 재구성하고 중복된 파일 목록 컴포넌트 통합 및 모듈 간 의존성 방향을 ESLint로 강제
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4e82c5e556
commit
877cf9c42e
94 files changed
+398
-518
No files matched your search
+5
-2
@@ -1,7 +1,6 @@
|
||||
/* 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/features/filesystem/index.js";
|
||||
import { decryptChunk, encodeToBase64 } from "#lib/shared/crypto/index.js";
|
||||
|
||||
export interface Thumbnail {
|
||||
@@ -33,7 +32,11 @@ const fetchFromServer = async (fileId: number, dataKey: CryptoKey) => {
|
||||
return getThumbnailUrl(thumbnailBuffer);
|
||||
};
|
||||
|
||||
export const getFileThumbnail = (file: SummarizedFileInfo) => {
|
||||
export const getFileThumbnail = (file: {
|
||||
id: number;
|
||||
contentType: string;
|
||||
dataKey?: { key: CryptoKey };
|
||||
}) => {
|
||||
if (!(file.contentType.startsWith("image/") || file.contentType.startsWith("video/"))) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
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;
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user