Improved upload progress tracking. Fixed path on frontend export
This commit is contained in:
@@ -32,6 +32,7 @@
|
||||
<script src="/js/fileManager.js"></script>
|
||||
<script src="/js/codeEditor.js"></script>
|
||||
<script src="/js/keyBinds.js"></script>
|
||||
<script src="/js/xmlHttpRequest.js"></script>
|
||||
<script src="/ace/ace.js"></script>
|
||||
<script src="/_framework/blazor.webassembly.js"></script>
|
||||
<script>navigator.serviceWorker.register('service-worker.js');</script>
|
||||
|
||||
80
Moonlight.Client/wwwroot/js/xmlHttpRequest.js
Normal file
80
Moonlight.Client/wwwroot/js/xmlHttpRequest.js
Normal file
@@ -0,0 +1,80 @@
|
||||
window.moonCoreXmlHttpRequest = {
|
||||
storage: {},
|
||||
initialize: function (trackingId, refObject) {
|
||||
const req = new XMLHttpRequest();
|
||||
|
||||
req.addEventListener("timeout", async ev => {
|
||||
await refObject.invokeMethodAsync("TriggerTimeoutEvent", {
|
||||
"loaded": ev.loaded,
|
||||
"total": ev.total
|
||||
});
|
||||
});
|
||||
|
||||
req.addEventListener("progress", async ev => {
|
||||
await refObject.invokeMethodAsync("TriggerDownloadProgressEvent", {
|
||||
"loaded": ev.loaded,
|
||||
"total": ev.total
|
||||
});
|
||||
});
|
||||
|
||||
req.upload.addEventListener("progress", async ev => {
|
||||
await refObject.invokeMethodAsync("TriggerUploadProgressEvent", {
|
||||
"loaded": ev.loaded,
|
||||
"total": ev.total
|
||||
});
|
||||
});
|
||||
|
||||
req.addEventListener("loadend", async ev => {
|
||||
await refObject.invokeMethodAsync("TriggerLoadedEvent", ev);
|
||||
});
|
||||
|
||||
req.addEventListener("readystatechange", async _ => {
|
||||
await refObject.invokeMethodAsync("TriggerReadyStateChangeEvent", req.readyState);
|
||||
});
|
||||
|
||||
this.storage[trackingId] = req;
|
||||
|
||||
return req;
|
||||
},
|
||||
setProperty: function (trackingId, property, value) {
|
||||
this.storage[trackingId][property] = value;
|
||||
console.log(this.storage[trackingId]);
|
||||
},
|
||||
getProperty: function (trackingId, property) {
|
||||
return this.storage[trackingId][property];
|
||||
},
|
||||
sendStream: async function (trackingId, streamRef) {
|
||||
const stream = await streamRef.stream();
|
||||
const blob = await this.streamToBlob(stream);
|
||||
this.storage[trackingId].send(blob);
|
||||
},
|
||||
sendFile: async function (trackingId, formName, fileName, streamRef) {
|
||||
const stream = await streamRef.stream();
|
||||
const blob = await this.streamToBlob(stream);
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append(formName, blob, fileName);
|
||||
|
||||
this.storage[trackingId].send(formData);
|
||||
},
|
||||
getResponseStream: function (trackingId) {
|
||||
return this.storage[trackingId].response;
|
||||
},
|
||||
dispose: function (trackingId) {
|
||||
this.storage[trackingId] = undefined;
|
||||
},
|
||||
streamToBlob: async function (stream) {
|
||||
const reader = stream.getReader();
|
||||
|
||||
let chunks = [];
|
||||
|
||||
while (true) {
|
||||
const {done, value} = await reader.read();
|
||||
if (done) break;
|
||||
|
||||
chunks.push(value);
|
||||
}
|
||||
|
||||
return new Blob(chunks);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user