fix log path, update api doc

This commit is contained in:
jb-alvarado 2024-07-01 07:36:32 +02:00
parent fd8562dd52
commit c8f1b63a9b
3 changed files with 36 additions and 27 deletions

View File

@ -122,6 +122,21 @@ curl -X DELETE http://127.0.0.1:8787/api/channel/2 -H "Authorization: Bearer <TO
#### ffplayout Config
**Get Advanced Config**
```BASH
curl -X GET http://127.0.0.1:8787/api/playout/advanced/1 -H 'Authorization: Bearer <TOKEN>'
```
Response is a JSON object
**Update Advanced Config**
```BASH
curl -X PUT http://127.0.0.1:8787/api/playout/advanced/1 -H "Content-Type: application/json" \
-d { <CONFIG DATA> } -H 'Authorization: Bearer <TOKEN>'
```
**Get Config**
```BASH
@ -159,7 +174,7 @@ curl -X PUT http://127.0.0.1:8787/api/presets/1 -H 'Content-Type: application/js
**Add new Preset**
```BASH
curl -X POST http://127.0.0.1:8787/api/presets/ -H 'Content-Type: application/json' \
curl -X POST http://127.0.0.1:8787/api/presets/1/ -H 'Content-Type: application/json' \
-d '{ "name": "<PRESET NAME>", "text": "TEXT>", "x": "<X>", "y": "<Y>", "fontsize": 24, "line_spacing": 4, "fontcolor": "#ffffff", "box": 1, "boxcolor": "#000000", "boxborderw": 4, "alpha": 1.0, "channel_id": 1 }' \
-H 'Authorization: Bearer <TOKEN>'
```
@ -282,10 +297,10 @@ curl -X DELETE http://127.0.0.1:8787/api/playlist/1/2022-06-20
### Log file
**Read Log Life**
**Read Log File**
```BASH
curl -X GET http://127.0.0.1:8787/api/log/1
curl -X GET http://127.0.0.1:8787/api/log/1?date=2022-06-20
-H 'Content-Type: application/json' -H 'Authorization: Bearer <TOKEN>'
```

View File

@ -572,7 +572,7 @@ async fn get_advanced_config(
Ok(web::Json(config))
}
/// **Update Config**
/// **Update Advanced Config**
///
/// ```BASH
/// curl -X PUT http://127.0.0.1:8787/api/playout/advanced/1 -H "Content-Type: application/json" \
@ -1087,10 +1087,10 @@ pub async fn del_playlist(
/// ### Log file
///
/// **Read Log Life**
/// **Read Log File**
///
/// ```BASH
/// curl -X GET http://127.0.0.1:8787/api/log/1
/// curl -X GET http://127.0.0.1:8787/api/log/1?date=2022-06-20
/// -H 'Content-Type: application/json' -H 'Authorization: Bearer <TOKEN>'
/// ```
#[get("/log/{id}")]

View File

@ -1,6 +1,5 @@
use std::{
env, fmt,
fs::{self, metadata},
net::TcpListener,
path::{Path, PathBuf},
};
@ -11,6 +10,7 @@ use log::*;
use path_clean::PathClean;
use rand::Rng;
use regex::Regex;
use tokio::fs;
use serde::{
de::{self, Visitor},
@ -207,29 +207,23 @@ pub fn public_path() -> PathBuf {
}
pub async fn read_log_file(channel_id: &i32, date: &str) -> Result<String, ServiceError> {
let mut date_str = "".to_string();
if !date.is_empty() {
date_str.push('.');
date_str.push_str(date);
}
let mut log_path = log_file_path()
.join(format!("ffplayout_{channel_id}.log"))
.display()
.to_string();
log_path.push_str(&date_str);
let file_size = metadata(&log_path)?.len() as f64;
let file_content = if file_size > 5000000.0 {
error!("Log file to big: {}", sizeof_fmt(file_size));
format!("The log file is larger ({}) than the hard limit of 5MB, the probability is very high that something is wrong with the playout. Check this on the server with `less {log_path}`.", sizeof_fmt(file_size))
let date_str = if date.is_empty() {
"".to_string()
} else {
fs::read_to_string(log_path)?
format!("_{date}")
};
Ok(file_content)
let log_path = log_file_path().join(format!("ffplayout_{channel_id}{date_str}.log"));
let file_size = fs::metadata(&log_path).await?.len() as f64;
let log_content = if file_size > 5000000.0 {
error!("Log file to big: {}", sizeof_fmt(file_size));
format!("The log file is larger ({}) than the hard limit of 5MB, the probability is very high that something is wrong with the playout. Check this on the server with `less {log_path:?}`.", sizeof_fmt(file_size))
} else {
fs::read_to_string(log_path).await?
};
Ok(log_content)
}
/// get human readable file size