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
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"

View File

@ -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"

View File

@ -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"

View File

@ -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<Mutex<ChannelController>>,
) -> Result<actix_files::NamedFile, ServiceError> {
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();

View File

@ -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<PathBuf>,
#[clap(short, env, long, help = "Listen on IP:PORT, like: 127.0.0.1:8787")]
pub listen: Option<String>,
@ -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<String>,
#[clap(long, env, help = "Path to public files, also HLS playlists")]
pub public: Option<String>,
#[clap(long, env, help = "Playlist root path")]
pub playlist_root: Option<String>,
@ -438,7 +435,7 @@ pub async fn run_args(pool: &Pool<Sqlite>) -> 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<Sqlite>) -> 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<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 {
match AdvancedConfig::dump(pool, id).await {
Ok(_) => {

View File

@ -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<dyn std::error::Error>> {
}
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<String, ServiceError> {

View File

@ -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
);