about summary refs log tree commit diff
path: root/splorm/src/handler/api/mod.rs
diff options
context:
space:
mode:
authorgennyble <gen@nyble.dev>2026-09-25 03:56:11 -0500
committergennyble <gen@nyble.dev>2026-09-25 03:56:11 -0500
commitba592de54cd3dce52eb2096dabbe748107f5db2b (patch)
tree4a23377e9788630e09c669e9ed18aecd27673ee7 /splorm/src/handler/api/mod.rs
parentf4d8e8d03c1b80d5c59ee85631d5a78048892a32 (diff)
splorm auth
Diffstat (limited to 'splorm/src/handler/api/mod.rs')
-rw-r--r--splorm/src/handler/api/mod.rs49
1 files changed, 49 insertions, 0 deletions
diff --git a/splorm/src/handler/api/mod.rs b/splorm/src/handler/api/mod.rs
new file mode 100644
index 0000000..a7bfd4b
--- /dev/null
+++ b/splorm/src/handler/api/mod.rs
@@ -0,0 +1,49 @@
+mod auth;
+
+use axum::{
+	Router,
+	body::Body,
+	extract::{Path, State},
+	response::Response,
+	routing::{get, post},
+};
+use sessionhash::RequestContext;
+
+use crate::{RuntimeError, fs, state::SplormState};
+
+/// Routes nested under /api
+pub fn routes() -> Router<SplormState> {
+	Router::new()
+		.route("/auth/register", post(auth::register))
+		.route("/auth/login", post(auth::login))
+		.route("/stats/now/{name}", get(stats))
+}
+
+async fn stats(
+	Path(name): Path<String>,
+	State(state): State<SplormState>,
+	ctx: RequestContext,
+) -> Result<Response, RuntimeError> {
+	tracing::trace!("{ctx} GET /api/stats/{name}");
+
+	let graphs = {
+		let mut connector = state.gatherer_thread().await;
+		connector.regular_graphs().await
+	};
+
+	let file_path = match name.as_str() {
+		"current_hostmeminfo.gif" => graphs.meminfo,
+		"current_hostnetinfo.gif" => graphs.meminfo,
+		"current_hostcpuinfo.gif" => graphs.cpuinfo,
+		_ => return Err(RuntimeError::generic_404()),
+	};
+
+	tracing::trace!("graph {name} system_path={file_path}");
+	let file = fs::unsafe_read_file(file_path).await?;
+
+	Response::builder()
+		.header("content-type", "image/gif")
+		.status(200)
+		.body(Body::from(file))
+		.map_err(|_| RuntimeError::Unknown)
+}