Merge pull request #424 from jb-alvarado/master
preview file from storage path
This commit is contained in:
commit
688bac8c8c
8
Cargo.lock
generated
8
Cargo.lock
generated
@ -1112,7 +1112,7 @@ checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ffplayout"
|
name = "ffplayout"
|
||||||
version = "0.20.0-beta3"
|
version = "0.20.0-beta4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"clap",
|
"clap",
|
||||||
@ -1134,7 +1134,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ffplayout-api"
|
name = "ffplayout-api"
|
||||||
version = "0.20.0-beta3"
|
version = "0.20.0-beta4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-files",
|
"actix-files",
|
||||||
"actix-multipart",
|
"actix-multipart",
|
||||||
@ -1167,7 +1167,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ffplayout-lib"
|
name = "ffplayout-lib"
|
||||||
version = "0.20.0-beta3"
|
version = "0.20.0-beta4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"crossbeam-channel",
|
"crossbeam-channel",
|
||||||
@ -3126,7 +3126,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tests"
|
name = "tests"
|
||||||
version = "0.20.0-beta3"
|
version = "0.20.0-beta4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"crossbeam-channel",
|
"crossbeam-channel",
|
||||||
|
@ -4,7 +4,7 @@ default-members = ["ffplayout-api", "ffplayout-engine", "tests"]
|
|||||||
resolver = "2"
|
resolver = "2"
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "0.20.0-beta3"
|
version = "0.20.0-beta4"
|
||||||
license = "GPL-3.0"
|
license = "GPL-3.0"
|
||||||
repository = "https://github.com/ffplayout/ffplayout"
|
repository = "https://github.com/ffplayout/ffplayout"
|
||||||
authors = ["Jonathan Baecker <jonbae77@gmail.com>"]
|
authors = ["Jonathan Baecker <jonbae77@gmail.com>"]
|
||||||
|
@ -328,6 +328,14 @@ curl -X PUT http://127.0.0.1:8787/api/file/1/upload/ -H 'Authorization: Bearer <
|
|||||||
-F "file=@file.mp4"
|
-F "file=@file.mp4"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**Get File**
|
||||||
|
|
||||||
|
Can be used for preview video files
|
||||||
|
|
||||||
|
```BASH
|
||||||
|
curl -X GET http://127.0.0.1:8787/file/1/path/to/file.mp4
|
||||||
|
```
|
||||||
|
|
||||||
**Import playlist**
|
**Import playlist**
|
||||||
|
|
||||||
Import text/m3u file and convert it to a playlist
|
Import text/m3u file and convert it to a playlist
|
||||||
|
@ -10,9 +10,18 @@
|
|||||||
/// `{id}` represent the channel id, and at default is 1.
|
/// `{id}` represent the channel id, and at default is 1.
|
||||||
use std::{collections::HashMap, env, fs, path::PathBuf};
|
use std::{collections::HashMap, env, fs, path::PathBuf};
|
||||||
|
|
||||||
|
use actix_files;
|
||||||
use actix_multipart::Multipart;
|
use actix_multipart::Multipart;
|
||||||
use actix_web::{delete, get, http::StatusCode, patch, post, put, web, HttpResponse, Responder};
|
use actix_web::{
|
||||||
|
delete, get,
|
||||||
|
http::{
|
||||||
|
header::{ContentDisposition, DispositionType},
|
||||||
|
StatusCode,
|
||||||
|
},
|
||||||
|
patch, post, put, web, HttpRequest, HttpResponse, Responder,
|
||||||
|
};
|
||||||
use actix_web_grants::{permissions::AuthDetails, proc_macro::has_any_role};
|
use actix_web_grants::{permissions::AuthDetails, proc_macro::has_any_role};
|
||||||
|
|
||||||
use argon2::{
|
use argon2::{
|
||||||
password_hash::{rand_core::OsRng, PasswordHash, SaltString},
|
password_hash::{rand_core::OsRng, PasswordHash, SaltString},
|
||||||
Argon2, PasswordHasher, PasswordVerifier,
|
Argon2, PasswordHasher, PasswordVerifier,
|
||||||
@ -785,7 +794,7 @@ pub async fn gen_playlist(
|
|||||||
config.general.template = obj.template.clone();
|
config.general.template = obj.template.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
match generate_playlist(config, channel.name).await {
|
match generate_playlist(config.to_owned(), channel.name).await {
|
||||||
Ok(playlist) => Ok(web::Json(playlist)),
|
Ok(playlist) => Ok(web::Json(playlist)),
|
||||||
Err(e) => Err(e),
|
Err(e) => Err(e),
|
||||||
}
|
}
|
||||||
@ -919,6 +928,33 @@ async fn save_file(
|
|||||||
upload(&pool.into_inner(), *id, payload, &obj.path, false).await
|
upload(&pool.into_inner(), *id, payload, &obj.path, false).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// **Get File**
|
||||||
|
///
|
||||||
|
/// Can be used for preview video files
|
||||||
|
///
|
||||||
|
/// ```BASH
|
||||||
|
/// curl -X GET http://127.0.0.1:8787/file/1/path/to/file.mp4
|
||||||
|
/// ```
|
||||||
|
#[get("/file/{id}/{filename:.*}")]
|
||||||
|
async fn get_file(
|
||||||
|
pool: web::Data<Pool<Sqlite>>,
|
||||||
|
req: HttpRequest,
|
||||||
|
) -> Result<actix_files::NamedFile, ServiceError> {
|
||||||
|
let id: i32 = req.match_info().query("id").parse()?;
|
||||||
|
let (config, _) = playout_config(&pool.into_inner(), &id).await?;
|
||||||
|
let storage_path = config.storage.path;
|
||||||
|
let file_path = req.match_info().query("filename");
|
||||||
|
let (path, _, _) = norm_abs_path(&storage_path, file_path);
|
||||||
|
let file = actix_files::NamedFile::open(path)?;
|
||||||
|
|
||||||
|
Ok(file
|
||||||
|
.use_last_modified(true)
|
||||||
|
.set_content_disposition(ContentDisposition {
|
||||||
|
disposition: DispositionType::Attachment,
|
||||||
|
parameters: vec![],
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
/// **Import playlist**
|
/// **Import playlist**
|
||||||
///
|
///
|
||||||
/// Import text/m3u file and convert it to a playlist
|
/// Import text/m3u file and convert it to a playlist
|
||||||
|
@ -12,17 +12,7 @@ pub mod api;
|
|||||||
pub mod db;
|
pub mod db;
|
||||||
pub mod utils;
|
pub mod utils;
|
||||||
|
|
||||||
use api::{
|
use api::{auth, routes::*};
|
||||||
auth,
|
|
||||||
routes::{
|
|
||||||
add_channel, add_dir, add_preset, add_user, control_playout, del_playlist, delete_preset,
|
|
||||||
file_browser, gen_playlist, get_all_channels, get_channel, get_log, get_playlist,
|
|
||||||
get_playout_config, get_presets, get_program, get_user, import_playlist, login,
|
|
||||||
media_current, media_last, media_next, move_rename, patch_channel, process_control, remove,
|
|
||||||
remove_channel, save_file, save_playlist, send_text_message, update_playout_config,
|
|
||||||
update_preset, update_user,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
use db::{db_pool, models::LoginUser};
|
use db::{db_pool, models::LoginUser};
|
||||||
use utils::{args_parse::Args, control::ProcessControl, db_path, init_config, run_args, Role};
|
use utils::{args_parse::Args, control::ProcessControl, db_path, init_config, run_args, Role};
|
||||||
|
|
||||||
@ -141,6 +131,7 @@ async fn main() -> std::io::Result<()> {
|
|||||||
.service(import_playlist)
|
.service(import_playlist)
|
||||||
.service(get_program),
|
.service(get_program),
|
||||||
)
|
)
|
||||||
|
.service(get_file)
|
||||||
.service(Files::new("/", public_path()).index_file("index.html"))
|
.service(Files::new("/", public_path()).index_file("index.html"))
|
||||||
})
|
})
|
||||||
.bind((addr, port))?
|
.bind((addr, port))?
|
||||||
|
@ -64,6 +64,12 @@ impl From<std::io::Error> for ServiceError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<std::num::ParseIntError> for ServiceError {
|
||||||
|
fn from(err: std::num::ParseIntError) -> ServiceError {
|
||||||
|
ServiceError::BadRequest(err.to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<actix_web::error::BlockingError> for ServiceError {
|
impl From<actix_web::error::BlockingError> for ServiceError {
|
||||||
fn from(err: actix_web::error::BlockingError) -> ServiceError {
|
fn from(err: actix_web::error::BlockingError) -> ServiceError {
|
||||||
ServiceError::BadRequest(err.to_string())
|
ServiceError::BadRequest(err.to_string())
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 50bee93c8555b14181864a654239f7e68c50cafb
|
Subproject commit d00ffcabeaafc98169e6fe3ad163e226460048f4
|
Loading…
x
Reference in New Issue
Block a user