mirror of
https://github.com/sigoden/dufs.git
synced 2026-04-09 00:59:02 +03:00
feat: add option --allow-hash to allow/disallow file hashing (#657)
This commit is contained in:
12
src/args.rs
12
src/args.rs
@@ -148,6 +148,14 @@ pub fn build_cli() -> Command {
|
||||
.action(ArgAction::SetTrue)
|
||||
.help("Allow download folders as archive file"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("allow-hash")
|
||||
.env("DUFS_ALLOW_HASH")
|
||||
.hide_env(true)
|
||||
.long("allow-hash")
|
||||
.action(ArgAction::SetTrue)
|
||||
.help("Allow ?hash query to get file sha256 hash"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("enable-cors")
|
||||
.env("DUFS_ENABLE_CORS")
|
||||
@@ -281,6 +289,7 @@ pub struct Args {
|
||||
pub allow_search: bool,
|
||||
pub allow_symlink: bool,
|
||||
pub allow_archive: bool,
|
||||
pub allow_hash: bool,
|
||||
pub render_index: bool,
|
||||
pub render_spa: bool,
|
||||
pub render_try_index: bool,
|
||||
@@ -375,6 +384,9 @@ impl Args {
|
||||
if !args.allow_symlink {
|
||||
args.allow_symlink = allow_all || matches.get_flag("allow-symlink");
|
||||
}
|
||||
if !args.allow_hash {
|
||||
args.allow_hash = allow_all || matches.get_flag("allow-hash");
|
||||
}
|
||||
if !args.allow_archive {
|
||||
args.allow_archive = allow_all || matches.get_flag("allow-archive");
|
||||
}
|
||||
|
||||
@@ -358,7 +358,11 @@ impl Server {
|
||||
self.handle_edit_file(path, DataKind::View, head_only, user, &mut res)
|
||||
.await?;
|
||||
} else if has_query_flag(&query_params, "hash") {
|
||||
self.handle_hash_file(path, head_only, &mut res).await?;
|
||||
if self.args.allow_hash {
|
||||
self.handle_hash_file(path, head_only, &mut res).await?;
|
||||
} else {
|
||||
status_forbid(&mut res);
|
||||
}
|
||||
} else {
|
||||
self.handle_send_file(path, headers, head_only, &mut res)
|
||||
.await?;
|
||||
|
||||
Reference in New Issue
Block a user