aboutsummaryrefslogtreecommitdiff
path: root/stream/src
diff options
context:
space:
mode:
Diffstat (limited to 'stream/src')
-rw-r--r--stream/src/jhls.rs10
-rw-r--r--stream/src/lib.rs16
-rw-r--r--stream/src/segment.rs10
3 files changed, 28 insertions, 8 deletions
diff --git a/stream/src/jhls.rs b/stream/src/jhls.rs
index 5183a26..850cc32 100644
--- a/stream/src/jhls.rs
+++ b/stream/src/jhls.rs
@@ -1,8 +1,9 @@
use anyhow::Result;
-use jellybase::CONF;
+use jellybase::{permission::PermissionSetExt, CONF};
use jellycommon::{
jhls::{JhlsMetadata, JhlsTrack},
stream::StreamSpec,
+ user::{PermissionSet, UserPermission},
LocalTrack, Node,
};
use tokio::io::{AsyncWriteExt, DuplexStream};
@@ -12,6 +13,7 @@ pub async fn jhls_stream(
track_sources: Vec<LocalTrack>,
_spec: StreamSpec,
mut b: DuplexStream,
+ perms: &PermissionSet,
) -> Result<()> {
let media = node.public.media.clone().unwrap();
let tracks = tokio::task::spawn_blocking(move || {
@@ -42,7 +44,11 @@ pub async fn jhls_stream(
let out = serde_json::to_string(&JhlsMetadata {
tracks,
- extra_profiles: CONF.transcoding_profiles.clone(),
+ extra_profiles: if perms.check(&UserPermission::Transcode) {
+ CONF.transcoding_profiles.clone()
+ } else {
+ vec![]
+ },
duration: media.duration,
})?;
tokio::spawn(async move { b.write_all(out.as_bytes()).await });
diff --git a/stream/src/lib.rs b/stream/src/lib.rs
index 85ff382..e9b9a4b 100644
--- a/stream/src/lib.rs
+++ b/stream/src/lib.rs
@@ -10,9 +10,10 @@ pub mod segment;
use anyhow::{anyhow, bail, Context, Result};
use hls::{hls_master_stream, hls_variant_stream};
-use jellybase::CONF;
+use jellybase::{permission::PermissionSetExt, CONF};
use jellycommon::{
stream::{StreamFormat, StreamSpec},
+ user::{PermissionSet, UserPermission},
LocalTrack, MediaSource, Node,
};
use jhls::jhls_stream;
@@ -41,7 +42,14 @@ pub fn stream_head(spec: &StreamSpec) -> StreamHead {
}
}
-pub async fn stream(node: Node, spec: StreamSpec, range: Range<usize>) -> Result<DuplexStream> {
+pub async fn stream(
+ node: Node,
+ spec: StreamSpec,
+ range: Range<usize>,
+ perms: &PermissionSet,
+) -> Result<DuplexStream> {
+ perms.assert(&UserPermission::StreamFormat(spec.format))?;
+
let (a, b) = duplex(4096);
let track_sources = match node
@@ -59,8 +67,8 @@ pub async fn stream(node: Node, spec: StreamSpec, range: Range<usize>) -> Result
StreamFormat::Matroska => remux_stream(node, track_sources, spec, range, b).await?,
StreamFormat::HlsMaster => hls_master_stream(node, track_sources, spec, b).await?,
StreamFormat::HlsVariant => hls_variant_stream(node, track_sources, spec, b).await?,
- StreamFormat::Jhls => jhls_stream(node, track_sources, spec, b).await?,
- StreamFormat::Segment => segment_stream(node, track_sources, spec, b).await?,
+ StreamFormat::Jhls => jhls_stream(node, track_sources, spec, b, perms).await?,
+ StreamFormat::Segment => segment_stream(node, track_sources, spec, b, perms).await?,
}
Ok(a)
diff --git a/stream/src/segment.rs b/stream/src/segment.rs
index ce3f8e1..309da1d 100644
--- a/stream/src/segment.rs
+++ b/stream/src/segment.rs
@@ -4,8 +4,12 @@
Copyright (C) 2023 metamuffin <metamuffin.org>
*/
use anyhow::{anyhow, bail, Result};
-use jellybase::{AssetLocationExt, CONF};
-use jellycommon::{stream::StreamSpec, LocalTrack, Node};
+use jellybase::{permission::PermissionSetExt, AssetLocationExt, CONF};
+use jellycommon::{
+ stream::StreamSpec,
+ user::{PermissionSet, UserPermission},
+ LocalTrack, Node,
+};
use jellytranscoder::snippet::transcode;
use log::warn;
use tokio::{fs::File, io::DuplexStream};
@@ -16,6 +20,7 @@ pub async fn segment_stream(
track_sources: Vec<LocalTrack>,
spec: StreamSpec,
mut b: DuplexStream,
+ perms: &PermissionSet,
) -> Result<()> {
if spec.tracks.len() != 1 {
bail!("unsupported number of tracks for segment, must be exactly one");
@@ -24,6 +29,7 @@ pub async fn segment_stream(
let n = spec.index.ok_or(anyhow!("segment index missing"))?;
if let Some(profile) = spec.profile {
+ perms.assert(&UserPermission::Transcode)?;
let location = transcode(
&format!("{track} {n} {:?}", node.private.source), // TODO maybe not use the entire source
CONF.transcoding_profiles