Add version to controller and api
This commit is contained in:
parent
f3d367e479
commit
4e97006919
7 changed files with 77 additions and 3 deletions
21
Cargo.lock
generated
21
Cargo.lock
generated
|
|
@ -823,6 +823,7 @@ dependencies = [
|
||||||
"actix-ws",
|
"actix-ws",
|
||||||
"emgauwa-common",
|
"emgauwa-common",
|
||||||
"futures",
|
"futures",
|
||||||
|
"git-version",
|
||||||
"itertools",
|
"itertools",
|
||||||
"log",
|
"log",
|
||||||
"rand 0.9.2",
|
"rand 0.9.2",
|
||||||
|
|
@ -1054,6 +1055,26 @@ version = "0.31.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f"
|
checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "git-version"
|
||||||
|
version = "0.3.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1ad568aa3db0fcbc81f2f116137f263d7304f512a1209b35b85150d3ef88ad19"
|
||||||
|
dependencies = [
|
||||||
|
"git-version-macro",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "git-version-macro"
|
||||||
|
version = "0.3.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "53010ccb100b96a67bc32c0175f0ed1426b31b655d562898e57325f81c023ac0"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "h2"
|
name = "h2"
|
||||||
version = "0.3.26"
|
version = "0.3.26"
|
||||||
|
|
|
||||||
|
|
@ -28,3 +28,4 @@ sqlx = { version = "0.8", features = ["sqlite", "runtime-tokio", "macros"] }
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
tokio = { version = "1.36", features = ["macros", "rt", "rt-multi-thread"] }
|
tokio = { version = "1.36", features = ["macros", "rt", "rt-multi-thread"] }
|
||||||
rand = "0.9.2"
|
rand = "0.9.2"
|
||||||
|
git-version = "0.3"
|
||||||
|
|
|
||||||
32
api.v1.json
32
api.v1.json
|
|
@ -27,6 +27,9 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "websocket"
|
"name": "websocket"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "misc"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"paths": {
|
"paths": {
|
||||||
|
|
@ -1037,6 +1040,35 @@
|
||||||
"description": "Create a list of schedules"
|
"description": "Create a list of schedules"
|
||||||
},
|
},
|
||||||
"parameters": []
|
"parameters": []
|
||||||
|
},
|
||||||
|
"/api/v1/version": {
|
||||||
|
"get": {
|
||||||
|
"summary": "get version info",
|
||||||
|
"tags": [
|
||||||
|
"misc"
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"headers": {},
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"version": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"operationId": "get-relays",
|
||||||
|
"description": "Return a list with all relays."
|
||||||
|
},
|
||||||
|
"parameters": []
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"components": {
|
"components": {
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ pub async fn update(
|
||||||
.ok_or(DatabaseError::NotFound)?;
|
.ok_or(DatabaseError::NotFound)?;
|
||||||
|
|
||||||
let controller = controller
|
let controller = controller
|
||||||
.update(&mut pool_conn, data.name.as_str(), controller.relay_count)
|
.update(&mut pool_conn, data.name.as_str(), controller.relay_count, &controller.version)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let return_controller = Controller::from_db_model(&mut pool_conn, controller)?;
|
let return_controller = Controller::from_db_model(&mut pool_conn, controller)?;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,24 @@
|
||||||
|
use actix_web::{get, HttpResponse};
|
||||||
|
use git_version::git_version;
|
||||||
|
use serde_derive::Serialize;
|
||||||
|
|
||||||
pub mod controllers;
|
pub mod controllers;
|
||||||
pub mod macros;
|
pub mod macros;
|
||||||
pub mod relays;
|
pub mod relays;
|
||||||
pub mod schedules;
|
pub mod schedules;
|
||||||
pub mod tags;
|
pub mod tags;
|
||||||
pub mod ws;
|
pub mod ws;
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
struct VersionResponse {
|
||||||
|
version: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[get("/version")]
|
||||||
|
pub async fn version() -> HttpResponse {
|
||||||
|
let version_response = VersionResponse {
|
||||||
|
version: String::from(git_version!()),
|
||||||
|
};
|
||||||
|
|
||||||
|
HttpResponse::Ok().json(version_response)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,8 @@ async fn main() -> Result<(), std::io::Error> {
|
||||||
.service(handlers::v1::macros::delete)
|
.service(handlers::v1::macros::delete)
|
||||||
.service(handlers::v1::macros::execute)
|
.service(handlers::v1::macros::execute)
|
||||||
.service(handlers::v1::ws::ws_controllers)
|
.service(handlers::v1::ws::ws_controllers)
|
||||||
.service(handlers::v1::ws::ws_relays),
|
.service(handlers::v1::ws::ws_relays)
|
||||||
|
.service(handlers::v1::version),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.workers((pool_size / 2) as usize)
|
.workers((pool_size / 2) as usize)
|
||||||
|
|
|
||||||
|
|
@ -253,10 +253,11 @@ impl WsServer {
|
||||||
&c.uid,
|
&c.uid,
|
||||||
&c.name,
|
&c.name,
|
||||||
c.relay_count,
|
c.relay_count,
|
||||||
|
&c.version,
|
||||||
))?;
|
))?;
|
||||||
block_on(controller_db.update_active(&mut pool_conn, true))?;
|
block_on(controller_db.update_active(&mut pool_conn, true))?;
|
||||||
// update only the relay count
|
// update only the relay count
|
||||||
block_on(controller_db.update(&mut pool_conn, &controller_db.name, c.relay_count))?;
|
block_on(controller_db.update(&mut pool_conn, &controller_db.name, c.relay_count, &c.version))?;
|
||||||
|
|
||||||
for relay in &controller.relays {
|
for relay in &controller.relays {
|
||||||
log::debug!(
|
log::debug!(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue