Skip to content

Commit

Permalink
Add igni source & spec managment
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikWin committed Jan 10, 2025
1 parent 353cd3c commit 8960fad
Show file tree
Hide file tree
Showing 7 changed files with 460 additions and 27 deletions.
6 changes: 6 additions & 0 deletions vidformer-igni/init/setup.sql
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,9 @@ CREATE TABLE spec_t (
frame TEXT,
PRIMARY KEY (spec_id, pos)
);

CREATE TABLE spec_source_dependency (
spec_id UUID REFERENCES spec(id) ON DELETE CASCADE,
source_id UUID REFERENCES source(id),
PRIMARY KEY (spec_id, source_id)
);
13 changes: 13 additions & 0 deletions vidformer-igni/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,19 @@ async fn cmd_source_del(
}
};

let conflicting_spec: Option<uuid::Uuid> =
sqlx::query_scalar("SELECT spec_id FROM spec_source_dependency WHERE source_id = $1")
.bind(&source_id)
.fetch_optional(&pool)
.await?;

if let Some(spec_id) = conflicting_spec {
return Err(IgniError::General(format!(
"Spec {} depends on source {}",
spec_id, source_id
)));
}

let resp = sqlx::query("DELETE FROM source WHERE id = $1")
.bind(source_id)
.execute(&pool)
Expand Down
32 changes: 32 additions & 0 deletions vidformer-igni/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ async fn igni_http_req(
let segment_number = matches.get(2).unwrap().as_str().parse().unwrap();
vod::get_segment(req, global, spec_id, segment_number).await
}
(hyper::Method::GET, "/v2/source") // /v2/source (list)
=> {
api::list_sources(req, global).await
}
(hyper::Method::GET, _) // /v2/source/<uuid>
if {
Regex::new(r"^/v2/source/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$").unwrap().is_match(req.uri().path())
Expand All @@ -190,6 +194,22 @@ async fn igni_http_req(
=> {
api::push_source(req, global).await
}
(hyper::Method::DELETE, _) // /v2/source/<uuid>
if {
Regex::new(r"^/v2/source/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$").unwrap().is_match(req.uri().path())
} =>
{
let r = Regex::new(
r"^/v2/source/([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$",
);
let uri = req.uri().path().to_string();
let source_id = r.unwrap().captures(&uri).unwrap().get(1).unwrap().as_str();
api::delete_source(req, global, source_id).await
}
(hyper::Method::GET, "/v2/spec") // /v2/spec (list)
=> {
api::list_specs(req, global).await
}
(hyper::Method::GET, _) // /v2/spec/<uuid>
if {
Regex::new(r"^/v2/spec/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$").unwrap().is_match(req.uri().path())
Expand All @@ -202,6 +222,18 @@ async fn igni_http_req(
let spec_id = r.unwrap().captures(&uri).unwrap().get(1).unwrap().as_str();
api::get_spec(req, global, spec_id).await
}
(hyper::Method::DELETE, _) // /v2/spec/<uuid>
if {
Regex::new(r"^/v2/spec/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$").unwrap().is_match(req.uri().path())
} =>
{
let r = Regex::new(
r"^/v2/spec/([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$",
);
let uri = req.uri().path().to_string();
let spec_id = r.unwrap().captures(&uri).unwrap().get(1).unwrap().as_str();
api::delete_spec(req, global, spec_id).await
}
(hyper::Method::POST, "/v2/spec") // /v2/spec
=> {
api::push_spec(req, global).await
Expand Down
Loading

0 comments on commit 8960fad

Please sign in to comment.