feat: Add transcription worker and state management
Introduce an `AppState` struct to hold shared application state, including configuration and the transcription sender. Modify `create_router` and `create_router_with_state` to use `AppState`. Update `main.rs` to initialize the transcription worker and pass the `AppState` to the router. Implement the transcription worker logic in `server/src/transcribe/worker.rs`, handling job queues, FFmpeg remuxing, and Whisper transcription. Update `server/src/auth.rs` to use `Arc<Config>` from the shared state. Modify `server/src/routes/upload.rs` to enqueue transcription jobs and handle potential errors. Add `TranscribeJob` and channel types in `server/src/transcribe/mod.rs`.
This commit is contained in:
+35
-3
@@ -7,11 +7,43 @@ pub mod transcribe;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use axum::extract::FromRef;
|
||||
use axum::Router;
|
||||
|
||||
use config::Config;
|
||||
use transcribe::TranscribeSender;
|
||||
|
||||
/// Build the application router. Used by main.rs and integration tests.
|
||||
pub fn create_router(config: Arc<Config>) -> Router {
|
||||
routes::api_router().with_state(config)
|
||||
/// Shared application state. Clonable — all fields are cheap to clone
|
||||
/// (`Arc` and `mpsc::Sender`).
|
||||
#[derive(Clone)]
|
||||
pub struct AppState {
|
||||
pub config: Arc<Config>,
|
||||
pub transcribe_tx: TranscribeSender,
|
||||
}
|
||||
|
||||
impl FromRef<AppState> for Arc<Config> {
|
||||
fn from_ref(state: &AppState) -> Self {
|
||||
state.config.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl FromRef<AppState> for TranscribeSender {
|
||||
fn from_ref(state: &AppState) -> Self {
|
||||
state.transcribe_tx.clone()
|
||||
}
|
||||
}
|
||||
|
||||
/// Test/simple entrypoint: jobs pushed into the transcribe channel are dropped
|
||||
/// because the receiver is not retained. Use [`create_router_with_state`] from
|
||||
/// `main.rs` where a real worker owns the receiver.
|
||||
pub fn create_router(config: Arc<Config>) -> Router {
|
||||
let (tx, _rx) = transcribe::channel();
|
||||
create_router_with_state(AppState {
|
||||
config,
|
||||
transcribe_tx: tx,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn create_router_with_state(state: AppState) -> Router {
|
||||
routes::api_router().with_state(state)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user