clippy and fmt

This commit is contained in:
xenofem 2022-05-24 16:52:00 -04:00
parent 8497b4137d
commit 62e6d64253
3 changed files with 41 additions and 41 deletions

View file

@ -8,8 +8,8 @@ use std::{fmt::Debug, path::PathBuf, str::FromStr};
use actix_files::NamedFile;
use actix_web::{
error::InternalError, get, http::StatusCode, middleware::Logger, post, web, App, HttpRequest, HttpResponse,
HttpServer, Responder,
error::InternalError, get, http::StatusCode, middleware::Logger, post, web, App, HttpRequest,
HttpResponse, HttpServer, Responder,
};
use actix_web_actors::ws;
use askama::Template;
@ -51,7 +51,6 @@ pub fn log_auth_failure(ip_addr: &str) {
warn!("Incorrect authentication attempt from {}", ip_addr);
}
#[derive(Deserialize)]
struct DownloadRequest {
code: String,
@ -81,7 +80,7 @@ async fn handle_download(
let info = if let Some(i) = info {
i
} else {
return not_found(req, data, true)
return not_found(req, data, true);
};
let storage_path = data.config.storage_dir.join(code);
@ -102,15 +101,19 @@ async fn handle_download(
info,
selection,
}
.into_response(&req))
.into_response(&req))
} else {
let offsets = info.contents.as_deref().map(zip::file_data_offsets);
Ok(HttpResponse::Ok().body(DownloadInfo {
file: info,
code: code.clone(),
available: file.metadata().await?.len(),
offsets,
}.render().unwrap()))
Ok(HttpResponse::Ok().body(
DownloadInfo {
file: info,
code: code.clone(),
available: file.metadata().await?.len(),
offsets,
}
.render()
.unwrap(),
))
}
}
@ -133,7 +136,7 @@ async fn download_info(
let info = if let Some(i) = info {
i
} else {
return not_found(req, data, true)
return not_found(req, data, true);
};
let storage_path = data.config.storage_dir.join(code);
@ -146,18 +149,18 @@ async fn download_info(
}))
}
fn not_found<T>(
req: HttpRequest,
data: web::Data<AppState>,
report: bool,
) -> actix_web::Result<T> {
fn not_found<T>(req: HttpRequest, data: web::Data<AppState>, report: bool) -> actix_web::Result<T> {
if report {
let ip_addr = get_ip_addr(&req, data.config.reverse_proxy);
log_auth_failure(&ip_addr);
}
Err(InternalError::from_response("Download not found", NamedFile::open(data.config.static_dir.join("404.html"))?
.set_status_code(StatusCode::NOT_FOUND)
.into_response(&req)).into())
Err(InternalError::from_response(
"Download not found",
NamedFile::open(data.config.static_dir.join("404.html"))?
.set_status_code(StatusCode::NOT_FOUND)
.into_response(&req),
)
.into())
}
#[get("/upload")]