diff --git a/src/projects.rs b/src/projects.rs index cf599b2..19c65e6 100644 --- a/src/projects.rs +++ b/src/projects.rs @@ -19,7 +19,7 @@ where .expect("missing auth token extension"); if let Some(auth) = req.headers().get("authorization") { if let Ok(auth) = auth.to_str() { - if auth == &token.0 { + if auth == token.0 { return Ok(Self(())); } } diff --git a/src/routes.rs b/src/routes.rs index b6c07b9..0c02772 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -40,13 +40,13 @@ async fn get_asset( let filename = filename.clone(); move || { let mut zip = ZipArchive::new(File::open(path)?)?; - let asset = find_asset(&mut zip, &filename.clone())?; + let asset = find_asset(&mut zip, &filename)?; let asset = if let Some(asset) = asset { Some(( mime_guess::from_path(filename).first_or_octet_stream(), asset, )) - } else if filename.ends_with("/") { + } else if filename.ends_with('/') { let changed_name = format!("{filename}index.html"); find_asset(&mut zip, &changed_name)?.map(|data| { ( @@ -88,11 +88,7 @@ fn find_asset( zip: &mut ZipArchive, filename: &str, ) -> color_eyre::Result>> { - let filename = if filename.starts_with("/") { - &filename[1..] - } else { - filename - }; + let filename = filename.strip_prefix('/').unwrap_or(filename); let entry = zip.by_name(filename); match entry { Ok(mut entry) => { @@ -114,20 +110,21 @@ async fn upload_project( _auth: Authed, Path(project): Path, ) -> Result<(), StatusCode> { - while let Some(field) = multipart + if let Some(field) = multipart .next_field() .await .map_err(|_| StatusCode::BAD_REQUEST)? { let path = path::Path::new("project-archives").join(format!("{project}.zip")); - return if let Err(e) = stream_to_file(path, field).await { + if let Err(e) = stream_to_file(path, field).await { tracing::error!(%e, "failed to upload project archive"); Err(StatusCode::INTERNAL_SERVER_ERROR) } else { Ok(()) - }; + } + } else { + Err(StatusCode::BAD_REQUEST) } - Err(StatusCode::BAD_REQUEST) } async fn stream_to_file(target: PathBuf, stream: S) -> color_eyre::Result<()>