chore: fix typos

This commit is contained in:
sigoden 2024-01-15 12:53:59 +00:00
parent e1fabc7349
commit 9b348fc945
3 changed files with 12 additions and 12 deletions

View file

@ -29,15 +29,15 @@ lazy_static! {
pub struct AccessControl { pub struct AccessControl {
use_hashed_password: bool, use_hashed_password: bool,
users: IndexMap<String, (String, AccessPaths)>, users: IndexMap<String, (String, AccessPaths)>,
anony: Option<AccessPaths>, anonymous: Option<AccessPaths>,
} }
impl Default for AccessControl { impl Default for AccessControl {
fn default() -> Self { fn default() -> Self {
AccessControl { AccessControl {
use_hashed_password: false, use_hashed_password: false,
anony: Some(AccessPaths::new(AccessPerm::ReadWrite)),
users: IndexMap::new(), users: IndexMap::new(),
anonymous: Some(AccessPaths::new(AccessPerm::ReadWrite)),
} }
} }
} }
@ -66,15 +66,15 @@ impl AccessControl {
account_paths_pairs.push((user, pass, paths)); account_paths_pairs.push((user, pass, paths));
} }
} }
let mut anony = None; let mut anonymous = None;
if let Some(paths) = annoy_paths { if let Some(paths) = annoy_paths {
let mut access_paths = AccessPaths::default(); let mut access_paths = AccessPaths::default();
access_paths.merge(paths); access_paths.merge(paths);
anony = Some(access_paths); anonymous = Some(access_paths);
} }
let mut users = IndexMap::new(); let mut users = IndexMap::new();
for (user, pass, paths) in account_paths_pairs.into_iter() { for (user, pass, paths) in account_paths_pairs.into_iter() {
let mut access_paths = anony.clone().unwrap_or_default(); let mut access_paths = anonymous.clone().unwrap_or_default();
access_paths access_paths
.merge(paths) .merge(paths)
.ok_or_else(|| anyhow!("Invalid auth `{user}:{pass}@{paths}"))?; .ok_or_else(|| anyhow!("Invalid auth `{user}:{pass}@{paths}"))?;
@ -87,7 +87,7 @@ impl AccessControl {
Ok(Self { Ok(Self {
use_hashed_password, use_hashed_password,
users, users,
anony, anonymous,
}) })
} }
@ -120,7 +120,7 @@ impl AccessControl {
return (None, Some(AccessPaths::new(AccessPerm::ReadOnly))); return (None, Some(AccessPaths::new(AccessPerm::ReadOnly)));
} }
if let Some(paths) = self.anony.as_ref() { if let Some(paths) = self.anonymous.as_ref() {
return (None, paths.find(path, !is_readonly_method(method))); return (None, paths.find(path, !is_readonly_method(method)));
} }

View file

@ -623,7 +623,7 @@ impl Server {
) -> Result<()> { ) -> Result<()> {
let (mut writer, reader) = tokio::io::duplex(BUF_SIZE); let (mut writer, reader) = tokio::io::duplex(BUF_SIZE);
let filename = try_get_file_name(path)?; let filename = try_get_file_name(path)?;
set_content_diposition(res, false, &format!("{}.zip", filename))?; set_content_disposition(res, false, &format!("{}.zip", filename))?;
res.headers_mut() res.headers_mut()
.insert("content-type", HeaderValue::from_static("application/zip")); .insert("content-type", HeaderValue::from_static("application/zip"));
if head_only { if head_only {
@ -811,7 +811,7 @@ impl Server {
); );
let filename = try_get_file_name(path)?; let filename = try_get_file_name(path)?;
set_content_diposition(res, true, filename)?; set_content_disposition(res, true, filename)?;
res.headers_mut().typed_insert(AcceptRanges::bytes()); res.headers_mut().typed_insert(AcceptRanges::bytes());
@ -1599,7 +1599,7 @@ fn status_bad_request(res: &mut Response, body: &str) {
} }
} }
fn set_content_diposition(res: &mut Response, inline: bool, filename: &str) -> Result<()> { fn set_content_disposition(res: &mut Response, inline: bool, filename: &str) -> Result<()> {
let kind = if inline { "inline" } else { "attachment" }; let kind = if inline { "inline" } else { "attachment" };
let filename: String = filename let filename: String = filename
.chars() .chars()
@ -1682,7 +1682,7 @@ fn parse_upload_offset(headers: &HeaderMap<HeaderValue>, size: u64) -> Result<Op
Some(v) => v, Some(v) => v,
None => return Ok(None), None => return Ok(None),
}; };
let err = || anyhow!("Invalid X-Updage-Range header"); let err = || anyhow!("Invalid X-Update-Range header");
let value = value.to_str().map_err(|_| err())?; let value = value.to_str().map_err(|_| err())?;
if value == "append" { if value == "append" {
return Ok(Some(size)); return Ok(Some(size));

View file

@ -59,7 +59,7 @@ fn hidden_search_dir(#[case] server: TestServer, #[case] exist: bool) -> Result<
#[rstest] #[rstest]
#[case(server(&["--hidden", "hidden/"]), "dir4/", 1)] #[case(server(&["--hidden", "hidden/"]), "dir4/", 1)]
#[case(server(&["--hidden", "hidden"]), "dir4/", 0)] #[case(server(&["--hidden", "hidden"]), "dir4/", 0)]
fn hidden_dir_noly( fn hidden_dir_only(
#[case] server: TestServer, #[case] server: TestServer,
#[case] dir: &str, #[case] dir: &str,
#[case] count: usize, #[case] count: usize,