fix: ui set default max uploading to 1 (#220)

This commit is contained in:
sigoden 2023-06-01 21:32:22 +08:00 committed by GitHub
parent 4622c48120
commit 8d7c1fbf53
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -22,6 +22,8 @@
* @property {string} editable
*/
var DUFS_MAX_UPLOADINGS = 1;
/**
* @type {DATA} DATA
*/
@ -152,7 +154,6 @@ class Uploader {
}
ajax() {
Uploader.runnings += 1;
const url = newUrl(this.name);
this.lastUptime = Date.now();
const ajax = new XMLHttpRequest();
@ -187,13 +188,13 @@ class Uploader {
complete() {
this.$uploadStatus.innerHTML = ``;
Uploader.runnings -= 1;
Uploader.runnings--;
Uploader.runQueue();
}
fail() {
this.$uploadStatus.innerHTML = ``;
Uploader.runnings -= 1;
Uploader.runnings--;
Uploader.runQueue();
}
}
@ -211,16 +212,14 @@ Uploader.queues = [];
Uploader.runQueue = async () => {
if (Uploader.runnings > 2) return;
if (Uploader.runnings >= DUFS_MAX_UPLOADINGS) return;
if (Uploader.queues.length == 0) return;
Uploader.runnings++;
let uploader = Uploader.queues.shift();
if (!uploader) return;
if (!Uploader.auth) {
Uploader.auth = true;
try {
await login();
} catch {
Uploader.auth = false;
}
const success = await login(true);
Uploader.auth = !!success;
}
uploader.ajax();
}
@ -662,6 +661,7 @@ async function login(alert = false) {
document.querySelector(".login-btn").classList.add("hidden");
$userBtn.classList.remove("hidden");
$userBtn.title = "";
return true;
} catch (err) {
let message = `Cannot login, ${err.message}`;
if (alert) {