fix: download zip files when zip browse enabled (#9)

Co-authored-by: Zitz, Johannes AVL AT <johannes.zitz@avl.com>
This commit is contained in:
jogotcha 2026-02-12 12:15:33 +01:00 committed by GitHub
parent 1b86054481
commit ab3023f8a5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 25 additions and 3 deletions

View File

@ -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) {

View File

@ -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()

View File

@ -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,