Allow bulk downloading selection

This commit is contained in:
2026-10-05 14:12:18 +02:00
parent 93d5583940
commit 6f0f58d2d9
3 changed files with 24 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
import { loading_finish, loading_run, loading_start } from "lib/Loading";
import { fs_get_node, fs_encode_path, fs_split_path, fs_path_from_json, fs_rename } from "lib/FilesystemAPI.svelte";
import { fs_get_node, fs_encode_path, fs_split_path, fs_path_from_json, fs_path_url, fs_rename } from "lib/FilesystemAPI.svelte";
import type { FSNode, FSPath, FSPermissions, FSContext } from "lib/FilesystemAPI.svelte";
export class FSNavigator {
@@ -286,6 +286,27 @@ export class FSNavigator {
this.set_selecting(true)
}
// Downloads the selection, or the open node if nothing is selected. More
// than one node is zipped by the closest directory which they are all in
download = () => {
const nodes = [...this.selection.values()]
if (nodes.length < 2) {
return (nodes[0] ?? this.base).download()
}
let dir = nodes[0].path
do {
dir = dir.slice(0, dir.lastIndexOf("/"))
} while (!nodes.every(n => n.path.startsWith(dir + "/")))
const a = document.createElement("a")
a.href = fs_path_url(dir) + "?bulk_download&" + new URLSearchParams(
nodes.map(n => ["include", n.path.slice(dir.length + 1)])
)
a.download = ""
a.dispatchEvent(new MouseEvent("click"))
}
// A directory can't be moved into itself, and there has to be at least one
// node which is not in dir already
can_move = (dir: string) => {