From ab3023f8a543b7feff112008c19e72dedc509eef Mon Sep 17 00:00:00 2001 From: jogotcha Date: Thu, 12 Feb 2026 12:15:33 +0100 Subject: [PATCH] fix: download zip files when zip browse enabled (#9) Co-authored-by: Zitz, Johannes AVL AT --- assets/index.js | 2 +- src/server.rs | 8 +++++++- tests/zip_browse.rs | 18 +++++++++++++++++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/assets/index.js b/assets/index.js index 0ee4c9e..2b4d3de 100644 --- a/assets/index.js +++ b/assets/index.js @@ -563,7 +563,7 @@ function addPath(file, index) { let actionEdit = ""; let actionView = ""; let isDir = file.path_type.endsWith("Dir") || isZip; - const downloadUrl = url; + const downloadUrl = isZip ? `${url}?download` : url; if (isDir) { url += "/"; if (DATA.allow_archive && !isZip) { diff --git a/src/server.rs b/src/server.rs index 323a4f1..6001df6 100644 --- a/src/server.rs +++ b/src/server.rs @@ -197,11 +197,17 @@ impl Server { .map(|(k, v)| (k.to_string(), v.to_string())) .collect(); - let zip_browse = if self.args.allow_zip_browse { + let mut zip_browse = if self.args.allow_zip_browse { self.parse_zip_browse_path(req_path, &relative_path) } else { None }; + if has_query_flag(&query_params, "download") + && let Some(zip_browse_path) = zip_browse.as_ref() + && zip_browse_path.inner_path.is_empty() + { + zip_browse = None; + } let auth_path = zip_browse .as_ref() diff --git a/tests/zip_browse.rs b/tests/zip_browse.rs index c4e6198..ee9456e 100644 --- a/tests/zip_browse.rs +++ b/tests/zip_browse.rs @@ -5,7 +5,7 @@ use async_zip::{Compression, ZipEntryBuilder, tokio::write::ZipFileWriter}; use fixtures::{Error, TestServer, server}; use rstest::rstest; use sha2::{Digest, Sha256}; -use std::path::Path; +use std::{fs, path::Path}; use tokio::runtime::Runtime; fn write_zip(path: &Path, entries: Vec<(&str, &[u8])>) -> Result<(), Error> { @@ -123,6 +123,22 @@ fn zip_extensions_allow_custom_formats( Ok(()) } +#[rstest] +fn zip_download_returns_raw_file( + #[with(&["--allow-zip-browse"])] server: TestServer, +) -> Result<(), Error> { + let zip_path = server.path().join("archive.zip"); + write_zip(&zip_path, vec![("folder/note.txt", b"note")])?; + + let url = format!("{}archive.zip?download", server.url()); + let resp = reqwest::blocking::get(url)?; + assert_eq!(resp.status(), 200); + let body = resp.bytes()?; + let expected = fs::read(&zip_path)?; + assert_eq!(body.as_ref(), expected.as_slice()); + Ok(()) +} + #[rstest] fn zip_search_filters_entries( #[with(&["--allow-zip-browse", "--allow-search"])] server: TestServer,