파일 다운로드 임시 구현

This commit is contained in:
static
2025-01-05 20:45:31 +09:00
parent 9ca6444bc9
commit c580556740
7 changed files with 137 additions and 18 deletions

View File

@@ -0,0 +1,33 @@
import { decryptData } from "$lib/modules/crypto";
export { decryptFileMetadata } from "$lib/services/file";
export const requestFileDownload = (
fileId: number,
fileEncryptedIv: string,
dataKey: CryptoKey,
) => {
return new Promise<ArrayBuffer>((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.responseType = "arraybuffer";
xhr.addEventListener("load", async () => {
if (xhr.status !== 200) {
reject(new Error("Failed to download file"));
return;
}
const fileDecrypted = await decryptData(
xhr.response as ArrayBuffer,
fileEncryptedIv,
dataKey,
);
resolve(fileDecrypted);
});
// TODO: Progress, ...
xhr.open("GET", `/api/file/${fileId}/download`);
xhr.send();
});
};