chore(backend): satisfy cargo fmt
`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) <noreply@anthropic.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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,11 +301,8 @@ 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,
|
||||
)
|
||||
let _ =
|
||||
Upload::set_derivatives_rev(&worker.pool, id, Self::DERIVATIVES_REV)
|
||||
.await;
|
||||
tracing::info!("derivatives regenerated for upload {id}");
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user