Merge branch 'chore/rustfmt'

This commit is contained in:
fabi
2026-07-28 21:26:28 +02:00
5 changed files with 39 additions and 28 deletions

View File

@@ -221,7 +221,8 @@ pub async fn recover(
// unconditional throwaway one for names that don't exist (see below), so an unknown // 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 // 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. // 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( if let Err(retry_after_secs) = state.rate_limiter.check_with_retry(
format!("recover_ip:{ip}"), format!("recover_ip:{ip}"),
ip_ceiling, ip_ceiling,
@@ -411,8 +412,7 @@ pub async fn admin_login(
let dummy_pin: String = (0..32) let dummy_pin: String = (0..32)
.map(|_| rand::rng().random_range(b'a'..=b'z') as char) .map(|_| rand::rng().random_range(b'a'..=b'z') as char)
.collect(); .collect();
let dummy_hash = let dummy_hash = hash_password(dummy_pin.clone(), 4).await?;
hash_password(dummy_pin.clone(), 4).await?;
let user = User::create(&state.pool, event.id, admin_name, &dummy_hash).await?; let user = User::create(&state.pool, event.id, admin_name, &dummy_hash).await?;
sqlx::query("UPDATE \"user\" SET role = 'admin' WHERE id = $1") sqlx::query("UPDATE \"user\" SET role = 'admin' WHERE id = $1")
.bind(user.id) .bind(user.id)

View File

@@ -760,9 +760,7 @@ async fn stream_media_file(
.len(); .len();
let range = parse_range( let range = parse_range(
req_headers req_headers.get(header::RANGE).and_then(|v| v.to_str().ok()),
.get(header::RANGE)
.and_then(|v| v.to_str().ok()),
len, len,
); );
@@ -789,10 +787,7 @@ async fn stream_media_file(
let span = end - start + 1; let span = end - start + 1;
base(StatusCode::PARTIAL_CONTENT) base(StatusCode::PARTIAL_CONTENT)
.header(header::CONTENT_LENGTH, span) .header(header::CONTENT_LENGTH, span)
.header( .header(header::CONTENT_RANGE, format!("bytes {start}-{end}/{len}"))
header::CONTENT_RANGE,
format!("bytes {start}-{end}/{len}"),
)
.body(Body::from_stream(ReaderStream::new(file.take(span)))) .body(Body::from_stream(ReaderStream::new(file.take(span))))
.map_err(|e| AppError::Internal(e.into())) .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. // 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. // 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 /// Streaming access to an upload's compressed **preview** image. Gated exactly like
@@ -980,13 +982,22 @@ mod tests {
#[test] #[test]
fn start_past_eof_is_416_not_a_full_body() { fn start_past_eof_is_416_not_a_full_body() {
// Answering 200 here makes a player re-request forever. // Answering 200 here makes a player re-request forever.
assert_eq!(parse_range(Some("bytes=100-"), 100), RangeSpec::Unsatisfiable); assert_eq!(
assert_eq!(parse_range(Some("bytes=200-300"), 100), RangeSpec::Unsatisfiable); parse_range(Some("bytes=100-"), 100),
RangeSpec::Unsatisfiable
);
assert_eq!(
parse_range(Some("bytes=200-300"), 100),
RangeSpec::Unsatisfiable
);
} }
#[test] #[test]
fn inverted_range_is_unsatisfiable() { 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] #[test]

View File

@@ -150,11 +150,7 @@ impl Upload {
/// Stamp which revision of the derivative pipeline produced this row's preview/display, /// 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. /// so the startup backfill can find rows generated by an older one exactly once.
pub async fn set_derivatives_rev( pub async fn set_derivatives_rev(pool: &PgPool, id: Uuid, rev: i16) -> Result<(), sqlx::Error> {
pool: &PgPool,
id: Uuid,
rev: i16,
) -> Result<(), sqlx::Error> {
sqlx::query("UPDATE upload SET derivatives_rev = $2 WHERE id = $1") sqlx::query("UPDATE upload SET derivatives_rev = $2 WHERE id = $1")
.bind(id) .bind(id)
.bind(rev) .bind(rev)

View File

@@ -86,8 +86,7 @@ impl CompressionWorker {
error = ?e, %upload_id, attempt, error = ?e, %upload_id, attempt,
"compression attempt failed; retrying" "compression attempt failed; retrying"
); );
tokio::time::sleep(std::time::Duration::from_secs(2u64.pow(attempt))) tokio::time::sleep(std::time::Duration::from_secs(2u64.pow(attempt))).await;
.await;
attempt += 1; attempt += 1;
// The data may have been reset while we slept (e2e TRUNCATE). // The data may have been reset while we slept (e2e TRUNCATE).
if worker.generation.load(Ordering::SeqCst) != born_at { if worker.generation.load(Ordering::SeqCst) != born_at {
@@ -302,11 +301,8 @@ impl CompressionWorker {
Ok((preview_rel, display_rel)) => { Ok((preview_rel, display_rel)) => {
let _ = Upload::set_preview_path(&worker.pool, id, &preview_rel).await; 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_display_path(&worker.pool, id, &display_rel).await;
let _ = Upload::set_derivatives_rev( let _ =
&worker.pool, Upload::set_derivatives_rev(&worker.pool, id, Self::DERIVATIVES_REV)
id,
Self::DERIVATIVES_REV,
)
.await; .await;
tracing::info!("derivatives regenerated for upload {id}"); tracing::info!("derivatives regenerated for upload {id}");
} }

View File

@@ -86,7 +86,15 @@ async fn sweeps_only_long_failed_soft_deleted_uploads(pool: PgPool) {
// Everything below is a near-miss that must survive. // Everything below is a near-miss that must survive.
// A healthy live upload — the catastrophic case if the predicate were ever loosened. // 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 // 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. // of keeping the file, so reclaiming it early would defeat the fix it protects.
let recent = seed_upload( let recent = seed_upload(