mirror of
https://github.com/kmc7468/arkvault.git
synced 2025-12-16 06:58:46 +00:00
파일/디렉터리 목록 캐싱 추가
This commit is contained in:
@@ -1,32 +1,27 @@
|
||||
<script lang="ts">
|
||||
import FileSaver from "file-saver";
|
||||
import type { Writable } from "svelte/store";
|
||||
import { TopBar } from "$lib/components";
|
||||
import { masterKeyStore } from "$lib/stores";
|
||||
import { decryptFileMetadata, requestFileDownload } from "./service";
|
||||
import { getFileInfo } from "$lib/modules/file";
|
||||
import { masterKeyStore, type FileInfo } from "$lib/stores";
|
||||
import { requestFileDownload } from "./service";
|
||||
|
||||
let { data } = $props();
|
||||
|
||||
let metadata = $state<Awaited<ReturnType<typeof decryptFileMetadata>> | undefined>();
|
||||
let info: Writable<FileInfo | null> | undefined = $state();
|
||||
let isDownloaded = $state(false);
|
||||
|
||||
$effect(() => {
|
||||
if ($masterKeyStore) {
|
||||
decryptFileMetadata(data.metadata, $masterKeyStore.get(data.metadata.mekVersion)!.key).then(
|
||||
async (_metadata) => {
|
||||
metadata = _metadata;
|
||||
info = getFileInfo(data.id, $masterKeyStore?.get(1)?.key!);
|
||||
isDownloaded = false;
|
||||
});
|
||||
|
||||
const file = await requestFileDownload(
|
||||
data.id,
|
||||
data.metadata.contentIv,
|
||||
_metadata.dataKey,
|
||||
);
|
||||
|
||||
// TODO: Preview
|
||||
|
||||
const blob = new Blob([file]);
|
||||
|
||||
FileSaver.saveAs(blob, metadata.name);
|
||||
},
|
||||
);
|
||||
$effect(() => {
|
||||
if (info && $info && !isDownloaded) {
|
||||
isDownloaded = true;
|
||||
requestFileDownload(data.id, $info.contentIv, $info.dataKey).then((content) => {
|
||||
FileSaver.saveAs(new Blob([content], { type: "application/octet-stream" }), $info.name);
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
@@ -35,8 +30,4 @@
|
||||
<title>파일</title>
|
||||
</svelte:head>
|
||||
|
||||
{#if metadata}
|
||||
<TopBar title={metadata.name} />
|
||||
{:else}
|
||||
<TopBar />
|
||||
{/if}
|
||||
<TopBar title={$info?.name} />
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { error } from "@sveltejs/kit";
|
||||
import { z } from "zod";
|
||||
import { callGetApi } from "$lib/hooks";
|
||||
import type { FileInfoResponse } from "$lib/server/schemas";
|
||||
import type { PageLoad } from "./$types";
|
||||
|
||||
export const load: PageLoad = async ({ params, fetch }) => {
|
||||
export const load: PageLoad = async ({ params }) => {
|
||||
const zodRes = z
|
||||
.object({
|
||||
id: z.coerce.number().int().positive(),
|
||||
@@ -13,12 +11,5 @@ export const load: PageLoad = async ({ params, fetch }) => {
|
||||
if (!zodRes.success) error(404, "Not found");
|
||||
const { id } = zodRes.data;
|
||||
|
||||
const res = await callGetApi(`/api/file/${id}`, fetch);
|
||||
if (!res.ok) error(404, "Not found");
|
||||
|
||||
const fileInfo: FileInfoResponse = await res.json();
|
||||
return {
|
||||
id,
|
||||
metadata: fileInfo,
|
||||
};
|
||||
return { id };
|
||||
};
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import { decryptData } from "$lib/modules/crypto";
|
||||
|
||||
export { decryptFileMetadata } from "$lib/services/file";
|
||||
|
||||
export const requestFileDownload = (
|
||||
fileId: number,
|
||||
fileEncryptedIv: string,
|
||||
|
||||
Reference in New Issue
Block a user