1c9352a7c5c2550a52b1d9fb2bae806b6aaed1be
chmalee
Thu Jan 18 13:28:56 2024 -0800
Starting on pre-create hook for tusd
diff --git src/hg/js/hgMyData.js src/hg/js/hgMyData.js
index 39a0f6d..3fb8d9f 100644
--- src/hg/js/hgMyData.js
+++ src/hg/js/hgMyData.js
@@ -8,37 +8,37 @@
return `${((num/1000)/1000).toFixed(1)}mb`;
} else {
return `${(((num/1000)/1000)/1000).toFixed(1)}gb`;
}
}
var hubCreate = (function() {
let uiState = { // our object for keeping track of the current UI and what to do
toUpload: {}, // set of file objects keyed by name
input: null, // the element for picking files from the users machine
pickedList: null, // the
for displaying files in toUpload
pendingQueue: [], // our queue of pending [xmlhttprequests, file], kind of like the toUpload object
};
// We can use XMLHttpRequest if necessary or a mirror can't use tus
- var useTus = tus.isSupported && typeof tusdPort !== 'undefined' && typeof tusdBasePath !== 'undefined';
+ var useTus = tus.isSupported && true;
function getTusdEndpoint() {
// return the port and basepath of the tusd server
// NOTE: the port and basepath are specified in hg.conf
- let currUrl = parseUrl(window.location.href);
- return "https://hgwdev-chmalee.gi.ucsc.edu" + ":" + tusdPort + "/" + tusdBasePath + "/";
+ //let currUrl = parseUrl(window.location.href);
+ return "https://hgwdev-hubspace.gi.ucsc.edu/files";
}
function togglePickStateMessage(showMsg = false) {
if (showMsg) {
let para = document.createElement("p");
para.textContent = "No files selected for upload";
para.classList.add("noFiles");
uiState.pickedList.prepend(para);
} else {
let msg = document.querySelector(".noFiles");
if (msg) {
msg.parentNode.removeChild(msg);
}
}
}
@@ -196,40 +196,46 @@
this.xhr.upload.addEventListener("timeout", (e) => {
});
// finally we can send the request
this.xhr.open("POST", endpoint, true);
fd.set("createHub", 1);
fd.set("userFile", file);
this.xhr.send(fd);
uiState.pendingQueue.push([this.xhr,file]);
addCancelButton(file, this.xhr);
}
function submitPickedFiles() {
let tusdServer = getTusdEndpoint();
+ let onBeforeRequest = function(req) {
+ let xhr = req.getUnderlyingObject(req);
+ xhr.withCredentials = true;
+ };
for (let f in uiState.toUpload) {
file = uiState.toUpload[f];
if (useTus) {
let tusOptions = {
endpoint: tusdServer,
metadata: {
filename: file.name,
fileType: file.type,
fileSize: file.size
- }
+ },
+ onBeforeRequest: onBeforeRequest,
+ retryDelays: [1000],
};
// TODO: get the uploadUrl from the tusd server
// use a pre-create hook to validate the user
// and get an uploadUrl
let tusUpload = new tus.Upload(file, tusOptions);
tusUpload.start();
} else {
// make a new XMLHttpRequest for each file, if tusd-tusclient not supported
new sendFile(file);
}
}
addCancelAllButton();
return;
}