사소한 리팩토링

This commit is contained in:
static
2025-12-31 02:43:07 +09:00
parent 7b666cf692
commit 182ec18a2b
6 changed files with 22 additions and 20 deletions

View File

@@ -1,5 +1,7 @@
import type { DataKey } from "$lib/modules/filesystem";
export interface SelectedCategory {
id: number;
dataKey?: { key: CryptoKey; version: Date };
dataKey?: DataKey;
name: string;
}

View File

@@ -18,7 +18,7 @@ export interface FileDownloadState {
result?: ArrayBuffer;
}
export type LiveFileDownloadState = FileDownloadState & {
type LiveFileDownloadState = FileDownloadState & {
status: "download-pending" | "downloading" | "decryption-pending" | "decrypting";
};
@@ -34,9 +34,7 @@ export const getFileDownloadState = (fileId: number) => {
};
export const getDownloadingFiles = () => {
return downloadingFiles.filter((file): file is LiveFileDownloadState =>
isFileDownloading(file.status),
);
return downloadingFiles.filter((file) => isFileDownloading(file.status));
};
export const clearDownloadedFiles = () => {

View File

@@ -3,7 +3,7 @@ import { unwrapDataKey, decryptString } from "$lib/modules/crypto";
export class FilesystemCache<K, V extends RV, RV = V> {
private map = new Map<K, V | Promise<V>>();
get(key: K, loader: (isInitial: boolean, resolve: (value: RV) => void) => void) {
get(key: K, loader: (isInitial: boolean, resolve: (value: RV | undefined) => void) => void) {
const info = this.map.get(key);
if (info instanceof Promise) {
return info;
@@ -15,6 +15,8 @@ export class FilesystemCache<K, V extends RV, RV = V> {
}
loader(!info, (loadedInfo) => {
if (!loadedInfo) return;
let info = this.map.get(key)!;
if (info instanceof Promise) {
const state = $state(loadedInfo);

View File

@@ -1,4 +1,4 @@
type DataKey = { key: CryptoKey; version: Date };
export type DataKey = { key: CryptoKey; version: Date };
interface LocalDirectoryInfo {
id: number;
@@ -13,7 +13,6 @@ interface RootDirectoryInfo {
id: "root";
parentId?: undefined;
dataKey?: undefined;
dataKeyVersion?: undefined;
name?: undefined;
subDirectories: SubDirectoryInfo[];
files: SummarizedFileInfo[];
@@ -39,7 +38,7 @@ export type CategoryFileInfo = SummarizedFileInfo & { isRecursive: boolean };
interface LocalCategoryInfo {
id: number;
dataKey?: DataKey | undefined;
dataKey?: DataKey;
name: string;
subCategories: SubCategoryInfo[];
files: CategoryFileInfo[];

View File

@@ -1,16 +1,16 @@
export const monotonicResolve = <T>(
promises: (Promise<T | undefined> | false)[],
promises: (Promise<T> | false)[],
callback: (value: T) => void,
) => {
let latestResolvedIndex = -1;
promises.forEach((promise, index) => {
if (!promise) return;
promise.then((value) => {
if (value !== undefined && index > latestResolvedIndex) {
latestResolvedIndex = index;
callback(value);
}
promises
.filter((promise) => !!promise)
.forEach((promise, index) => {
promise.then((value) => {
if (index > latestResolvedIndex) {
latestResolvedIndex = index;
callback(value);
}
});
});
});
};