Improve backend code quality
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2025-11-03 19:08:46 +01:00
parent 75ffa69afd
commit 4cd448208b
6 changed files with 34 additions and 57 deletions

View File

@@ -63,21 +63,20 @@ pub async fn download(
pub async fn serve_file(req: HttpRequest, file: &File, download_file: bool) -> HttpResult {
if !download_file {
// Check if the browser already knows the etag
if let Some(c) = req.headers().get(header::IF_NONE_MATCH) {
if c.to_str().unwrap_or("") == file.sha512.as_str() {
return Ok(HttpResponse::NotModified().finish());
}
if let Some(c) = req.headers().get(header::IF_NONE_MATCH)
&& c.to_str().unwrap_or("") == file.sha512.as_str()
{
return Ok(HttpResponse::NotModified().finish());
}
// Check if the browser already knows the file by date
if let Some(c) = req.headers().get(header::IF_MODIFIED_SINCE) {
let date_str = c.to_str().unwrap_or("");
if let Ok(date) = httpdate::parse_http_date(date_str) {
if date.add(Duration::from_secs(1))
if let Ok(date) = httpdate::parse_http_date(date_str)
&& date.add(Duration::from_secs(1))
>= time_utils::unix_to_system_time(file.time_create as u64)
{
return Ok(HttpResponse::NotModified().finish());
}
{
return Ok(HttpResponse::NotModified().finish());
}
}
}