Allow bulk downloading selection
This commit is contained in:
@@ -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) => {
|
||||
|
||||
@@ -84,7 +84,7 @@ const keydown = (e: KeyboardEvent) => {
|
||||
}
|
||||
break;
|
||||
case "s":
|
||||
nav.base.download()
|
||||
nav.download()
|
||||
break;
|
||||
case "r":
|
||||
nav.shuffle = !nav.shuffle
|
||||
|
||||
@@ -52,7 +52,7 @@ export const copy_link = () => {
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<button onclick={() => $nav.base.download()}>
|
||||
<button onclick={() => nav.download()}>
|
||||
<i class="icon">save</i>
|
||||
<span>Download</span>
|
||||
</button>
|
||||
|
||||
Reference in New Issue
Block a user