From 19358f588b4f01319cccb3b76302e642e7616e9a Mon Sep 17 00:00:00 2001 From: Louis FRADIN Date: Mon, 12 Oct 2026 14:29:39 +0200 Subject: [PATCH 1/2] Add "Download All (Separately)" and put both download buttons above the file list Co-Authored-By: Claude Sonnet 5.5 --- web/src/App.css | 8 +++++++ web/src/App.tsx | 21 ++++++++--------- web/src/FileManager.tsx | 50 ++++++++++++++++++++++++++++++++++++++++- 3 files changed, 68 insertions(+), 11 deletions(-) diff --git a/web/src/App.css b/web/src/App.css index eefb18b..a988555 100644 --- a/web/src/App.css +++ b/web/src/App.css @@ -850,3 +850,11 @@ button.danger { color: var(--muted); margin: 0 0 0.6rem; } + +.fm-downloads { + display: flex; + flex-direction: column; + align-items: flex-start; + gap: 0.4rem; + margin-bottom: 0.75rem; +} diff --git a/web/src/App.tsx b/web/src/App.tsx index 58f5d01..f118e87 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -599,16 +599,17 @@ function Dashboard({ user: initialUser, onLogout }: { user: User; onLogout: () = Delete - - {(selected.stats.complete || - selected.status === 'seeding' || - selected.completed_at) && ( -
- - Download All (ZIP) - -
- )} + ) : null} diff --git a/web/src/FileManager.tsx b/web/src/FileManager.tsx index d2cbd2b..37db4e1 100644 --- a/web/src/FileManager.tsx +++ b/web/src/FileManager.tsx @@ -10,12 +10,26 @@ function parent(dir: string): string { return i <= 0 ? '/' : dir.slice(0, i) } -export function FileManager({ torrentId }: { torrentId: number }) { +async function collectFiles(torrentId: number, dir: string): Promise { + const res = await api.listFiles(torrentId, dir) + const out: string[] = [] + for (const e of res.entries) { + const full = join(dir, e.name) + if (e.is_dir) out.push(...(await collectFiles(torrentId, full))) + else out.push(full) + } + return out +} + +const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms)) + +export function FileManager({ torrentId, zipUrl }: { torrentId: number; zipUrl?: string }) { const [dir, setDir] = useState('/') const [entries, setEntries] = useState([]) const [writable, setWritable] = useState(false) const [error, setError] = useState('') const [busy, setBusy] = useState(false) + const [progress, setProgress] = useState('') const load = useCallback( async (path: string) => { @@ -48,12 +62,46 @@ export function FileManager({ torrentId }: { torrentId: number }) { } } + // Starts one browser download per file; browsers may ask to allow multiple downloads. + async function downloadSeparately() { + setBusy(true) + try { + const paths = await collectFiles(torrentId, '/') + for (let i = 0; i < paths.length; i++) { + setProgress(`Downloading ${i + 1}/${paths.length}…`) + const a = document.createElement('a') + a.href = api.fileDownloadUrl(torrentId, paths[i]) + a.download = '' + document.body.appendChild(a) + a.click() + a.remove() + await sleep(400) + } + } catch (err) { + setError(err instanceof Error ? err.message : 'Download failed') + } finally { + setProgress('') + setBusy(false) + } + } + const crumbs = dir === '/' ? [] : dir.slice(1).split('/') return (

Files

+ {zipUrl ? ( +
+ + Download All (ZIP) + + +
+ ) : null} + {dir !== '/' ? (