Merge pull request #424 from jb-alvarado/master

preview file from storage path
This commit is contained in:
jb-alvarado 2023-10-30 23:23:07 +01:00 committed by GitHub
commit 688bac8c8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 60 additions and 19 deletions

8
Cargo.lock generated
View File

@ -1112,7 +1112,7 @@ checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5"
[[package]]
name = "ffplayout"
version = "0.20.0-beta3"
version = "0.20.0-beta4"
dependencies = [
"chrono",
"clap",
@ -1134,7 +1134,7 @@ dependencies = [
[[package]]
name = "ffplayout-api"
version = "0.20.0-beta3"
version = "0.20.0-beta4"
dependencies = [
"actix-files",
"actix-multipart",
@ -1167,7 +1167,7 @@ dependencies = [
[[package]]
name = "ffplayout-lib"
version = "0.20.0-beta3"
version = "0.20.0-beta4"
dependencies = [
"chrono",
"crossbeam-channel",
@ -3126,7 +3126,7 @@ dependencies = [
[[package]]
name = "tests"
version = "0.20.0-beta3"
version = "0.20.0-beta4"
dependencies = [
"chrono",
"crossbeam-channel",

View File

@ -4,7 +4,7 @@ default-members = ["ffplayout-api", "ffplayout-engine", "tests"]
resolver = "2"
[workspace.package]
version = "0.20.0-beta3"
version = "0.20.0-beta4"
license = "GPL-3.0"
repository = "https://github.com/ffplayout/ffplayout"
authors = ["Jonathan Baecker <jonbae77@gmail.com>"]

View File

@ -328,6 +328,14 @@ curl -X PUT http://127.0.0.1:8787/api/file/1/upload/ -H 'Authorization: Bearer <
-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 text/m3u file and convert it to a playlist

View File

@ -10,9 +10,18 @@
/// `{id}` represent the channel id, and at default is 1.
use std::{collections::HashMap, env, fs, path::PathBuf};
use actix_files;
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 argon2::{
password_hash::{rand_core::OsRng, PasswordHash, SaltString},
Argon2, PasswordHasher, PasswordVerifier,
@ -785,7 +794,7 @@ pub async fn gen_playlist(
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)),
Err(e) => Err(e),
}
@ -919,6 +928,33 @@ async fn save_file(
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 text/m3u file and convert it to a playlist

View File

@ -12,17 +12,7 @@ pub mod api;
pub mod db;
pub mod utils;
use api::{
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 api::{auth, routes::*};
use db::{db_pool, models::LoginUser};
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(get_program),
)
.service(get_file)
.service(Files::new("/", public_path()).index_file("index.html"))
})
.bind((addr, port))?

View File

@ -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 {
fn from(err: actix_web::error::BlockingError) -> ServiceError {
ServiceError::BadRequest(err.to_string())

@ -1 +1 @@
Subproject commit 50bee93c8555b14181864a654239f7e68c50cafb
Subproject commit d00ffcabeaafc98169e6fe3ad163e226460048f4