diff options
Diffstat (limited to 'server/src/routes')
| -rw-r--r-- | server/src/routes/stream.rs | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/server/src/routes/stream.rs b/server/src/routes/stream.rs index a72e0d9..f117070 100644 --- a/server/src/routes/stream.rs +++ b/server/src/routes/stream.rs @@ -14,28 +14,34 @@ use jellystream::SMediaInfo; use log::{info, warn}; use rocket::{ Either, Request, Response, get, head, - http::{Header, Status}, - request::{self, FromRequest}, + http::{Header, Status, uri::Segments}, + request::{self, FromRequest, FromSegments}, response::{self, Redirect, Responder}, }; -use std::{ - collections::{BTreeMap, BTreeSet}, - ops::Range, - sync::Arc, -}; +use std::{collections::BTreeSet, ops::Range, sync::Arc}; use tokio::{ io::{DuplexStream, duplex}, task::spawn_blocking, }; use tokio_util::io::SyncIoBridge; -#[head("/n/<_id>/stream?<spec..>")] +pub struct StringPath<'a>(Vec<&'a str>); +impl<'r> FromSegments<'r> for StringPath<'r> { + type Error = !; + fn from_segments( + segments: Segments<'r, rocket::http::uri::fmt::Path>, + ) -> Result<Self, Self::Error> { + Ok(Self(segments.collect())) + } +} + +#[head("/n/<_id>/media/<path..>")] pub async fn r_stream_head( _sess: RequestInfo<'_>, _id: &str, - spec: BTreeMap<String, String>, + path: StringPath<'_>, ) -> Result<Either<StreamResponse, Redirect>, MyError> { - let spec = StreamSpec::from_query_kv(&spec).map_err(|x| anyhow!("spec invalid: {x}"))?; + let spec = StreamSpec::from_path(&path.0).map_err(|x| anyhow!("media path invalid: {x}"))?; let head = jellystream::stream_head(&spec); Ok(Either::Left(StreamResponse { stream: duplex(0).0, @@ -45,14 +51,14 @@ pub async fn r_stream_head( })) } -#[get("/n/<slug>/stream?<spec..>")] +#[get("/n/<slug>/media/<path..>")] pub async fn r_stream( ri: RequestInfo<'_>, slug: &str, range: Option<RequestRange>, - spec: BTreeMap<String, String>, + path: StringPath<'_>, ) -> Result<StreamResponse, MyError> { - let spec = StreamSpec::from_query_kv(&spec).map_err(|x| anyhow!("spec invalid: {x}"))?; + let spec = StreamSpec::from_path(&path.0).map_err(|x| anyhow!("media path invalid: {x}"))?; let mut node = None; ri.state.database.transaction(&mut |txn| { |