no rpc logging, add default config, better naming, code cleanup

This commit is contained in:
jb-alvarado 2022-07-19 11:11:23 +02:00
parent a7d0a43fdd
commit 94816903c3
10 changed files with 44 additions and 52 deletions

2
Cargo.lock generated
View File

@ -1056,7 +1056,7 @@ dependencies = [
[[package]]
name = "ffplayout-lib"
version = "0.10.4"
version = "0.10.5"
dependencies = [
"chrono 0.4.20-beta.1",
"crossbeam-channel 0.5.5",

View File

@ -66,7 +66,7 @@ curl -X GET http://127.0.0.1:8000/api/channel/1 -H "Authorization: Bearer <TOKEN
```JSON
{
"id": 1,
"channel_name": "Channel 1",
"name": "Channel 1",
"preview_url": "http://localhost/live/preview.m3u8",
"config_path": "/etc/ffplayout/ffplayout.yml",
"extra_extensions": "jpg,jpeg,png",
@ -85,7 +85,7 @@ curl -X GET http://127.0.0.1:8000/api/channels -H "Authorization: Bearer <TOKEN>
```BASH
curl -X PATCH http://127.0.0.1:8000/api/channel/1 -H "Content-Type: application/json" \
-d '{ "id": 1, "channel_name": "Channel 1", "preview_url": "http://localhost/live/stream.m3u8", \
-d '{ "id": 1, "name": "Channel 1", "preview_url": "http://localhost/live/stream.m3u8", \
"config_path": "/etc/ffplayout/ffplayout.yml", "extra_extensions": "jpg,jpeg,png", "timezone": "Europe/Berlin"}' \
-H "Authorization: Bearer <TOKEN>"
```
@ -94,7 +94,7 @@ curl -X PATCH http://127.0.0.1:8000/api/channel/1 -H "Content-Type: application/
```BASH
curl -X POST http://127.0.0.1:8000/api/channel/ -H "Content-Type: application/json" \
-d '{ "channel_name": "Channel 2", "preview_url": "http://localhost/live/channel2.m3u8", \
-d '{ "name": "Channel 2", "preview_url": "http://localhost/live/channel2.m3u8", \
"config_path": "/etc/ffplayout/channel2.yml", "extra_extensions": "jpg,jpeg,png",
"timezone": "Europe/Berlin", "service": "ffplayout@channel2.service" }' \
-H "Authorization: Bearer <TOKEN>"

View File

@ -18,39 +18,27 @@ pub async fn create_channel(target_channel: Channel) -> Result<Channel, ServiceE
return Err(ServiceError::BadRequest("Bad config path!".to_string()));
}
if let Ok(source_channel) = db_get_channel(&1).await {
if fs::copy(&source_channel.config_path, &target_channel.config_path).is_ok() {
match db_add_channel(target_channel).await {
Ok(c) => {
if let Err(e) = control_service(c.id, "enable").await {
return Err(e);
}
return Ok(c);
}
Err(e) => {
return Err(ServiceError::Conflict(e.to_string()));
}
};
}
}
fs::copy(
"/usr/share/ffplayout/ffplayout.yml.orig",
&target_channel.config_path,
)?;
Err(ServiceError::InternalServerError)
let new_channel = db_add_channel(target_channel).await?;
control_service(new_channel.id, "enable").await?;
Ok(new_channel)
}
pub async fn delete_channel(id: i64) -> Result<(), ServiceError> {
if let Ok(channel) = db_get_channel(&id).await {
if control_service(channel.id, "stop").await.is_ok()
&& control_service(channel.id, "disable").await.is_ok()
{
if let Err(e) = fs::remove_file(channel.config_path) {
error!("{e}");
};
match db_delete_channel(&id).await {
Ok(_) => return Ok(()),
Err(e) => return Err(ServiceError::Conflict(e.to_string())),
}
}
}
let channel = db_get_channel(&id).await?;
control_service(channel.id, "stop").await?;
control_service(channel.id, "disable").await?;
Err(ServiceError::InternalServerError)
if let Err(e) = fs::remove_file(channel.config_path) {
error!("{e}");
};
db_delete_channel(&id).await?;
Ok(())
}

View File

@ -36,13 +36,13 @@ async fn create_schema() -> Result<SqliteQueryResult, sqlx::Error> {
CREATE TABLE IF NOT EXISTS channels
(
id INTEGER PRIMARY KEY AUTOINCREMENT,
channel_name TEXT NOT NULL,
name TEXT NOT NULL,
preview_url TEXT NOT NULL,
config_path TEXT NOT NULL,
extra_extensions TEXT NOT NULL,
timezone TEXT NOT NULL,
service TEXT NOT NULL,
UNIQUE(channel_name, service)
UNIQUE(name, service)
);
CREATE TABLE IF NOT EXISTS presets
(
@ -111,7 +111,7 @@ pub async fn db_init(domain: Option<String>) -> Result<&'static str, Box<dyn std
SELECT RAISE(FAIL, 'Database is already initialized!');
END;
INSERT INTO global(secret) VALUES($1);
INSERT INTO channels(channel_name, preview_url, config_path, extra_extensions, timezone, service)
INSERT INTO channels(name, preview_url, config_path, extra_extensions, timezone, service)
VALUES('Channel 1', $2, '/etc/ffplayout/ffplayout.yml', 'jpg,jpeg,png', 'UTC', 'ffplayout.service');
INSERT INTO roles(name) VALUES('admin'), ('user'), ('guest');
INSERT INTO presets(name, text, x, y, fontsize, line_spacing, fontcolor, box, boxcolor, boxborderw, alpha, channel_id)
@ -158,7 +158,7 @@ pub async fn db_get_channel(id: &i64) -> Result<Channel, sqlx::Error> {
pub async fn db_get_all_channels() -> Result<Vec<Channel>, sqlx::Error> {
let conn = db_connection().await?;
let query = "SELECT * FROM settings";
let query = "SELECT * FROM channels";
let result: Vec<Channel> = sqlx::query_as(query).fetch_all(&conn).await?;
conn.close().await;
@ -171,13 +171,14 @@ pub async fn db_update_channel(
) -> Result<SqliteQueryResult, sqlx::Error> {
let conn = db_connection().await?;
let query = "UPDATE channels SET channel_name = $2, preview_url = $3, config_path = $4, extra_extensions = $5 WHERE id = $1";
let query = "UPDATE channels SET name = $2, preview_url = $3, config_path = $4, extra_extensions = $5, timezone = $6 WHERE id = $1";
let result: SqliteQueryResult = sqlx::query(query)
.bind(id)
.bind(channel.channel_name.clone())
.bind(channel.preview_url.clone())
.bind(channel.config_path.clone())
.bind(channel.extra_extensions.clone())
.bind(channel.name)
.bind(channel.preview_url)
.bind(channel.config_path)
.bind(channel.extra_extensions)
.bind(channel.timezone)
.execute(&conn)
.await?;
conn.close().await;
@ -188,9 +189,9 @@ pub async fn db_update_channel(
pub async fn db_add_channel(channel: Channel) -> Result<Channel, sqlx::Error> {
let conn = db_connection().await?;
let query = "INSERT INTO channels (channel_name, preview_url, config_path, extra_extensions, timezone, service) VALUES($1, $2, $3, $4, $5, $6)";
let query = "INSERT INTO channels (name, preview_url, config_path, extra_extensions, timezone, service) VALUES($1, $2, $3, $4, $5, $6)";
let result = sqlx::query(query)
.bind(channel.channel_name)
.bind(channel.name)
.bind(channel.preview_url)
.bind(channel.config_path)
.bind(channel.extra_extensions)

View File

@ -62,7 +62,7 @@ pub struct TextPreset {
pub struct Channel {
#[serde(skip_deserializing)]
pub id: i64,
pub channel_name: String,
pub name: String,
pub preview_url: String,
pub config_path: String,
pub extra_extensions: String,

View File

@ -75,10 +75,10 @@ pub async fn write_playlist(id: i64, json_data: JsonPlaylist) -> Result<String,
}
pub async fn generate_playlist(id: i64, date: String) -> Result<JsonPlaylist, ServiceError> {
let (mut config, settings) = playout_config(&id).await?;
let (mut config, channel) = playout_config(&id).await?;
config.general.generate = Some(vec![date.clone()]);
match playlist_generator(&config, Some(settings.channel_name)) {
match playlist_generator(&config, Some(channel.name)) {
Ok(playlists) => {
if !playlists.is_empty() {
Ok(playlists[0].clone())

View File

@ -231,7 +231,7 @@ async fn add_user(data: web::Json<User>) -> Result<impl Responder, ServiceError>
/// ```JSON
/// {
/// "id": 1,
/// "channel_name": "Channel 1",
/// "name": "Channel 1",
/// "preview_url": "http://localhost/live/preview.m3u8",
/// "config_path": "/etc/ffplayout/ffplayout.yml",
/// "extra_extensions": "jpg,jpeg,png",
@ -268,7 +268,7 @@ async fn get_all_channels() -> Result<impl Responder, ServiceError> {
///
/// ```BASH
/// curl -X PATCH http://127.0.0.1:8000/api/channel/1 -H "Content-Type: application/json" \
/// -d '{ "id": 1, "channel_name": "Channel 1", "preview_url": "http://localhost/live/stream.m3u8", \
/// -d '{ "id": 1, "name": "Channel 1", "preview_url": "http://localhost/live/stream.m3u8", \
/// "config_path": "/etc/ffplayout/ffplayout.yml", "extra_extensions": "jpg,jpeg,png", "timezone": "Europe/Berlin"}' \
/// -H "Authorization: Bearer <TOKEN>"
/// ```
@ -289,7 +289,7 @@ async fn patch_channel(
///
/// ```BASH
/// curl -X POST http://127.0.0.1:8000/api/channel/ -H "Content-Type: application/json" \
/// -d '{ "channel_name": "Channel 2", "preview_url": "http://localhost/live/channel2.m3u8", \
/// -d '{ "name": "Channel 2", "preview_url": "http://localhost/live/channel2.m3u8", \
/// "config_path": "/etc/ffplayout/channel2.yml", "extra_extensions": "jpg,jpeg,png",
/// "timezone": "Europe/Berlin", "service": "ffplayout@channel2.service" }' \
/// -H "Authorization: Bearer <TOKEN>"

View File

@ -52,6 +52,7 @@ assets = [
["../assets/11-ffplayout", "/etc/sudoers.d/", "644"],
["../assets/ffplayout.yml", "/etc/ffplayout/", "644"],
["../assets/logo.png", "/usr/share/ffplayout/", "644"],
["../assets/ffplayout.yml", "/usr/share/ffplayout/ffplayout.yml.orig", "644"],
["../README.md", "/usr/share/doc/ffplayout/README", "644"],
]
maintainer-scripts = "../debian/"
@ -72,6 +73,7 @@ assets = [
{ source = "../README.md", dest = "/usr/share/doc/ffplayout/README", mode = "644", doc = true },
{ source = "../LICENSE", dest = "/usr/share/doc/ffplayout/LICENSE", mode = "644" },
{ source = "../assets/logo.png", dest = "/usr/share/ffplayout/logo.png", mode = "644" },
{ source = "../assets/ffplayout.yml", dest = "/usr/share/ffplayout/ffplayout.yml.orig", mode = "644" },
{ source = "../debian/postinst", dest = "/usr/share/ffplayout/postinst", mode = "755" },
]
auto-req = "no"

View File

@ -4,7 +4,7 @@ description = "Library for ffplayout"
license = "GPL-3.0"
authors = ["Jonathan Baecker jonbae77@gmail.com"]
readme = "README.md"
version = "0.10.4"
version = "0.10.5"
edition = "2021"
[dependencies]

View File

@ -188,6 +188,7 @@ pub fn init_logging(
.add_filter_ignore_str("hyper")
.add_filter_ignore_str("sqlx")
.add_filter_ignore_str("reqwest")
.add_filter_ignore_str("rpc")
.set_level_padding(LevelPadding::Left)
.set_time_level(time_level)
.clone();