mirror of
https://github.com/kmc7468/arkvault.git
synced 2026-02-04 08:06:56 +00:00
사소한 리팩토링
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
|
import type { DataKey } from "$lib/modules/filesystem";
|
||||||
|
|
||||||
export interface SelectedCategory {
|
export interface SelectedCategory {
|
||||||
id: number;
|
id: number;
|
||||||
dataKey?: { key: CryptoKey; version: Date };
|
dataKey?: DataKey;
|
||||||
name: string;
|
name: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ export interface FileDownloadState {
|
|||||||
result?: ArrayBuffer;
|
result?: ArrayBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type LiveFileDownloadState = FileDownloadState & {
|
type LiveFileDownloadState = FileDownloadState & {
|
||||||
status: "download-pending" | "downloading" | "decryption-pending" | "decrypting";
|
status: "download-pending" | "downloading" | "decryption-pending" | "decrypting";
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -34,9 +34,7 @@ export const getFileDownloadState = (fileId: number) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const getDownloadingFiles = () => {
|
export const getDownloadingFiles = () => {
|
||||||
return downloadingFiles.filter((file): file is LiveFileDownloadState =>
|
return downloadingFiles.filter((file) => isFileDownloading(file.status));
|
||||||
isFileDownloading(file.status),
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const clearDownloadedFiles = () => {
|
export const clearDownloadedFiles = () => {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { unwrapDataKey, decryptString } from "$lib/modules/crypto";
|
|||||||
export class FilesystemCache<K, V extends RV, RV = V> {
|
export class FilesystemCache<K, V extends RV, RV = V> {
|
||||||
private map = new Map<K, V | Promise<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);
|
const info = this.map.get(key);
|
||||||
if (info instanceof Promise) {
|
if (info instanceof Promise) {
|
||||||
return info;
|
return info;
|
||||||
@@ -15,6 +15,8 @@ export class FilesystemCache<K, V extends RV, RV = V> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
loader(!info, (loadedInfo) => {
|
loader(!info, (loadedInfo) => {
|
||||||
|
if (!loadedInfo) return;
|
||||||
|
|
||||||
let info = this.map.get(key)!;
|
let info = this.map.get(key)!;
|
||||||
if (info instanceof Promise) {
|
if (info instanceof Promise) {
|
||||||
const state = $state(loadedInfo);
|
const state = $state(loadedInfo);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
type DataKey = { key: CryptoKey; version: Date };
|
export type DataKey = { key: CryptoKey; version: Date };
|
||||||
|
|
||||||
interface LocalDirectoryInfo {
|
interface LocalDirectoryInfo {
|
||||||
id: number;
|
id: number;
|
||||||
@@ -13,7 +13,6 @@ interface RootDirectoryInfo {
|
|||||||
id: "root";
|
id: "root";
|
||||||
parentId?: undefined;
|
parentId?: undefined;
|
||||||
dataKey?: undefined;
|
dataKey?: undefined;
|
||||||
dataKeyVersion?: undefined;
|
|
||||||
name?: undefined;
|
name?: undefined;
|
||||||
subDirectories: SubDirectoryInfo[];
|
subDirectories: SubDirectoryInfo[];
|
||||||
files: SummarizedFileInfo[];
|
files: SummarizedFileInfo[];
|
||||||
@@ -39,7 +38,7 @@ export type CategoryFileInfo = SummarizedFileInfo & { isRecursive: boolean };
|
|||||||
|
|
||||||
interface LocalCategoryInfo {
|
interface LocalCategoryInfo {
|
||||||
id: number;
|
id: number;
|
||||||
dataKey?: DataKey | undefined;
|
dataKey?: DataKey;
|
||||||
name: string;
|
name: string;
|
||||||
subCategories: SubCategoryInfo[];
|
subCategories: SubCategoryInfo[];
|
||||||
files: CategoryFileInfo[];
|
files: CategoryFileInfo[];
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
export const monotonicResolve = <T>(
|
export const monotonicResolve = <T>(
|
||||||
promises: (Promise<T | undefined> | false)[],
|
promises: (Promise<T> | false)[],
|
||||||
callback: (value: T) => void,
|
callback: (value: T) => void,
|
||||||
) => {
|
) => {
|
||||||
let latestResolvedIndex = -1;
|
let latestResolvedIndex = -1;
|
||||||
|
promises
|
||||||
promises.forEach((promise, index) => {
|
.filter((promise) => !!promise)
|
||||||
if (!promise) return;
|
.forEach((promise, index) => {
|
||||||
promise.then((value) => {
|
promise.then((value) => {
|
||||||
if (value !== undefined && index > latestResolvedIndex) {
|
if (index > latestResolvedIndex) {
|
||||||
latestResolvedIndex = index;
|
latestResolvedIndex = index;
|
||||||
callback(value);
|
callback(value);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -8,13 +8,14 @@ import {
|
|||||||
deleteFileThumbnailCache,
|
deleteFileThumbnailCache,
|
||||||
uploadFile,
|
uploadFile,
|
||||||
} from "$lib/modules/file";
|
} from "$lib/modules/file";
|
||||||
|
import type { DataKey } from "$lib/modules/filesystem";
|
||||||
import { hmacSecretStore, type MasterKey, type HmacSecret } from "$lib/stores";
|
import { hmacSecretStore, type MasterKey, type HmacSecret } from "$lib/stores";
|
||||||
import { trpc } from "$trpc/client";
|
import { trpc } from "$trpc/client";
|
||||||
|
|
||||||
export interface SelectedEntry {
|
export interface SelectedEntry {
|
||||||
type: "directory" | "file";
|
type: "directory" | "file";
|
||||||
id: number;
|
id: number;
|
||||||
dataKey: { key: CryptoKey; version: Date } | undefined;
|
dataKey: DataKey | undefined;
|
||||||
name: string;
|
name: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user