From 117c0c547f99df1a92a763a60341ee99603a8db9 Mon Sep 17 00:00:00 2001 From: fabi Date: Tue, 28 Jul 2026 21:26:28 +0200 Subject: [PATCH] chore(backend): satisfy cargo fmt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `checks.yml` runs `cargo fmt --check`, and it has been failing since the round-1 audit fixes: I gated those on `cargo build` and `cargo clippy` but never ran fmt, so three files drifted then and eight more this round. Pure formatting — no behaviour change; clippy stays at zero and all 70 backend tests still pass. Worth noting for next time: clippy passing is not evidence fmt does. Co-Authored-By: Claude Opus 5 (1M context) --- backend/src/auth/handlers.rs | 6 ++--- backend/src/handlers/upload.rs | 33 +++++++++++++++++--------- backend/src/models/upload.rs | 6 +---- backend/src/services/compression.rs | 12 ++++------ backend/tests/failed_original_sweep.rs | 10 +++++++- 5 files changed, 39 insertions(+), 28 deletions(-) diff --git a/backend/src/auth/handlers.rs b/backend/src/auth/handlers.rs index f7d495d..b16e15b 100644 --- a/backend/src/auth/handlers.rs +++ b/backend/src/auth/handlers.rs @@ -221,7 +221,8 @@ pub async fn recover( // unconditional throwaway one for names that don't exist (see below), so an unknown // name is the CHEAPEST way to make the server do ~200ms of hashing. Checked before // the per-name bucket so a name generator can't walk past it. - let ip_ceiling = config::get_usize(&state.config_cache, "recover_ip_rate_per_min", 30).await; + let ip_ceiling = + config::get_usize(&state.config_cache, "recover_ip_rate_per_min", 30).await; if let Err(retry_after_secs) = state.rate_limiter.check_with_retry( format!("recover_ip:{ip}"), ip_ceiling, @@ -411,8 +412,7 @@ pub async fn admin_login( let dummy_pin: String = (0..32) .map(|_| rand::rng().random_range(b'a'..=b'z') as char) .collect(); - let dummy_hash = - hash_password(dummy_pin.clone(), 4).await?; + let dummy_hash = hash_password(dummy_pin.clone(), 4).await?; let user = User::create(&state.pool, event.id, admin_name, &dummy_hash).await?; sqlx::query("UPDATE \"user\" SET role = 'admin' WHERE id = $1") .bind(user.id) diff --git a/backend/src/handlers/upload.rs b/backend/src/handlers/upload.rs index 6c1ac71..55f6830 100644 --- a/backend/src/handlers/upload.rs +++ b/backend/src/handlers/upload.rs @@ -760,9 +760,7 @@ async fn stream_media_file( .len(); let range = parse_range( - req_headers - .get(header::RANGE) - .and_then(|v| v.to_str().ok()), + req_headers.get(header::RANGE).and_then(|v| v.to_str().ok()), len, ); @@ -789,10 +787,7 @@ async fn stream_media_file( let span = end - start + 1; base(StatusCode::PARTIAL_CONTENT) .header(header::CONTENT_LENGTH, span) - .header( - header::CONTENT_RANGE, - format!("bytes {start}-{end}/{len}"), - ) + .header(header::CONTENT_RANGE, format!("bytes {start}-{end}/{len}")) .body(Body::from_stream(ReaderStream::new(file.take(span)))) .map_err(|e| AppError::Internal(e.into())) } @@ -838,7 +833,14 @@ pub async fn get_original( // Full-res original: never cache at the edge, so a takedown revokes access promptly. // Range requests still work under no-store; the client simply re-fetches each range. - stream_media_file(&headers, &absolute, media.mime_type, &disposition, "no-store").await + stream_media_file( + &headers, + &absolute, + media.mime_type, + &disposition, + "no-store", + ) + .await } /// Streaming access to an upload's compressed **preview** image. Gated exactly like @@ -980,13 +982,22 @@ mod tests { #[test] fn start_past_eof_is_416_not_a_full_body() { // Answering 200 here makes a player re-request forever. - assert_eq!(parse_range(Some("bytes=100-"), 100), RangeSpec::Unsatisfiable); - assert_eq!(parse_range(Some("bytes=200-300"), 100), RangeSpec::Unsatisfiable); + assert_eq!( + parse_range(Some("bytes=100-"), 100), + RangeSpec::Unsatisfiable + ); + assert_eq!( + parse_range(Some("bytes=200-300"), 100), + RangeSpec::Unsatisfiable + ); } #[test] fn inverted_range_is_unsatisfiable() { - assert_eq!(parse_range(Some("bytes=50-10"), 100), RangeSpec::Unsatisfiable); + assert_eq!( + parse_range(Some("bytes=50-10"), 100), + RangeSpec::Unsatisfiable + ); } #[test] diff --git a/backend/src/models/upload.rs b/backend/src/models/upload.rs index bcfb153..d27fbd7 100644 --- a/backend/src/models/upload.rs +++ b/backend/src/models/upload.rs @@ -150,11 +150,7 @@ impl Upload { /// Stamp which revision of the derivative pipeline produced this row's preview/display, /// so the startup backfill can find rows generated by an older one exactly once. - pub async fn set_derivatives_rev( - pool: &PgPool, - id: Uuid, - rev: i16, - ) -> Result<(), sqlx::Error> { + pub async fn set_derivatives_rev(pool: &PgPool, id: Uuid, rev: i16) -> Result<(), sqlx::Error> { sqlx::query("UPDATE upload SET derivatives_rev = $2 WHERE id = $1") .bind(id) .bind(rev) diff --git a/backend/src/services/compression.rs b/backend/src/services/compression.rs index f021f10..0ad11d7 100644 --- a/backend/src/services/compression.rs +++ b/backend/src/services/compression.rs @@ -86,8 +86,7 @@ impl CompressionWorker { error = ?e, %upload_id, attempt, "compression attempt failed; retrying" ); - tokio::time::sleep(std::time::Duration::from_secs(2u64.pow(attempt))) - .await; + tokio::time::sleep(std::time::Duration::from_secs(2u64.pow(attempt))).await; attempt += 1; // The data may have been reset while we slept (e2e TRUNCATE). if worker.generation.load(Ordering::SeqCst) != born_at { @@ -302,12 +301,9 @@ impl CompressionWorker { Ok((preview_rel, display_rel)) => { let _ = Upload::set_preview_path(&worker.pool, id, &preview_rel).await; let _ = Upload::set_display_path(&worker.pool, id, &display_rel).await; - let _ = Upload::set_derivatives_rev( - &worker.pool, - id, - Self::DERIVATIVES_REV, - ) - .await; + let _ = + Upload::set_derivatives_rev(&worker.pool, id, Self::DERIVATIVES_REV) + .await; tracing::info!("derivatives regenerated for upload {id}"); } Err(e) => { diff --git a/backend/tests/failed_original_sweep.rs b/backend/tests/failed_original_sweep.rs index a1743d9..96840df 100644 --- a/backend/tests/failed_original_sweep.rs +++ b/backend/tests/failed_original_sweep.rs @@ -86,7 +86,15 @@ async fn sweeps_only_long_failed_soft_deleted_uploads(pool: PgPool) { // Everything below is a near-miss that must survive. // A healthy live upload — the catastrophic case if the predicate were ever loosened. - let live = seed_upload(&pool, event_id, user_id, "done", None, "originals/e/live.jpg").await; + let live = seed_upload( + &pool, + event_id, + user_id, + "done", + None, + "originals/e/live.jpg", + ) + .await; // Failed but still inside the retention window: the recovery window is the entire point // of keeping the file, so reclaiming it early would defeat the fix it protects. let recent = seed_upload(