diff options
| author | Joris Guyonvarch | 2026-03-21 22:02:35 +0100 |
|---|---|---|
| committer | Joris Guyonvarch | 2026-03-21 22:02:35 +0100 |
| commit | f7d4a5d134e99da46976fa2817ce463c8d33fe12 (patch) | |
| tree | 787b1a4d01b7ebc06f56ef997fac736c8317a550 | |
| parent | 44cf1913ea1433b99154fb46f5761ac8b280908b (diff) | |
Format sources
| -rw-r--r-- | src/db/files.rs | 2 | ||||
| -rw-r--r-- | src/db/mod.rs | 4 | ||||
| -rw-r--r-- | src/routes.rs | 20 | ||||
| -rw-r--r-- | src/util.rs | 18 |
4 files changed, 25 insertions, 19 deletions
diff --git a/src/db/files.rs b/src/db/files.rs index f9b669d..44314bc 100644 --- a/src/db/files.rs +++ b/src/db/files.rs @@ -61,7 +61,7 @@ pub async fn get(conn: &Connection, file_id: impl Into<String>) -> Result<Option Some(_) => { log::error!("Error reading file in DB"); Ok(None) - }, + } None => Ok(None), } }) diff --git a/src/db/mod.rs b/src/db/mod.rs index c3c2258..935e05a 100644 --- a/src/db/mod.rs +++ b/src/db/mod.rs @@ -21,9 +21,7 @@ async fn apply_migrations(conn: &Connection) -> Result<()> { M::up(include_str!("migrations/02-strict-tables.sql")), ]); - Ok(conn - .call(move |conn| migrations .to_latest(conn)) - .await?) + Ok(conn.call(move |conn| migrations.to_latest(conn)).await?) } async fn set_pragma( diff --git a/src/routes.rs b/src/routes.rs index 509f1b2..ca1cc41 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -33,13 +33,9 @@ pub async fn routes( match (request.method(), path_parts) { (&Method::GET, []) => Ok(html(templates::INDEX)), - (&Method::GET, ["static", "main.js"]) => - Ok(static_file(MAIN_JS, "application/javascript")), - (&Method::GET, ["static", "icon.png"]) => - Ok(static_file(ICON_PNG, "image/png")), - (&Method::GET, ["static", "main.css"]) => { - Ok(static_file(MAIN_CSS, "text/css")) - } + (&Method::GET, ["static", "main.js"]) => Ok(static_file(MAIN_JS, "application/javascript")), + (&Method::GET, ["static", "icon.png"]) => Ok(static_file(ICON_PNG, "image/png")), + (&Method::GET, ["static", "main.css"]) => Ok(static_file(MAIN_CSS, "text/css")), (&Method::POST, ["upload"]) => { upload_file(request, db_conn, authorized_key, files_dir).await } @@ -134,9 +130,7 @@ async fn get( ) -> Result<Response<BoxBody<Bytes, std::io::Error>>> { let file = db::files::get(&db_conn, file_id).await; match (get_file, file) { - (GetFile::ShowPage, Ok(Some(file))) => { - Ok(html(templates::file_page(file))) - }, + (GetFile::ShowPage, Ok(Some(file))) => Ok(html(templates::file_page(file))), (GetFile::Download, Ok(Some(file))) => { let path = files_dir.join(file_id); Ok(stream_file(path, file).await) @@ -150,7 +144,7 @@ async fn get( } fn static_file( - content: &'static[u8], + content: &'static [u8], content_type: &str, ) -> Response<BoxBody<Bytes, std::io::Error>> { let response = Response::builder() @@ -204,7 +198,9 @@ fn html(text: impl Into<String>) -> Response<BoxBody<Bytes, std::io::Error>> { html_response(response(StatusCode::OK, text)) } -fn html_response(response: Response<BoxBody<Bytes, std::io::Error>>) -> Response<BoxBody<Bytes, std::io::Error>> { +fn html_response( + response: Response<BoxBody<Bytes, std::io::Error>>, +) -> Response<BoxBody<Bytes, std::io::Error>> { with_headers(response, vec![(CONTENT_TYPE, "text/html")]) } diff --git a/src/util.rs b/src/util.rs index 59ef485..0b68ecd 100644 --- a/src/util.rs +++ b/src/util.rs @@ -26,15 +26,27 @@ pub fn pretty_print_duration(d: Duration) -> String { if d.num_days() > 0 { let plural = if d.num_days() > 1 { "s" } else { "" }; let remaining_hours = d.num_hours() - d.num_days() * 24; - let formatted_hours = if remaining_hours > 0 { format!(" {remaining_hours} h") } else { "".to_string() }; + let formatted_hours = if remaining_hours > 0 { + format!(" {remaining_hours} h") + } else { + "".to_string() + }; format!("{} day{}{}", d.num_days(), plural, formatted_hours) } else if d.num_hours() > 0 { let remaining_minutes = d.num_minutes() - d.num_hours() * 60; - let formatted_minutes = if remaining_minutes > 0 { format!(" {remaining_minutes} min") } else { "".to_string() }; + let formatted_minutes = if remaining_minutes > 0 { + format!(" {remaining_minutes} min") + } else { + "".to_string() + }; format!("{} h{}", d.num_hours(), formatted_minutes) } else if d.num_minutes() > 0 { let remaining_seconds = d.num_seconds() - d.num_minutes() * 60; - let formatted_seconds = if remaining_seconds > 0 { format!(" {remaining_seconds} s") } else { "".to_string() }; + let formatted_seconds = if remaining_seconds > 0 { + format!(" {remaining_seconds} s") + } else { + "".to_string() + }; format!("{} min{}", d.num_minutes(), formatted_seconds) } else { format!("{} s", d.num_seconds()) |
