Pārlūkot izejas kodu

Add function to download and decrypt a file

Vishnu Mohandas 4 gadi atpakaļ
vecāks
revīzija
580ce23c17
1 mainītis faili ar 13 papildinājumiem un 0 dzēšanām
  1. 13 0
      src/services/fileService.ts

+ 13 - 0
src/services/fileService.ts

@@ -92,3 +92,16 @@ export const getPreview = async (token: string, file: file) => {
         file.key);
     return URL.createObjectURL(new Blob([decrypted]));
 }
+
+export const getFile = async (token: string, file: file) => {
+    const resp = await HTTPService.get(
+        `${ENDPOINT}/files/download/${file.id}`,
+        { token }, null, { responseType: 'arraybuffer' },
+    );
+    const worker = await new CryptoWorker();
+    const decrypted: any = await worker.decryptFile(
+        new Uint8Array(resp.data),
+        await worker.fromB64(file.file.decryptionHeader),
+        file.key);
+    return URL.createObjectURL(new Blob([decrypted]));
+}