diff options
| author | Ellie Huxtable <ellie@elliehuxtable.com> | 2023-07-14 20:44:47 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-14 20:44:47 +0100 |
| commit | 578615596975b5a2e6aa8b8d7a8f36b9e390f9ea (patch) | |
| tree | 3898fe4b1b987ade80a3a8fb175bb09817bd7c5c /atuin-server | |
| parent | Add new sync (#1093) (diff) | |
| download | atuin-578615596975b5a2e6aa8b8d7a8f36b9e390f9ea.zip | |
Add total history count to the index API (#1102)
Thought it would be fun to collect some cool stats, maybe put them on
atuin.sh.
Diffstat (limited to 'atuin-server')
| -rw-r--r-- | atuin-server/src/handlers/mod.rs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/atuin-server/src/handlers/mod.rs b/atuin-server/src/handlers/mod.rs index 2bd782db..18b1af8e 100644 --- a/atuin-server/src/handlers/mod.rs +++ b/atuin-server/src/handlers/mod.rs @@ -1,5 +1,8 @@ use atuin_common::api::{ErrorResponse, IndexResponse}; -use axum::{response::IntoResponse, Json}; +use atuin_server_database::Database; +use axum::{extract::State, response::IntoResponse, Json}; + +use crate::router::AppState; pub mod history; pub mod record; @@ -8,12 +11,17 @@ pub mod user; const VERSION: &str = env!("CARGO_PKG_VERSION"); -pub async fn index() -> Json<IndexResponse> { +pub async fn index<DB: Database>(state: State<AppState<DB>>) -> Json<IndexResponse> { let homage = r#""Through the fathomless deeps of space swims the star turtle Great A'Tuin, bearing on its back the four giant elephants who carry on their shoulders the mass of the Discworld." -- Sir Terry Pratchett"#; + // Error with a -1 response + // It's super unlikley this will happen + let count = state.database.total_history().await.unwrap_or(-1); + Json(IndexResponse { homage: homage.to_string(), version: VERSION.to_string(), + total_history: count, }) } |
