Skip to content

Commit

Permalink
add cache information in About API (#597)
Browse files Browse the repository at this point in the history
fixes #593
  • Loading branch information
nikhilsinhaparseable authored Jan 4, 2024
1 parent 037a7c6 commit 1fcbd4e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
18 changes: 18 additions & 0 deletions server/src/handlers/http/about.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
*/

use actix_web::web::Json;
use human_size::SpecificSize;
use serde_json::json;

use crate::{about, option::CONFIG, storage::StorageMetadata, utils::update};
use std::path::PathBuf;

pub async fn about() -> Json<serde_json::Value> {
let meta = StorageMetadata::global();
Expand Down Expand Up @@ -48,6 +50,21 @@ pub async fn about() -> Json<serde_json::Value> {
let is_oidc_active = CONFIG.parseable.openid.is_some();
let ui_version = option_env!("UI_VERSION").unwrap_or("development");

let cache_details: String = if CONFIG.cache_dir().is_none() {
"Disabled".to_string()
} else {
let cache_dir: &Option<PathBuf> = CONFIG.cache_dir();
let cache_size: SpecificSize<human_size::Gigibyte> =
SpecificSize::new(CONFIG.cache_size() as f64, human_size::Byte)
.unwrap()
.into();
format!(
"Enabled, Path: {} (Size: {})",
cache_dir.as_ref().unwrap().display(),
cache_size
)
};

Json(json!({
"version": current_version,
"uiVersion": ui_version,
Expand All @@ -61,6 +78,7 @@ pub async fn about() -> Json<serde_json::Value> {
"license": "AGPL-3.0-only",
"mode": mode,
"staging": staging,
"cache": cache_details,
"grpcPort": grpc_port,
"store": store
}))
Expand Down
8 changes: 8 additions & 0 deletions server/src/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ impl Config {
&self.parseable.local_staging_path
}

pub fn cache_size(&self) -> u64 {
self.parseable.local_cache_size
}

pub fn cache_dir(&self) -> &Option<PathBuf> {
&self.parseable.local_cache_path
}

pub fn is_default_creds(&self) -> bool {
self.parseable.username == Server::DEFAULT_USERNAME
&& self.parseable.password == Server::DEFAULT_PASSWORD
Expand Down

0 comments on commit 1fcbd4e

Please sign in to comment.