implement upload manager to limit concurrent uploads
This commit is contained in:
parent
dffe7b00ce
commit
11851bbfed
|
@ -129,8 +129,10 @@ export class FileUpload {
|
||||||
this.nav_window_ref.modal_prompt.alert(e, data);
|
this.nav_window_ref.modal_prompt.alert(e, data);
|
||||||
})
|
})
|
||||||
this.proc.done((data) => {
|
this.proc.done((data) => {
|
||||||
this.nav_window_ref.refresh();
|
if (!this.done_hook)
|
||||||
|
this.nav_window_ref.refresh();
|
||||||
})
|
})
|
||||||
|
this.proc.always(() => this?.done_hook?.());
|
||||||
this.reader.onerror = (evt) => {
|
this.reader.onerror = (evt) => {
|
||||||
this.modal_prompt.alert("Failed to read file: " + this.filename, "Upload of directories not supported.");
|
this.modal_prompt.alert("Failed to read file: " + this.filename, "Upload of directories not supported.");
|
||||||
this.done();
|
this.done();
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
/*
|
||||||
|
Cockpit Navigator - A File System Browser for Cockpit.
|
||||||
|
Copyright (C) 2021 Josh Boudreau <jboudreau@45drives.com>
|
||||||
|
Copyright (C) 2021 Sam Silver <ssilver@45drives.com>
|
||||||
|
Copyright (C) 2021 Dawson Della Valle <ddellavalle@45drives.com>
|
||||||
|
|
||||||
|
This file is part of Cockpit Navigator.
|
||||||
|
Cockpit Navigator is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
Cockpit Navigator is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Cockpit Navigator. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {FileUpload} from "./FileUpload.js";
|
||||||
|
import {NavWindow} from "./NavWindow.js";
|
||||||
|
|
||||||
|
export class FileUploadManager {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {FileUpload[]} uploads
|
||||||
|
* @param {NavWindow} nav_window_ref
|
||||||
|
* @param {number} max_concurrent
|
||||||
|
*/
|
||||||
|
constructor(uploads, nav_window_ref, max_concurrent = 10) {
|
||||||
|
this.remaining_uploads = uploads;
|
||||||
|
this.max_concurrent = Math.min(max_concurrent, uploads.length);
|
||||||
|
let start_next = this.kickoff = () => {
|
||||||
|
let next_upload = this.remaining_uploads.pop();
|
||||||
|
next_upload?.upload?.();
|
||||||
|
if (!this.remaining_uploads.length)
|
||||||
|
nav_window_ref.refresh();
|
||||||
|
}
|
||||||
|
this.remaining_uploads.forEach((upload) => {upload.done_hook = start_next});
|
||||||
|
}
|
||||||
|
|
||||||
|
start_uploads() {
|
||||||
|
for (let i = 0; i < this.max_concurrent; i++) {
|
||||||
|
this.kickoff();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -20,7 +20,7 @@
|
||||||
import {FileUpload} from "./FileUpload.js";
|
import {FileUpload} from "./FileUpload.js";
|
||||||
import {ModalPrompt} from "./ModalPrompt.js";
|
import {ModalPrompt} from "./ModalPrompt.js";
|
||||||
import {NavWindow} from "./NavWindow.js";
|
import {NavWindow} from "./NavWindow.js";
|
||||||
import {check_if_exists} from "../functions.js";
|
import {FileUploadManager} from "./FileUploadManager.js";
|
||||||
|
|
||||||
export class NavDragDrop {
|
export class NavDragDrop {
|
||||||
/**
|
/**
|
||||||
|
@ -117,7 +117,6 @@ export class NavDragDrop {
|
||||||
} catch {
|
} catch {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log(exist_result);
|
|
||||||
let keepers = [];
|
let keepers = [];
|
||||||
let requests = {};
|
let requests = {};
|
||||||
for (let upload of uploads) {
|
for (let upload of uploads) {
|
||||||
|
@ -189,7 +188,8 @@ export class NavDragDrop {
|
||||||
}
|
}
|
||||||
uploads = await this.handle_conflicts(uploads);
|
uploads = await this.handle_conflicts(uploads);
|
||||||
this.nav_window_ref.stop_load();
|
this.nav_window_ref.stop_load();
|
||||||
uploads.forEach((upload) => {upload.upload()});
|
let upload_manager = new FileUploadManager(uploads, this.nav_window_ref);
|
||||||
|
upload_manager.start_uploads();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
this.drop_area.classList.remove("drag-enter");
|
this.drop_area.classList.remove("drag-enter");
|
||||||
|
|
Loading…
Reference in New Issue