chore: Cleanup clippy warnings

This commit is contained in:
Ashhhleyyy 2022-07-05 11:41:08 +01:00
parent 88aa3093dd
commit d1d12bdfb5
Signed by: ash
GPG key ID: 83B789081A0878FB
2 changed files with 9 additions and 12 deletions

View file

@ -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(()));
}
}

View file

@ -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<impl std::io::Read + std::io::Seek>,
filename: &str,
) -> color_eyre::Result<Option<Vec<u8>>> {
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<String>,
) -> 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<S, E>(target: PathBuf, stream: S) -> color_eyre::Result<()>