Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I67206fd813d514f8903041eea0a4cd266a6a6964
70 lines
1.8 KiB
Rust
70 lines
1.8 KiB
Rust
use axum::{
|
|
Json,
|
|
extract::{Path, Query, State},
|
|
};
|
|
use pinakes_core::model::MediaId;
|
|
use uuid::Uuid;
|
|
|
|
use crate::{
|
|
dto::{CreateTranscodeRequest, PaginationParams, TranscodeSessionResponse},
|
|
error::ApiError,
|
|
state::AppState,
|
|
};
|
|
|
|
pub async fn start_transcode(
|
|
State(state): State<AppState>,
|
|
Path(id): Path<Uuid>,
|
|
Json(req): Json<CreateTranscodeRequest>,
|
|
) -> Result<Json<serde_json::Value>, ApiError> {
|
|
let job_id = state
|
|
.job_queue
|
|
.submit(pinakes_core::jobs::JobKind::Transcode {
|
|
media_id: MediaId(id),
|
|
profile: req.profile,
|
|
})
|
|
.await;
|
|
Ok(Json(serde_json::json!({"job_id": job_id.to_string()})))
|
|
}
|
|
|
|
pub async fn get_session(
|
|
State(state): State<AppState>,
|
|
Path(id): Path<Uuid>,
|
|
) -> Result<Json<TranscodeSessionResponse>, ApiError> {
|
|
let session = state.storage.get_transcode_session(id).await?;
|
|
Ok(Json(TranscodeSessionResponse::from(session)))
|
|
}
|
|
|
|
pub async fn list_sessions(
|
|
State(state): State<AppState>,
|
|
Query(params): Query<PaginationParams>,
|
|
) -> Result<Json<Vec<TranscodeSessionResponse>>, ApiError> {
|
|
let _ = params; // reserved for future filtering
|
|
let sessions = state.storage.list_transcode_sessions(None).await?;
|
|
Ok(Json(
|
|
sessions
|
|
.into_iter()
|
|
.map(TranscodeSessionResponse::from)
|
|
.collect(),
|
|
))
|
|
}
|
|
|
|
pub async fn cancel_session(
|
|
State(state): State<AppState>,
|
|
Path(id): Path<Uuid>,
|
|
) -> Result<Json<serde_json::Value>, ApiError> {
|
|
if let Some(transcode_service) = &state.transcode_service {
|
|
transcode_service
|
|
.cancel_transcode(id, &state.storage)
|
|
.await?;
|
|
} else {
|
|
state
|
|
.storage
|
|
.update_transcode_status(
|
|
id,
|
|
pinakes_core::transcode::TranscodeStatus::Cancelled,
|
|
0.0,
|
|
)
|
|
.await?;
|
|
}
|
|
Ok(Json(serde_json::json!({"cancelled": true})))
|
|
}
|