diff --git a/svelte/src/filesystem/FSNavigator.ts b/svelte/src/filesystem/FSNavigator.ts index 543cee1..728c22d 100644 --- a/svelte/src/filesystem/FSNavigator.ts +++ b/svelte/src/filesystem/FSNavigator.ts @@ -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) => { diff --git a/svelte/src/filesystem/Filesystem.svelte b/svelte/src/filesystem/Filesystem.svelte index a608361..6cec240 100644 --- a/svelte/src/filesystem/Filesystem.svelte +++ b/svelte/src/filesystem/Filesystem.svelte @@ -84,7 +84,7 @@ const keydown = (e: KeyboardEvent) => { } break; case "s": - nav.base.download() + nav.download() break; case "r": nav.shuffle = !nav.shuffle diff --git a/svelte/src/filesystem/Toolbar.svelte b/svelte/src/filesystem/Toolbar.svelte index 1429a98..a067a0e 100644 --- a/svelte/src/filesystem/Toolbar.svelte +++ b/svelte/src/filesystem/Toolbar.svelte @@ -52,7 +52,7 @@ export const copy_link = () => { -