unify public and public_root path, change order from preview url

This commit is contained in:
jb-alvarado 2024-09-10 08:16:20 +02:00
parent fc560c774d
commit bc01b2de1c
7 changed files with 31 additions and 55 deletions

View File

@ -1,6 +1,6 @@
FROM alpine:latest FROM alpine:latest
ARG FFPLAYOUT_VERSION=0.24.0-beta2 ARG FFPLAYOUT_VERSION=0.24.0-beta4
ARG SHARED_STORAGE=false ARG SHARED_STORAGE=false
ENV DB=/db ENV DB=/db
@ -12,7 +12,7 @@ COPY <<-EOT /run.sh
#!/bin/sh #!/bin/sh
if [ ! -f /db/ffplayout.db ]; then 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 fi
/usr/bin/ffplayout -l "0.0.0.0:8787" /usr/bin/ffplayout -l "0.0.0.0:8787"

View File

@ -1,6 +1,6 @@
FROM alpine:latest FROM alpine:latest
ARG FFPLAYOUT_VERSION=0.24.0-beta2 ARG FFPLAYOUT_VERSION=0.24.0-beta4
ARG SHARED_STORAGE=false ARG SHARED_STORAGE=false
ENV DB=/db ENV DB=/db
@ -14,7 +14,7 @@ COPY <<-EOT /run.sh
#!/bin/sh #!/bin/sh
if [ ! -f /db/ffplayout.db ]; then 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 fi
/usr/bin/ffplayout -l "0.0.0.0:8787" /usr/bin/ffplayout -l "0.0.0.0:8787"

View File

@ -1,6 +1,6 @@
FROM nvidia/cuda:12.5.0-runtime-rockylinux9 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 ARG SHARED_STORAGE=false
ENV DB=/db ENV DB=/db
@ -204,7 +204,7 @@ COPY <<-EOT /run.sh
#!/bin/sh #!/bin/sh
if [ ! -f /db/ffplayout.db ]; then 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 fi
/usr/bin/ffplayout -l "0.0.0.0:8787" /usr/bin/ffplayout -l "0.0.0.0:8787"

View File

@ -52,10 +52,10 @@ use crate::utils::{
playlist::{delete_playlist, generate_playlist, read_playlist, write_playlist}, playlist::{delete_playlist, generate_playlist, read_playlist, write_playlist},
public_path, read_log_file, system, TextFilter, public_path, read_log_file, system, TextFilter,
}; };
use crate::vec_strings;
use crate::{ use crate::{
api::auth::{create_jwt, Claims}, api::auth::{create_jwt, Claims},
utils::advanced_config::AdvancedConfig, utils::advanced_config::AdvancedConfig,
vec_strings,
}; };
use crate::{ use crate::{
db::{ db::{
@ -1309,24 +1309,21 @@ async fn get_file(
/// Can be used for HLS Playlist and other static files in public folder /// Can be used for HLS Playlist and other static files in public folder
/// ///
/// ```BASH /// ```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( async fn get_public(
path: web::Path<(String, i32, String)>, path: web::Path<(i32, String, String)>,
controllers: web::Data<Mutex<ChannelController>>, controllers: web::Data<Mutex<ChannelController>>,
) -> Result<actix_files::NamedFile, ServiceError> { ) -> Result<actix_files::NamedFile, ServiceError> {
let (public, id, file_stem) = path.into_inner(); let (id, public, file_stem) = path.into_inner();
let public_path = public_path();
let absolute_path = if file_stem.ends_with(".ts") || file_stem.ends_with(".m3u8") { let absolute_path = if file_stem.ends_with(".ts") || file_stem.ends_with(".m3u8") {
let manager = controllers.lock().unwrap().get(id).unwrap(); let manager = controllers.lock().unwrap().get(id).unwrap();
let config = manager.config.lock().unwrap(); let config = manager.config.lock().unwrap();
config.channel.hls_path.join(public) config.channel.hls_path.join(public)
} else if public_path.is_absolute() {
public_path.to_path_buf()
} else { } else {
env::current_dir()?.join(public_path) public_path()
} }
.clean(); .clean();

View File

@ -86,9 +86,6 @@ pub struct Args {
#[clap(long, help = "List available channel ids")] #[clap(long, help = "List available channel ids")]
pub list_channels: bool, pub list_channels: bool,
#[clap(long, env, help = "path to public files")]
pub public: Option<PathBuf>,
#[clap(short, env, long, help = "Listen on IP:PORT, like: 127.0.0.1:8787")] #[clap(short, env, long, help = "Listen on IP:PORT, like: 127.0.0.1:8787")]
pub listen: Option<String>, pub listen: Option<String>,
@ -123,8 +120,8 @@ pub struct Args {
#[clap(long, env, help = "Log to console")] #[clap(long, env, help = "Log to console")]
pub log_to_console: bool, pub log_to_console: bool,
#[clap(long, env, help = "Public (HLS) output path")] #[clap(long, env, help = "Path to public files, also HLS playlists")]
pub public_root: Option<String>, pub public: Option<String>,
#[clap(long, env, help = "Playlist root path")] #[clap(long, env, help = "Playlist root path")]
pub playlist_root: Option<String>, pub playlist_root: Option<String>,
@ -438,7 +435,7 @@ pub async fn run_args(pool: &Pool<Sqlite>) -> Result<(), i32> {
if !args.init if !args.init
&& args.storage_root.is_some() && args.storage_root.is_some()
&& args.playlist_root.is_some() && args.playlist_root.is_some()
&& args.public_root.is_some() && args.public.is_some()
&& args.log_path.is_some() && args.log_path.is_some()
{ {
error_code = 0; error_code = 0;
@ -448,7 +445,7 @@ pub async fn run_args(pool: &Pool<Sqlite>) -> Result<(), i32> {
secret: None, secret: None,
logging_path: args.log_path.unwrap().to_string_lossy().to_string(), logging_path: args.log_path.unwrap().to_string_lossy().to_string(),
playlist_root: args.playlist_root.unwrap(), playlist_root: args.playlist_root.unwrap(),
public_root: args.public_root.unwrap(), public_root: args.public.unwrap(),
storage_root: args.storage_root.unwrap(), storage_root: args.storage_root.unwrap(),
shared_storage: args.shared_storage, shared_storage: args.shared_storage,
}; };
@ -523,19 +520,6 @@ pub async fn run_args(pool: &Pool<Sqlite>) -> 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 { if let Some(id) = ARGS.dump_advanced {
match AdvancedConfig::dump(pool, id).await { match AdvancedConfig::dump(pool, id).await {
Ok(_) => { Ok(_) => {

View File

@ -30,6 +30,7 @@ pub mod playlist;
pub mod system; pub mod system;
pub mod task_runner; pub mod task_runner;
use crate::db::models::GlobalSettings;
use crate::player::utils::time_to_sec; use crate::player::utils::time_to_sec;
use crate::utils::{errors::ServiceError, logging::log_file_path}; use crate::utils::{errors::ServiceError, logging::log_file_path};
use crate::ARGS; use crate::ARGS;
@ -195,34 +196,28 @@ pub fn db_path() -> Result<&'static str, Box<dyn std::error::Error>> {
} }
pub fn public_path() -> PathBuf { 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. // When public path is set as argument use this path for serving static files.
// Works only when feature embed_frontend is not set. // 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() public.to_path_buf()
} else { } else {
env::current_dir().unwrap_or_default().join(public) env::current_dir().unwrap_or_default().join(public)
} }
.clean(); .clean();
} else if cfg!(debug_assertions) && dev_path.is_dir() {
return absolute_path; public_path = dev_path;
} }
let path = env::current_dir() return public_path;
.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/")
} }
pub async fn read_log_file(channel_id: &i32, date: &str) -> Result<String, ServiceError> { pub async fn read_log_file(channel_id: &i32, date: &str) -> Result<String, ServiceError> {

View File

@ -188,7 +188,7 @@ INSERT INTO
VALUES VALUES
( (
'Channel 1', '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', 'jpg,jpeg,png',
0 0
); );