Merge pull request #390 from jb-alvarado/master

make paths optional, fix docs
This commit is contained in:
jb-alvarado 2023-09-13 19:12:18 +00:00 committed by GitHub
commit c2fead5294
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 11 deletions

View File

@ -253,7 +253,7 @@ curl -X GET http://127.0.0.1:8787/api/playlist/1?date=2022-06-20
```BASH
curl -X POST http://127.0.0.1:8787/api/playlist/1/
-H 'Content-Type: application/json' -H 'Authorization: Bearer <TOKEN>'
-- data "{<JSON playlist data>}"
--data "{<JSON playlist data>}"
```
**Generate Playlist**
@ -261,8 +261,18 @@ curl -X POST http://127.0.0.1:8787/api/playlist/1/
A new playlist will be generated and response.
```BASH
curl -X GET http://127.0.0.1:8787/api/playlist/1/generate/2022-06-20
curl -X POST http://127.0.0.1:8787/api/playlist/1/generate/2022-06-20
-H 'Content-Type: application/json' -H 'Authorization: Bearer <TOKEN>'
/// --data '{ "paths": [<list of paths>] }' # <- data is optional
```
Or with template:
```BASH
curl -X POST http://127.0.0.1:8787/api/playlist/1/generate/2023-00-05
-H 'Content-Type: application/json' -H 'Authorization: Bearer <TOKEN>'
--data '{"template": {"sources": [\
{"start": "00:00:00", "duration": "10:00:00", "shuffle": true, "paths": ["path/1", "path/2"]}, \
{"start": "10:00:00", "duration": "14:00:00", "shuffle": false, "paths": ["path/3", "path/4"]}]}}'
```
**Delete Playlist**

View File

@ -1,4 +1,3 @@
## Playlist generation template
It is possible to generate playlists based on templates. A template could look like:
@ -64,8 +63,7 @@ Or through API:
```BASH
curl -X POST http://127.0.0.1:8787/api/playlist/1/generate/2023-00-05
-H 'Content-Type: application/json' -H 'Authorization: Bearer <TOKEN>'
--data '{ "paths": "template": {"sources": [\
--data '{"template": {"sources": [\
{"start": "00:00:00", "duration": "10:00:00", "shuffle": true, "paths": ["path/1", "path/2"]}, \
{"start": "10:00:00", "duration": "14:00:00", "shuffle": false, "paths": ["path/3", "path/4"]}]}}'
```

View File

@ -79,7 +79,7 @@ struct FileObj {
#[derive(Debug, Default, Deserialize, Serialize)]
pub struct PathsObj {
#[serde(default)]
paths: Vec<String>,
paths: Option<Vec<String>>,
template: Option<Template>,
}
@ -750,6 +750,15 @@ pub async fn save_playlist(
/// -H 'Content-Type: application/json' -H 'Authorization: Bearer <TOKEN>'
/// /// --data '{ "paths": [<list of paths>] }' # <- data is optional
/// ```
///
/// Or with template:
/// ```BASH
/// curl -X POST http://127.0.0.1:8787/api/playlist/1/generate/2023-00-05
/// -H 'Content-Type: application/json' -H 'Authorization: Bearer <TOKEN>'
/// --data '{"template": {"sources": [\
/// {"start": "00:00:00", "duration": "10:00:00", "shuffle": true, "paths": ["path/1", "path/2"]}, \
/// {"start": "10:00:00", "duration": "14:00:00", "shuffle": false, "paths": ["path/3", "path/4"]}]}}'
/// ```
#[post("/playlist/{id}/generate/{date}")]
#[has_any_role("Role::Admin", "Role::User", type = "Role")]
pub async fn gen_playlist(
@ -761,15 +770,18 @@ pub async fn gen_playlist(
config.general.generate = Some(vec![params.1.clone()]);
if let Some(obj) = data {
let mut path_list = vec![];
if let Some(paths) = &obj.paths {
let mut path_list = vec![];
for path in &obj.paths {
let (p, _, _) = norm_abs_path(&config.storage.path, path);
for path in paths {
let (p, _, _) = norm_abs_path(&config.storage.path, path);
path_list.push(p);
path_list.push(p);
}
config.storage.paths = path_list;
}
config.storage.paths = path_list;
config.general.template = obj.template.clone();
}