mirror of
https://github.com/kmc7468/arkvault.git
synced 2025-12-15 22:38:47 +00:00
파일 다운로드 임시 구현
This commit is contained in:
33
src/routes/(fullscreen)/file/[id]/service.ts
Normal file
33
src/routes/(fullscreen)/file/[id]/service.ts
Normal 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();
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user