Skip to content

Plan, apply and roll back changes to a production ontology, with a blast radius report and a proof an auditor can re-check.

feat: add /api/save REST endpoint for sessionless file persistence

FABIOTESS3ff65d418daf
diff --git a/src/main.rs b/src/main.rs
index 53537940..c6f36fbc 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -445,6 +445,7 @@ async fn main() -> anyhow::Result<()> {
let sg_query = shared_graph.clone();
let sg_update = shared_graph.clone();
let sg_load = shared_graph.clone();
+ let sg_save = shared_graph.clone();
let api = axum::Router::new()
.route("/stats", axum::routing::get(move || {
let g = sg_stats.clone();
@@ -488,6 +489,20 @@ async fn main() -> anyhow::Result<()> {
).unwrap_or_default())
}
}))
+ .route("/save", axum::routing::post(move |body: axum::Json<serde_json::Value>| {
+ let g = sg_save.clone();
+ async move {
+ let path = body.0["path"].as_str().unwrap_or("~/.open-ontologies/studio-live.ttl").to_string();
+ let format = body.0["format"].as_str().unwrap_or("turtle").to_string();
+ let path = open_ontologies::config::expand_tilde(&path);
+ axum::Json(serde_json::from_str::<serde_json::Value>(
+ &match g.save_file(&path, &format) {
+ Ok(_) => format!(r#"{{"ok":true,"path":"{}"}}"#, path),
+ Err(e) => format!(r#"{{"error":"{}"}}"#, e),
+ }
+ ).unwrap_or_default())
+ }
+ }))
.route("/lineage", axum::routing::get(move || {
let db = shared_db.clone();
async move {