mirror of
https://github.com/45Drives/cockpit-navigator.git
synced 2025-07-28 08:04:39 +02:00
have single upload manager that can be added to
This commit is contained in:
parent
11851bbfed
commit
f0fc84d80c
@ -44,6 +44,7 @@ export class FileUpload {
|
|||||||
this.timestamp = Date.now();
|
this.timestamp = Date.now();
|
||||||
this.modal_prompt = new ModalPrompt();
|
this.modal_prompt = new ModalPrompt();
|
||||||
this.using_webkit = true;
|
this.using_webkit = true;
|
||||||
|
this.make_html_element();
|
||||||
}
|
}
|
||||||
|
|
||||||
make_html_element() {
|
make_html_element() {
|
||||||
@ -121,7 +122,6 @@ export class FileUpload {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async upload() {
|
async upload() {
|
||||||
this.make_html_element();
|
|
||||||
this.proc = cockpit.spawn(["/usr/share/cockpit/navigator/scripts/write-chunks.py3", this.path], {err: "out", superuser: "try"});
|
this.proc = cockpit.spawn(["/usr/share/cockpit/navigator/scripts/write-chunks.py3", this.path], {err: "out", superuser: "try"});
|
||||||
this.proc.fail((e, data) => {
|
this.proc.fail((e, data) => {
|
||||||
this.reader.onload = () => {}
|
this.reader.onload = () => {}
|
||||||
|
@ -23,25 +23,40 @@ import {NavWindow} from "./NavWindow.js";
|
|||||||
export class FileUploadManager {
|
export class FileUploadManager {
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {FileUpload[]} uploads
|
|
||||||
* @param {NavWindow} nav_window_ref
|
* @param {NavWindow} nav_window_ref
|
||||||
* @param {number} max_concurrent
|
* @param {number} max_concurrent
|
||||||
*/
|
*/
|
||||||
constructor(uploads, nav_window_ref, max_concurrent = 10) {
|
constructor(nav_window_ref, max_concurrent = 10) {
|
||||||
this.remaining_uploads = uploads;
|
this.nav_window_ref = nav_window_ref;
|
||||||
this.max_concurrent = Math.min(max_concurrent, uploads.length);
|
this.running = 0;
|
||||||
let start_next = this.kickoff = () => {
|
this.remaining_uploads = [];
|
||||||
|
this.max_concurrent = max_concurrent;
|
||||||
|
this.start_next = () => {
|
||||||
let next_upload = this.remaining_uploads.pop();
|
let next_upload = this.remaining_uploads.pop();
|
||||||
next_upload?.upload?.();
|
if (next_upload) {
|
||||||
if (!this.remaining_uploads.length)
|
next_upload?.upload?.();
|
||||||
nav_window_ref.refresh();
|
this.running++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.remaining_uploads.forEach((upload) => {upload.done_hook = start_next});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
start_uploads() {
|
/**
|
||||||
for (let i = 0; i < this.max_concurrent; i++) {
|
*
|
||||||
this.kickoff();
|
* @param {...FileUpload} uploads
|
||||||
|
*/
|
||||||
|
add(...uploads) {
|
||||||
|
let done_hook = () => {
|
||||||
|
this.running--;
|
||||||
|
this.start_next();
|
||||||
|
if (!this.running)
|
||||||
|
this.nav_window_ref.refresh();
|
||||||
|
}
|
||||||
|
for (let upload of uploads) {
|
||||||
|
upload.done_hook = done_hook;
|
||||||
|
this.remaining_uploads.unshift(upload);
|
||||||
|
}
|
||||||
|
while (this.remaining_uploads.length && this.running < this.max_concurrent) {
|
||||||
|
this.start_next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -36,6 +36,7 @@ export class NavDragDrop {
|
|||||||
this.drop_area = drop_area;
|
this.drop_area = drop_area;
|
||||||
this.nav_window_ref = nav_window_ref;
|
this.nav_window_ref = nav_window_ref;
|
||||||
this.modal_prompt = new ModalPrompt();
|
this.modal_prompt = new ModalPrompt();
|
||||||
|
this.upload_manager = new FileUploadManager(this.nav_window_ref, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -188,8 +189,7 @@ 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();
|
||||||
let upload_manager = new FileUploadManager(uploads, this.nav_window_ref);
|
this.upload_manager.add(... uploads);
|
||||||
upload_manager.start_uploads();
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
this.drop_area.classList.remove("drag-enter");
|
this.drop_area.classList.remove("drag-enter");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user