feat: Add API endpoint for listing oneliners

This commit introduces a new API endpoint `/api/oneliners` that allows
authenticated users to retrieve a list of their recent oneliners.

The endpoint supports conditional GET requests using the `ETag` header
for efficient caching. It also allows specifying a time window for the
oneliners via the `hours` query parameter, with sensible defaults and
clamping.

The implementation includes:
- A new route handler `handle_oneliners`.
- A new type `OnelinerWatermark` for tracking user-specific timestamps.
- Logic for scanning user data directories, filtering by time, and
  handling deleted cases.
- Test cases to cover various scenarios, including caching, time
  windowing, and edge cases.
This commit is contained in:
2026-04-18 09:27:23 +02:00
parent 6fbb549ddf
commit 94392e72d8
10 changed files with 658 additions and 16 deletions
+15 -2
View File
@@ -12,7 +12,7 @@ use doctate_server::analyze;
use doctate_server::config::Config;
use doctate_server::gazetteer::{Gazetteer, SpellbookDict};
use doctate_server::transcribe;
use doctate_server::AppState;
use doctate_server::{AppState, OnelinerWatermark};
#[tokio::main]
async fn main() {
@@ -110,6 +110,13 @@ async fn main() {
}
});
// Oneliner watermark: per-user "last successful oneliner write (UTC)".
// Feeds the ETag on `/api/oneliners`. Shared across the transcribe
// worker (writer) and the oneliners route handler (reader).
let oneliner_watermark: OnelinerWatermark = Arc::new(tokio::sync::RwLock::new(
std::collections::HashMap::new(),
));
// Transcription pipeline: channel + worker + recovery scan.
let (transcribe_tx, transcribe_rx) = transcribe::channel();
let transcribe_busy: doctate_server::WorkerBusy =
@@ -120,6 +127,7 @@ async fn main() {
http_client.clone(),
transcribe_busy.clone(),
vocab.clone(),
oneliner_watermark.clone(),
));
{
let tx = transcribe_tx.clone();
@@ -127,11 +135,15 @@ async fn main() {
let client = http_client.clone();
let cfg = config.clone();
let vocab = vocab.clone();
let watermark = oneliner_watermark.clone();
tokio::spawn(async move {
transcribe::recovery::scan_and_enqueue(&data_path, &tx).await;
// Then catch up oneliners for cases that crashed between
// transcript-write and oneliner-write in a previous run.
transcribe::recovery::regenerate_missing_oneliners(&data_path, &client, &cfg, &vocab).await;
transcribe::recovery::regenerate_missing_oneliners(
&data_path, &client, &cfg, &vocab, &watermark,
)
.await;
});
}
@@ -161,6 +173,7 @@ async fn main() {
session_store: doctate_server::web_session::new_store(),
analyze_busy: doctate_server::AnalyzeBusy(analyze_busy),
transcribe_busy: doctate_server::TranscribeBusy(transcribe_busy),
oneliner_watermark,
};
let addr = format!("0.0.0.0:{}", config.server_port);