Implement audio range requests

This commit enables serving audio files via HTTP Range requests. This is
crucial for allowing HTML5 audio players to seek to specific positions
within an audio file without re-downloading the entire file.

The changes include:
- Modifying `handle_audio` in `server/src/routes/web.rs` to parse
  `Range` headers.
- Implementing `serve_range` to handle partial content responses.
- Adding a `parse_range` helper function.
- Updating tests to verify range request functionality.
- Adding `ACCEPT_RANGES: bytes` header to indicate support for range
  requests.
- Storing recording duration in a sidecar file for faster UI rendering.
- Enhancing the HTML template to support a custom audio player with
  seeking.
This commit is contained in:
2026-04-19 22:26:04 +02:00
parent 2bcdb5436e
commit 17aa5d7200
9 changed files with 665 additions and 48 deletions
+23
View File
@@ -53,6 +53,12 @@ pub async fn run(
}
};
// Persist the container duration as a sidecar so the UI can render it
// without the browser having to HEAD every audio file. Non-fatal — the
// recordings scan has a lazy-backfill path, and transcription is the
// critical workload here.
write_duration_sidecar(&audio_path, remuxed.path()).await;
let text = match whisper::transcribe(
&client,
&config.whisper_url,
@@ -126,6 +132,23 @@ async fn mark_failed(audio_path: &Path) {
}
}
/// Probe the (remuxed) audio and persist the duration next to the original file
/// as `<ts>.duration.txt`. Probes on the remuxed copy because its `moov` atom
/// sits at the start — ffprobe returns without seeking to EOF.
async fn write_duration_sidecar(audio_path: &Path, probe_path: &Path) {
let secs = match ffmpeg::probe_duration_seconds(probe_path).await {
Ok(s) => s,
Err(e) => {
warn!(audio = %audio_path.display(), error = %e, "ffprobe duration failed — UI will lazy-backfill");
return;
}
};
let sidecar = audio_path.with_extension("duration.txt");
if let Err(e) = tokio::fs::write(&sidecar, secs.to_string()).await {
warn!(sidecar = %sidecar.display(), error = %e, "writing duration sidecar failed");
}
}
/// Regenerate `case_dir/oneliner.txt` from **all** non-empty transcripts in
/// the case, joined chronologically. Called after every successful transcript
/// write so later recordings can correct earlier ones (mirror of the