diff options
| author | Ellie Huxtable <ellie@elliehuxtable.com> | 2023-05-21 16:21:51 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-21 15:21:51 +0000 |
| commit | d2240e1163a62f96dfb1cb99c38ffa2390d53c33 (patch) | |
| tree | f25616f3855d7f79df9d7d548c901796e136f557 /atuin-server/src/handlers | |
| parent | Restructure account commands to account subcommand (#984) (diff) | |
| download | atuin-d2240e1163a62f96dfb1cb99c38ffa2390d53c33.zip | |
Allow server configured page size (#994)
* Allow server configured page size
* Backwards compat via semver checks
* Correct header name
Diffstat (limited to 'atuin-server/src/handlers')
| -rw-r--r-- | atuin-server/src/handlers/history.rs | 17 | ||||
| -rw-r--r-- | atuin-server/src/handlers/status.rs | 4 |
2 files changed, 21 insertions, 0 deletions
diff --git a/atuin-server/src/handlers/history.rs b/atuin-server/src/handlers/history.rs index 3e84074c..1c9dff5f 100644 --- a/atuin-server/src/handlers/history.rs +++ b/atuin-server/src/handlers/history.rs @@ -2,6 +2,7 @@ use std::collections::HashMap; use axum::{ extract::{Path, Query, State}, + http::HeaderMap, Json, }; use http::StatusCode; @@ -13,6 +14,7 @@ use crate::{ database::Database, models::{NewHistory, User}, router::AppState, + utils::client_version_min, }; use atuin_common::api::*; @@ -41,15 +43,30 @@ pub async fn count<DB: Database>( pub async fn list<DB: Database>( req: Query<SyncHistoryRequest>, user: User, + headers: HeaderMap, state: State<AppState<DB>>, ) -> Result<Json<SyncHistoryResponse>, ErrorResponseStatus<'static>> { let db = &state.0.database; + + let agent = headers + .get("user-agent") + .map_or("", |v| v.to_str().unwrap_or("")); + + let variable_page_size = client_version_min(agent, ">=15.0.0").unwrap_or(false); + + let page_size = if variable_page_size { + state.settings.page_size + } else { + 100 + }; + let history = db .list_history( &user, req.sync_ts.naive_utc(), req.history_ts.naive_utc(), &req.host, + page_size, ) .await; diff --git a/atuin-server/src/handlers/status.rs b/atuin-server/src/handlers/status.rs index 351c2dd2..97c02886 100644 --- a/atuin-server/src/handlers/status.rs +++ b/atuin-server/src/handlers/status.rs @@ -7,6 +7,8 @@ use crate::{database::Database, models::User, router::AppState}; use atuin_common::api::*; +const VERSION: &str = env!("CARGO_PKG_VERSION"); + #[instrument(skip_all, fields(user.id = user.id))] pub async fn status<DB: Database>( user: User, @@ -35,5 +37,7 @@ pub async fn status<DB: Database>( count, deleted, username: user.username, + version: VERSION.to_string(), + page_size: state.settings.page_size, })) } |
