mirror of
https://github.com/45Drives/cockpit-navigator.git
synced 2025-07-27 23:54:20 +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.modal_prompt = new ModalPrompt();
|
||||
this.using_webkit = true;
|
||||
this.make_html_element();
|
||||
}
|
||||
|
||||
make_html_element() {
|
||||
@ -121,7 +122,6 @@ export class FileUpload {
|
||||
}
|
||||
|
||||
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.fail((e, data) => {
|
||||
this.reader.onload = () => {}
|
||||
|
@ -23,25 +23,40 @@ 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 = () => {
|
||||
constructor(nav_window_ref, max_concurrent = 10) {
|
||||
this.nav_window_ref = nav_window_ref;
|
||||
this.running = 0;
|
||||
this.remaining_uploads = [];
|
||||
this.max_concurrent = max_concurrent;
|
||||
this.start_next = () => {
|
||||
let next_upload = this.remaining_uploads.pop();
|
||||
next_upload?.upload?.();
|
||||
if (!this.remaining_uploads.length)
|
||||
nav_window_ref.refresh();
|
||||
if (next_upload) {
|
||||
next_upload?.upload?.();
|
||||
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.nav_window_ref = nav_window_ref;
|
||||
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);
|
||||
this.nav_window_ref.stop_load();
|
||||
let upload_manager = new FileUploadManager(uploads, this.nav_window_ref);
|
||||
upload_manager.start_uploads();
|
||||
this.upload_manager.add(... uploads);
|
||||
break;
|
||||
default:
|
||||
this.drop_area.classList.remove("drag-enter");
|
||||
|
Loading…
x
Reference in New Issue
Block a user