aboutsummaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2026-03-07 04:02:48 +0100
committermetamuffin <metamuffin@disroot.org>2026-03-07 04:02:48 +0100
commit4ce6d64648634bd8d22e8ed0676e0e5b22947dc3 (patch)
treec1df9c9f623603651157006b9fd249de6d63fc7b /server
parentd3ed810656a563fc733771e760b2abbb05bd98cb (diff)
downloadjellything-4ce6d64648634bd8d22e8ed0676e0e5b22947dc3.tar
jellything-4ce6d64648634bd8d22e8ed0676e0e5b22947dc3.tar.bz2
jellything-4ce6d64648634bd8d22e8ed0676e0e5b22947dc3.tar.zst
new media path format
Diffstat (limited to 'server')
-rw-r--r--server/src/main.rs2
-rw-r--r--server/src/routes/stream.rs32
2 files changed, 20 insertions, 14 deletions
diff --git a/server/src/main.rs b/server/src/main.rs
index 0c42bb6..2837940 100644
--- a/server/src/main.rs
+++ b/server/src/main.rs
@@ -3,7 +3,7 @@
which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
Copyright (C) 2026 metamuffin <metamuffin.org>
*/
-#![feature(int_roundings, str_as_str, duration_constructors)]
+#![feature(int_roundings, str_as_str, duration_constructors, never_type)]
#![allow(clippy::needless_borrows_for_generic_args)]
#![recursion_limit = "4096"]
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| {