From bc01b2de1c5469367627ec5186f8d85be808db49 Mon Sep 17 00:00:00 2001 From: jb-alvarado Date: Tue, 10 Sep 2024 08:16:20 +0200 Subject: [PATCH] unify public and public_root path, change order from preview url --- docker/Dockerfile | 4 ++-- docker/nonfree.Dockerfile | 4 ++-- docker/nvidia.Dockerfile | 4 ++-- ffplayout/src/api/routes.rs | 15 ++++++-------- ffplayout/src/utils/args_parse.rs | 24 ++++------------------ ffplayout/src/utils/mod.rs | 33 +++++++++++++----------------- migrations/00001_create_tables.sql | 2 +- 7 files changed, 31 insertions(+), 55 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 81f356bb..8a9e1af9 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,6 +1,6 @@ FROM alpine:latest -ARG FFPLAYOUT_VERSION=0.24.0-beta2 +ARG FFPLAYOUT_VERSION=0.24.0-beta4 ARG SHARED_STORAGE=false ENV DB=/db @@ -12,7 +12,7 @@ COPY <<-EOT /run.sh #!/bin/sh if [ ! -f /db/ffplayout.db ]; then - ffplayout -u admin -p admin -m contact@example.com --storage-root "/tv-media" --playlist-root "/playlists" --public-root "/public" --log-path "/logging" --shared-storage + ffplayout -u admin -p admin -m contact@example.com --storage-root "/tv-media" --playlist-root "/playlists" --public "/public" --log-path "/logging" --shared-storage fi /usr/bin/ffplayout -l "0.0.0.0:8787" diff --git a/docker/nonfree.Dockerfile b/docker/nonfree.Dockerfile index 88c955d1..bd6f27bb 100644 --- a/docker/nonfree.Dockerfile +++ b/docker/nonfree.Dockerfile @@ -1,6 +1,6 @@ FROM alpine:latest -ARG FFPLAYOUT_VERSION=0.24.0-beta2 +ARG FFPLAYOUT_VERSION=0.24.0-beta4 ARG SHARED_STORAGE=false ENV DB=/db @@ -14,7 +14,7 @@ COPY <<-EOT /run.sh #!/bin/sh if [ ! -f /db/ffplayout.db ]; then - ffplayout -u admin -p admin -m contact@example.com --storage-root "/tv-media" --playlist-root "/playlists" --public-root "/public" --log-path "/logging" --shared-storage + ffplayout -u admin -p admin -m contact@example.com --storage-root "/tv-media" --playlist-root "/playlists" --public "/public" --log-path "/logging" --shared-storage fi /usr/bin/ffplayout -l "0.0.0.0:8787" diff --git a/docker/nvidia.Dockerfile b/docker/nvidia.Dockerfile index 10d668b7..285ba915 100644 --- a/docker/nvidia.Dockerfile +++ b/docker/nvidia.Dockerfile @@ -1,6 +1,6 @@ FROM nvidia/cuda:12.5.0-runtime-rockylinux9 -ARG FFPLAYOUT_VERSION=0.24.0-beta2 +ARG FFPLAYOUT_VERSION=0.24.0-beta4 ARG SHARED_STORAGE=false ENV DB=/db @@ -204,7 +204,7 @@ COPY <<-EOT /run.sh #!/bin/sh if [ ! -f /db/ffplayout.db ]; then - ffplayout -u admin -p admin -m contact@example.com --storage-root "/tv-media" --playlist-root "/playlists" --public-root "/public" --log-path "/logging" --shared-storage + ffplayout -u admin -p admin -m contact@example.com --storage-root "/tv-media" --playlist-root "/playlists" --public "/public" --log-path "/logging" --shared-storage fi /usr/bin/ffplayout -l "0.0.0.0:8787" diff --git a/ffplayout/src/api/routes.rs b/ffplayout/src/api/routes.rs index 2d3c85bb..7c7b4f8e 100644 --- a/ffplayout/src/api/routes.rs +++ b/ffplayout/src/api/routes.rs @@ -52,10 +52,10 @@ use crate::utils::{ playlist::{delete_playlist, generate_playlist, read_playlist, write_playlist}, public_path, read_log_file, system, TextFilter, }; -use crate::vec_strings; use crate::{ api::auth::{create_jwt, Claims}, utils::advanced_config::AdvancedConfig, + vec_strings, }; use crate::{ db::{ @@ -1309,24 +1309,21 @@ async fn get_file( /// Can be used for HLS Playlist and other static files in public folder /// /// ```BASH -/// curl -X GET http://127.0.0.1:8787/live/1/stream.m3u8 +/// curl -X GET http://127.0.0.1:8787/1/live/stream.m3u8 /// ``` -#[get("/{public:live|preview|public}/{id}/{file_stem:.*}")] +#[get("/{id}/{public:live|preview|public}/{file_stem:.*}")] async fn get_public( - path: web::Path<(String, i32, String)>, + path: web::Path<(i32, String, String)>, controllers: web::Data>, ) -> Result { - let (public, id, file_stem) = path.into_inner(); - let public_path = public_path(); + let (id, public, file_stem) = path.into_inner(); let absolute_path = if file_stem.ends_with(".ts") || file_stem.ends_with(".m3u8") { let manager = controllers.lock().unwrap().get(id).unwrap(); let config = manager.config.lock().unwrap(); config.channel.hls_path.join(public) - } else if public_path.is_absolute() { - public_path.to_path_buf() } else { - env::current_dir()?.join(public_path) + public_path() } .clean(); diff --git a/ffplayout/src/utils/args_parse.rs b/ffplayout/src/utils/args_parse.rs index 7b9fc043..1707be3b 100644 --- a/ffplayout/src/utils/args_parse.rs +++ b/ffplayout/src/utils/args_parse.rs @@ -86,9 +86,6 @@ pub struct Args { #[clap(long, help = "List available channel ids")] pub list_channels: bool, - #[clap(long, env, help = "path to public files")] - pub public: Option, - #[clap(short, env, long, help = "Listen on IP:PORT, like: 127.0.0.1:8787")] pub listen: Option, @@ -123,8 +120,8 @@ pub struct Args { #[clap(long, env, help = "Log to console")] pub log_to_console: bool, - #[clap(long, env, help = "Public (HLS) output path")] - pub public_root: Option, + #[clap(long, env, help = "Path to public files, also HLS playlists")] + pub public: Option, #[clap(long, env, help = "Playlist root path")] pub playlist_root: Option, @@ -438,7 +435,7 @@ pub async fn run_args(pool: &Pool) -> Result<(), i32> { if !args.init && args.storage_root.is_some() && args.playlist_root.is_some() - && args.public_root.is_some() + && args.public.is_some() && args.log_path.is_some() { error_code = 0; @@ -448,7 +445,7 @@ pub async fn run_args(pool: &Pool) -> Result<(), i32> { secret: None, logging_path: args.log_path.unwrap().to_string_lossy().to_string(), playlist_root: args.playlist_root.unwrap(), - public_root: args.public_root.unwrap(), + public_root: args.public.unwrap(), storage_root: args.storage_root.unwrap(), shared_storage: args.shared_storage, }; @@ -523,19 +520,6 @@ pub async fn run_args(pool: &Pool) -> Result<(), i32> { }; } - if let Some(id) = ARGS.dump_config { - match PlayoutConfig::dump(pool, id).await { - Ok(_) => { - println!("Dump config to: ffplayout_{id}.toml"); - error_code = 0; - } - Err(e) => { - eprintln!("Dump config: {e}"); - error_code = 1; - } - }; - } - if let Some(id) = ARGS.dump_advanced { match AdvancedConfig::dump(pool, id).await { Ok(_) => { diff --git a/ffplayout/src/utils/mod.rs b/ffplayout/src/utils/mod.rs index 00aeb240..047006fa 100644 --- a/ffplayout/src/utils/mod.rs +++ b/ffplayout/src/utils/mod.rs @@ -30,6 +30,7 @@ pub mod playlist; pub mod system; pub mod task_runner; +use crate::db::models::GlobalSettings; use crate::player::utils::time_to_sec; use crate::utils::{errors::ServiceError, logging::log_file_path}; use crate::ARGS; @@ -195,34 +196,28 @@ pub fn db_path() -> Result<&'static str, Box> { } pub fn public_path() -> PathBuf { - if let Some(public) = &ARGS.public { + let config = GlobalSettings::global(); + let dev_path = env::current_dir() + .unwrap_or_default() + .join("frontend/.output/public/"); + let mut public_path = PathBuf::from(&config.public_root); + + if let Some(p) = &ARGS.public { // When public path is set as argument use this path for serving static files. // Works only when feature embed_frontend is not set. - let absolute_path = if public.is_absolute() { + let public = PathBuf::from(p); + + public_path = if public.is_absolute() { public.to_path_buf() } else { env::current_dir().unwrap_or_default().join(public) } .clean(); - - return absolute_path; + } else if cfg!(debug_assertions) && dev_path.is_dir() { + public_path = dev_path; } - let path = env::current_dir() - .unwrap_or_default() - .join("frontend/.output/public/"); - - if cfg!(debug_assertions) && path.is_dir() { - return path; - } - - let path = PathBuf::from("/usr/share/ffplayout/public/"); - - if path.is_dir() { - return path; - } - - PathBuf::from("./public/") + return public_path; } pub async fn read_log_file(channel_id: &i32, date: &str) -> Result { diff --git a/migrations/00001_create_tables.sql b/migrations/00001_create_tables.sql index 72f64562..4fe57f9b 100644 --- a/migrations/00001_create_tables.sql +++ b/migrations/00001_create_tables.sql @@ -188,7 +188,7 @@ INSERT INTO VALUES ( 'Channel 1', - 'http://127.0.0.1:8787/live/1/stream.m3u8', + 'http://127.0.0.1:8787/1/live/stream.m3u8', 'jpg,jpeg,png', 0 );