mirror of
https://github.com/sigoden/dufs.git
synced 2026-09-14 02:56:16 +05:00
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:
parent
1b86054481
commit
ab3023f8a5
@ -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) {
|
||||
|
||||
@ -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()
|
||||
|
||||
@ -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,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user