diff --git a/VoidCat/spa/.env b/VoidCat/spa/.env index df32560..3ca0a11 100644 --- a/VoidCat/spa/.env +++ b/VoidCat/spa/.env @@ -1,2 +1,3 @@ BROWSER=none -HTTPS=true \ No newline at end of file +HTTPS=true +API_HOST=https://localhost:7195 \ No newline at end of file diff --git a/VoidCat/spa/src/Components/FileUpload/FileUpload.js b/VoidCat/spa/src/Components/FileUpload/FileUpload.js index ba30b31..f331423 100644 --- a/VoidCat/spa/src/Components/FileUpload/FileUpload.js +++ b/VoidCat/spa/src/Components/FileUpload/FileUpload.js @@ -7,6 +7,8 @@ import {ApiHost} from "../Shared/Const"; import {StreamEncryption} from "../Shared/StreamEncryption"; import {VoidButton} from "../Shared/VoidButton"; import {useFileTransfer} from "../Shared/FileTransferHook"; +import sjcl from "sjcl"; +import {sjclcodec} from "../../codecBytes"; const UploadState = { NotStarted: 0, @@ -99,7 +101,7 @@ export function FileUpload(props) { if (auth) { headers["Authorization"] = `Bearer ${auth}`; } - let req = await fetch("/upload", { + let req = await fetch(`${ApiHost}/upload`, { method: "POST", mode: "cors", body: rs, @@ -212,8 +214,17 @@ export function FileUpload(props) { } async function digest(file) { - let h = await window.crypto.subtle.digest(DigestAlgo, await file.arrayBuffer()); - return buf2hex(new Uint8Array(h)); + const ChunkSize = 1024 * 1024; + // must compute hash in chunks, subtle crypto cannot hash files > 2Gb + let sha = new sjcl.hash.sha256(); + for (let x = 0; x < Math.ceil(file.size / ChunkSize); x++) { + let offset = x * ChunkSize; + let slice = file.slice(offset, offset + ChunkSize); + let chunk = await slice.arrayBuffer(); + sha.update(sjclcodec.toBits(new Uint8Array(chunk))); + update(chunk.byteLength); + } + return buf2hex(sjclcodec.fromBits(sha.finalize())); } function renderStatus() {