feat: add option --allow-search (#62)

This commit is contained in:
sigoden
2022-06-21 07:23:20 +08:00
committed by GitHub
parent 069cb64889
commit 4058a2db72
8 changed files with 37 additions and 9 deletions

View File

@@ -81,6 +81,11 @@ fn app() -> Command<'static> {
.long("allow-delete")
.help("Allow delete files/folders"),
)
.arg(
Arg::new("allow-search")
.long("allow-search")
.help("Allow search files/folders"),
)
.arg(
Arg::new("allow-symlink")
.long("allow-symlink")
@@ -136,6 +141,7 @@ pub struct Args {
pub auth: AccessControl,
pub allow_upload: bool,
pub allow_delete: bool,
pub allow_search: bool,
pub allow_symlink: bool,
pub render_index: bool,
pub render_spa: bool,
@@ -179,6 +185,7 @@ impl Args {
let auth = AccessControl::new(&auth, &uri_prefix)?;
let allow_upload = matches.is_present("allow-all") || matches.is_present("allow-upload");
let allow_delete = matches.is_present("allow-all") || matches.is_present("allow-delete");
let allow_search = matches.is_present("allow-all") || matches.is_present("allow-search");
let allow_symlink = matches.is_present("allow-all") || matches.is_present("allow-symlink");
let render_index = matches.is_present("render-index");
let render_try_index = matches.is_present("render-try-index");
@@ -204,6 +211,7 @@ impl Args {
enable_cors,
allow_delete,
allow_upload,
allow_search,
allow_symlink,
render_index,
render_try_index,

View File

@@ -133,6 +133,7 @@ impl Server {
let allow_upload = self.args.allow_upload;
let allow_delete = self.args.allow_delete;
let allow_search = self.args.allow_search;
let render_index = self.args.render_index;
let render_spa = self.args.render_spa;
let render_try_index = self.args.render_try_index;
@@ -152,8 +153,8 @@ impl Server {
.await?;
} else if query == "zip" {
self.handle_zip_dir(path, head_only, &mut res).await?;
} else if let Some(q) = query.strip_prefix("q=") {
let q = decode_uri(q).unwrap_or_default();
} else if allow_search && query.starts_with("q=") {
let q = decode_uri(&query[2..]).unwrap_or_default();
self.handle_query_dir(path, &q, head_only, &mut res).await?;
} else {
self.handle_ls_dir(path, true, head_only, &mut res).await?;
@@ -696,6 +697,7 @@ impl Server {
paths,
allow_upload: self.args.allow_upload,
allow_delete: self.args.allow_delete,
allow_search: self.args.allow_search,
dir_exists: exist,
};
let data = serde_json::to_string(&data).unwrap();
@@ -824,6 +826,7 @@ struct IndexData {
paths: Vec<PathItem>,
allow_upload: bool,
allow_delete: bool,
allow_search: bool,
dir_exists: bool,
}