Updated mooncore dependencies

This commit is contained in:
2025-03-06 20:55:14 +01:00
parent 1f95577eb7
commit 9fb1667bf0
5 changed files with 112 additions and 27 deletions

View File

@@ -1,13 +1,46 @@
window.moonCoreDownloadService = {
download: async function (fileName, contentStreamReference) {
const arrayBuffer = await contentStreamReference.arrayBuffer();
const blob = new Blob([arrayBuffer]);
download: async function (fileName, contentStreamReference, id, reportRef) {
const stream = await contentStreamReference.stream();
const reader = stream.getReader();
let lastReportTime = 0;
let receivedLength = 0; // Track downloaded size
let chunks = []; // Store downloaded chunks
while (true) {
const { done, value } = await reader.read();
if (done) break;
chunks.push(value);
receivedLength += value.length;
if(reportRef)
{
const now = Date.now();
if (now - lastReportTime >= 500) { // Only log once per second
await reportRef.invokeMethodAsync("ReceiveReport", id, receivedLength, false);
lastReportTime = now;
}
}
}
// Combine chunks into a single Blob
const blob = new Blob(chunks);
const url = URL.createObjectURL(blob);
const anchorElement = document.createElement('a');
anchorElement.href = url;
anchorElement.download = fileName ?? '';
anchorElement.click();
anchorElement.remove();
// Trigger file download
const anchor = document.createElement("a");
anchor.href = url;
anchor.download = fileName;
document.body.appendChild(anchor);
anchor.click();
document.body.removeChild(anchor);
URL.revokeObjectURL(url);
if(reportRef)
await reportRef.invokeMethodAsync("ReceiveReport", id, receivedLength, true);
}
}