refactor: consolidate bulk actions, URL assembly, and case-artefact filenames
Pulls three pattern groups into shared helpers so a rename or wire-format tweak edits one file instead of 10+: - BulkAction enum in doctate-common replaces the "close"/"analyze"/"reset" string literals that were duplicated between the bulk handler and 3 attack/CSRF test files. FromStr preserves the exact "Unbekannte Aktion" error shape; the handler match is now exhaustive over the enum. - join_url helper in doctate-common absorbs 7 identical trim_end_matches+format! call sites across client-core, client-desktop, server/transcribe (ollama, whisper), and server/analyze (llm). - server/tests/common/artefacts.rs re-exports ONELINER_FILENAME (doctate-common), DOCUMENT_FILE + ANALYSIS_INPUT_FILE (doctate-server::analyze), and CLOSE_MARKER (doctate-server::paths) so test files reference the canonical name instead of inlining literals. Also lifts client-desktop local duplication: - paths.rs: project_path helper collapses 4 identical ProjectDirs chains - main.rs: or_die helper replaces 4 eprintln!+exit(1) blocks - app.rs: named RecordingContext struct replaces (Uuid, String) tuple at 3 sites around the ffmpeg-flush finalization path Verification: 397 tests pass (baseline was 389; +8 for new unit tests on BulkAction and join_url), 0 failed, 4 ignored (unchanged). clippy clean.
This commit is contained in:
@@ -27,6 +27,7 @@ use doctate_common::constants::{
|
||||
API_KEY_HEADER, CONTENT_TYPE_AUDIO_MP4, FIELD_AUDIO, FIELD_CASE_ID, FIELD_RECORDED_AT,
|
||||
UPLOAD_PATH,
|
||||
};
|
||||
use doctate_common::join_url;
|
||||
use doctate_common::oneliners::{ONELINERS_PATH, OnelinersResponse};
|
||||
use reqwest::StatusCode;
|
||||
use tokio::sync::{mpsc, watch};
|
||||
@@ -369,7 +370,7 @@ pub(crate) async fn post_upload(
|
||||
.text(FIELD_RECORDED_AT, upload.recorded_at.clone())
|
||||
.part(FIELD_AUDIO, audio_part);
|
||||
|
||||
let url = format!("{}{}", config.server_url.trim_end_matches('/'), UPLOAD_PATH);
|
||||
let url = join_url(&config.server_url, UPLOAD_PATH);
|
||||
|
||||
let resp = match http
|
||||
.post(&url)
|
||||
@@ -406,11 +407,7 @@ pub(crate) async fn poll_once(
|
||||
cache: &SnapshotCache,
|
||||
etag: &mut Option<String>,
|
||||
) -> Result<PollOutcome, PollError> {
|
||||
let url = format!(
|
||||
"{}{}",
|
||||
config.server_url.trim_end_matches('/'),
|
||||
ONELINERS_PATH,
|
||||
);
|
||||
let url = join_url(&config.server_url, ONELINERS_PATH);
|
||||
|
||||
let mut req = http.get(&url).header(API_KEY_HEADER, &config.api_key);
|
||||
if let Some(tag) = etag.as_deref() {
|
||||
|
||||
Reference in New Issue
Block a user