create preset set on channel creation, only select/insert/update presets that belongs to channel
This commit is contained in:
parent
537efc6d97
commit
9b1e75b62a
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -1210,7 +1210,7 @@ checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a"
|
||||
|
||||
[[package]]
|
||||
name = "ffplayout"
|
||||
version = "0.24.0-beta2"
|
||||
version = "0.24.0-beta3"
|
||||
dependencies = [
|
||||
"actix-files",
|
||||
"actix-multipart",
|
||||
@ -3540,7 +3540,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tests"
|
||||
version = "0.24.0-beta2"
|
||||
version = "0.24.0-beta3"
|
||||
dependencies = [
|
||||
"actix-rt",
|
||||
"actix-test",
|
||||
|
@ -4,7 +4,7 @@ default-members = ["ffplayout", "tests"]
|
||||
resolver = "2"
|
||||
|
||||
[workspace.package]
|
||||
version = "0.24.0-beta2"
|
||||
version = "0.24.0-beta3"
|
||||
license = "GPL-3.0"
|
||||
repository = "https://github.com/ffplayout/ffplayout"
|
||||
authors = ["Jonathan Baecker <jonbae77@gmail.com>"]
|
||||
|
@ -670,7 +670,7 @@ async fn update_playout_config(
|
||||
/// **Get all Presets**
|
||||
///
|
||||
/// ```BASH
|
||||
/// curl -X GET http://127.0.0.1:8787/api/presets/ -H 'Content-Type: application/json' \
|
||||
/// curl -X GET http://127.0.0.1:8787/api/presets/1 -H 'Content-Type: application/json' \
|
||||
/// -H 'Authorization: Bearer <TOKEN>'
|
||||
/// ```
|
||||
#[get("/presets/{id}")]
|
||||
@ -699,19 +699,21 @@ async fn get_presets(
|
||||
/// -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>'
|
||||
/// ```
|
||||
#[put("/presets/{id}")]
|
||||
#[put("/presets/{channel}/{id}")]
|
||||
#[protect(
|
||||
any("Role::GlobalAdmin", "Role::ChannelAdmin", "Role::User"),
|
||||
ty = "Role",
|
||||
expr = "user.channels.contains(&*id) || role.has_authority(&Role::GlobalAdmin)"
|
||||
expr = "user.channels.contains(&path.0) || role.has_authority(&Role::GlobalAdmin)"
|
||||
)]
|
||||
async fn update_preset(
|
||||
pool: web::Data<Pool<Sqlite>>,
|
||||
id: web::Path<i32>,
|
||||
path: web::Path<(i32, i32)>,
|
||||
data: web::Json<TextPreset>,
|
||||
role: AuthDetails<Role>,
|
||||
user: web::ReqData<UserMeta>,
|
||||
) -> Result<impl Responder, ServiceError> {
|
||||
let (_, id) = path.into_inner();
|
||||
|
||||
if handles::update_preset(&pool, &id, data.into_inner())
|
||||
.await
|
||||
.is_ok()
|
||||
@ -755,21 +757,23 @@ async fn add_preset(
|
||||
/// **Delete Preset**
|
||||
///
|
||||
/// ```BASH
|
||||
/// curl -X DELETE http://127.0.0.1:8787/api/presets/1 -H 'Content-Type: application/json' \
|
||||
/// curl -X DELETE http://127.0.0.1:8787/api/presets/1/1 -H 'Content-Type: application/json' \
|
||||
/// -H 'Authorization: Bearer <TOKEN>'
|
||||
/// ```
|
||||
#[delete("/presets/{id}")]
|
||||
#[delete("/presets/{channel}/{id}")]
|
||||
#[protect(
|
||||
any("Role::GlobalAdmin", "Role::ChannelAdmin", "Role::User"),
|
||||
ty = "Role",
|
||||
expr = "user.channels.contains(&*id) || role.has_authority(&Role::GlobalAdmin)"
|
||||
expr = "user.channels.contains(&path.0) || role.has_authority(&Role::GlobalAdmin)"
|
||||
)]
|
||||
async fn delete_preset(
|
||||
pool: web::Data<Pool<Sqlite>>,
|
||||
id: web::Path<i32>,
|
||||
path: web::Path<(i32, i32)>,
|
||||
role: AuthDetails<Role>,
|
||||
user: web::ReqData<UserMeta>,
|
||||
) -> Result<impl Responder, ServiceError> {
|
||||
let (_, id) = path.into_inner();
|
||||
|
||||
if handles::delete_preset(&pool, &id).await.is_ok() {
|
||||
return Ok("Delete preset Success");
|
||||
}
|
||||
|
@ -487,6 +487,19 @@ pub async fn insert_preset(
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn new_channel_presets(
|
||||
conn: &Pool<Sqlite>,
|
||||
channel_id: i32,
|
||||
) -> Result<SqliteQueryResult, sqlx::Error> {
|
||||
let query = "INSERT INTO presets (name, text, x, y, fontsize, line_spacing, fontcolor, box, boxcolor, boxborderw, alpha, channel_id)
|
||||
VALUES ('Default', 'Wellcome to ffplayout messenger!', '(w-text_w)/2', '(h-text_h)/2', '24', '4', '#ffffff@0xff', '0', '#000000@0x80', '4', '1.0', $1),
|
||||
('Empty Text', '', '0', '0', '24', '4', '#000000', '0', '#000000', '0', '0', $1),
|
||||
('Bottom Text fade in', 'The upcoming event will be delayed by a few minutes.', '(w-text_w)/2', '(h-line_h)*0.9', '24', '4', '#ffffff', '1', '#000000@0x80', '4', 'ifnot(ld(1),st(1,t));if(lt(t,ld(1)+1),0,if(lt(t,ld(1)+2),(t-(ld(1)+1))/1,if(lt(t,ld(1)+8),1,if(lt(t,ld(1)+9),(1-(t-(ld(1)+8)))/1,0))))', $1),
|
||||
('Scrolling Text', 'We have a very important announcement to make.', 'ifnot(ld(1),st(1,t));if(lt(t,ld(1)+1),w+4,w-w/12*mod(t-ld(1),12*(w+tw)/w))', '(h-line_h)*0.9', '24', '4', '#ffffff', '1', '#000000@0x80', '4', '1.0', $1);";
|
||||
|
||||
sqlx::query(query).bind(channel_id).execute(conn).await
|
||||
}
|
||||
|
||||
pub async fn delete_preset(
|
||||
conn: &Pool<Sqlite>,
|
||||
id: &i32,
|
||||
|
@ -63,6 +63,7 @@ pub async fn create_channel(
|
||||
) -> Result<Channel, ServiceError> {
|
||||
let global = handles::select_global(conn).await?;
|
||||
let mut channel = handles::insert_channel(conn, target_channel).await?;
|
||||
handles::new_channel_presets(conn, channel.id).await?;
|
||||
|
||||
channel.preview_url = preview_url(&channel.preview_url, channel.id);
|
||||
|
||||
|
2
frontend
2
frontend
@ -1 +1 @@
|
||||
Subproject commit 0b1e083ce5b1818589b899d2fe0cc04f4100df32
|
||||
Subproject commit 8d8ab58ef43d450968a3e4fa23f1141c77a31b88
|
@ -49,8 +49,7 @@ CREATE TABLE
|
||||
boxborderw TEXT NOT NULL,
|
||||
alpha TEXT NOT NULL,
|
||||
channel_id INTEGER NOT NULL DEFAULT 1,
|
||||
FOREIGN KEY (channel_id) REFERENCES channels (id) ON UPDATE CASCADE ON DELETE CASCADE,
|
||||
UNIQUE (name)
|
||||
FOREIGN KEY (channel_id) REFERENCES channels (id) ON UPDATE CASCADE ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE
|
||||
|
Loading…
Reference in New Issue
Block a user