파일 캐시 추가

This commit is contained in:
static
2025-01-14 01:03:26 +09:00
parent 9ab107794a
commit ea0f0e4a71
7 changed files with 127 additions and 2 deletions

View File

@@ -1,10 +1,14 @@
import { getFileCache, storeFileCache } from "$lib/modules/cache";
import { decryptData } from "$lib/modules/crypto";
export const requestFileDownload = (
export const requestFileDownload = async (
fileId: number,
fileEncryptedIv: string,
dataKey: CryptoKey,
) => {
const cache = await getFileCache(fileId);
if (cache) return cache;
return new Promise<ArrayBuffer>((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.responseType = "arraybuffer";
@@ -21,6 +25,7 @@ export const requestFileDownload = (
dataKey,
);
resolve(fileDecrypted);
await storeFileCache(fileId, fileDecrypted);
});
// TODO: Progress, ...