MCPcopy Create free account
hub / github.com/BruceDevices/firmware / uploadFile

Function uploadFile

embedded_resources/web_interface/index.js:238–280  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

236 });
237}
238async function uploadFile() {
239 if (_queueUpload.length === 0) {
240 _runningUpload = false;
241 $(".dialog.upload .dialog-body").innerHTML = "";
242 fetchSystemInfo();
243 fetchFiles(currentDrive, currentPath);
244 Dialog.hide();
245 return;
246 }
247
248 return new Promise((resolve, reject) => {
249 _runningUpload = true;
250 let file = _queueUpload.shift();
251 let fd = new FormData();
252 let filename = file.webkitRelativePath || file.name;
253 let fileId = stringToId(filename);
254 fd.append("file", file, filename);
255 fd.append("folder", currentPath);
256 fd.append("fs", currentDrive);
257
258 let realUrl = `/upload`;
259 if (IS_DEV) realUrl = "/bruce" + realUrl;
260 let req = new XMLHttpRequest();
261 req.upload.onprogress = (e) => {
262 if (e.lengthComputable) {
263 var percent = (e.loaded / e.total) * 100;
264 $("#" + fileId).style.width = Math.round(percent) + "%";
265 }
266 };
267 req.onload = () => {
268 uploadFile();
269 if (req.status >= 200 && req.status < 300) {
270 resolve(req.responseText);
271 } else {
272 reject();
273 }
274 };
275 req.onabort = () => reject();
276 req.onerror = () => reject();
277 req.open("POST", realUrl, true);
278 req.send(fd);
279 });
280}
281
282async function runCommand(cmd) {
283 Dialog.loading.show("Running command...");

Callers 1

index.jsFile · 0.85

Calls 4

$Function · 0.85
fetchSystemInfoFunction · 0.85
fetchFilesFunction · 0.85
stringToIdFunction · 0.85

Tested by

no test coverage detected