Skip to content

Commit 1fcbd4e

Browse files
add cache information in About API (#597)
fixes #593
1 parent 037a7c6 commit 1fcbd4e

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

server/src/handlers/http/about.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
*/
1818

1919
use actix_web::web::Json;
20+
use human_size::SpecificSize;
2021
use serde_json::json;
2122

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

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

53+
let cache_details: String = if CONFIG.cache_dir().is_none() {
54+
"Disabled".to_string()
55+
} else {
56+
let cache_dir: &Option<PathBuf> = CONFIG.cache_dir();
57+
let cache_size: SpecificSize<human_size::Gigibyte> =
58+
SpecificSize::new(CONFIG.cache_size() as f64, human_size::Byte)
59+
.unwrap()
60+
.into();
61+
format!(
62+
"Enabled, Path: {} (Size: {})",
63+
cache_dir.as_ref().unwrap().display(),
64+
cache_size
65+
)
66+
};
67+
5168
Json(json!({
5269
"version": current_version,
5370
"uiVersion": ui_version,
@@ -61,6 +78,7 @@ pub async fn about() -> Json<serde_json::Value> {
6178
"license": "AGPL-3.0-only",
6279
"mode": mode,
6380
"staging": staging,
81+
"cache": cache_details,
6482
"grpcPort": grpc_port,
6583
"store": store
6684
}))

server/src/option.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ impl Config {
112112
&self.parseable.local_staging_path
113113
}
114114

115+
pub fn cache_size(&self) -> u64 {
116+
self.parseable.local_cache_size
117+
}
118+
119+
pub fn cache_dir(&self) -> &Option<PathBuf> {
120+
&self.parseable.local_cache_path
121+
}
122+
115123
pub fn is_default_creds(&self) -> bool {
116124
self.parseable.username == Server::DEFAULT_USERNAME
117125
&& self.parseable.password == Server::DEFAULT_PASSWORD

0 commit comments

Comments
 (0)