various: simplify code; work on security and performance
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I9a5114addcab5fbff430ab2b919b83466a6a6964
This commit is contained in:
parent
016841b200
commit
c4adc4e3e0
75 changed files with 12921 additions and 358 deletions
63
crates/pinakes-server/src/routes/transcode.rs
Normal file
63
crates/pinakes-server/src/routes/transcode.rs
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
use axum::Json;
|
||||
use axum::extract::{Path, Query, State};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::dto::*;
|
||||
use crate::error::ApiError;
|
||||
use crate::state::AppState;
|
||||
|
||||
use pinakes_core::model::MediaId;
|
||||
|
||||
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})))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue