From a3ed3b055de23b3b970501a76b140772933828dd Mon Sep 17 00:00:00 2001 From: Nikhil Sinha Date: Wed, 3 Jan 2024 23:25:56 +0530 Subject: [PATCH 1/5] fix for PR# 593: added cache_dir and cache_size to the About API response json --- server/src/handlers/http/about.rs | 13 +++++++++++++ server/src/option.rs | 8 ++++++++ 2 files changed, 21 insertions(+) diff --git a/server/src/handlers/http/about.rs b/server/src/handlers/http/about.rs index dce3bf3c8..b29becee7 100644 --- a/server/src/handlers/http/about.rs +++ b/server/src/handlers/http/about.rs @@ -20,6 +20,7 @@ use actix_web::web::Json; use serde_json::json; use crate::{about, option::CONFIG, storage::StorageMetadata, utils::update}; +use std::path::PathBuf; pub async fn about() -> Json { let meta = StorageMetadata::global(); @@ -48,6 +49,15 @@ pub async fn about() -> Json { let is_oidc_active = CONFIG.parseable.openid.is_some(); let ui_version = option_env!("UI_VERSION").unwrap_or("development"); + let cache_size: &u64 = CONFIG.cache_size(); + let cache_enabled: &bool = if CONFIG.parseable.local_cache_path.is_none(){ + &false + } else { + &true + }; + + let cache_dir: &Option = CONFIG.cache_dir(); + Json(json!({ "version": current_version, "uiVersion": ui_version, @@ -61,6 +71,9 @@ pub async fn about() -> Json { "license": "AGPL-3.0-only", "mode": mode, "staging": staging, + "cacheEnabled": cache_enabled, + "cacheDir": cache_dir, + "cacheSize": cache_size, "grpcPort": grpc_port, "store": store })) diff --git a/server/src/option.rs b/server/src/option.rs index f20069305..9a340d3b6 100644 --- a/server/src/option.rs +++ b/server/src/option.rs @@ -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 { + &self.parseable.local_cache_path + } + pub fn is_default_creds(&self) -> bool { self.parseable.username == Server::DEFAULT_USERNAME && self.parseable.password == Server::DEFAULT_PASSWORD From 19e3fdd1f497c8536e09aeadd9a8d8bfe183d23c Mon Sep 17 00:00:00 2001 From: Nikhil Sinha Date: Thu, 4 Jan 2024 11:33:23 +0530 Subject: [PATCH 2/5] fix for PR #593: cache_size set to 0 in case cache is not enabled --- server/src/handlers/http/about.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/server/src/handlers/http/about.rs b/server/src/handlers/http/about.rs index b29becee7..77a43e66c 100644 --- a/server/src/handlers/http/about.rs +++ b/server/src/handlers/http/about.rs @@ -49,7 +49,11 @@ pub async fn about() -> Json { let is_oidc_active = CONFIG.parseable.openid.is_some(); let ui_version = option_env!("UI_VERSION").unwrap_or("development"); - let cache_size: &u64 = CONFIG.cache_size(); + let cache_size: &u64 = if CONFIG.parseable.local_cache_path.is_none(){ + &0 + } else { + CONFIG.cache_size() + }; let cache_enabled: &bool = if CONFIG.parseable.local_cache_path.is_none(){ &false } else { @@ -78,3 +82,5 @@ pub async fn about() -> Json { "store": store })) } + + From 36eab426bab21a3e1dba63fa966417e842d035d0 Mon Sep 17 00:00:00 2001 From: Nikhil Sinha Date: Thu, 4 Jan 2024 12:34:53 +0530 Subject: [PATCH 3/5] fix for PR#593: added Cache details to AboutAPI --- server/src/handlers/http/about.rs | 25 +++++++++++++------------ server/src/option.rs | 4 ++-- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/server/src/handlers/http/about.rs b/server/src/handlers/http/about.rs index 77a43e66c..2ee65f64e 100644 --- a/server/src/handlers/http/about.rs +++ b/server/src/handlers/http/about.rs @@ -17,6 +17,7 @@ */ use actix_web::web::Json; +use human_size::SpecificSize; use serde_json::json; use crate::{about, option::CONFIG, storage::StorageMetadata, utils::update}; @@ -48,19 +49,21 @@ pub async fn about() -> Json { let llm_provider = is_llm_active.then_some("OpenAI"); let is_oidc_active = CONFIG.parseable.openid.is_some(); let ui_version = option_env!("UI_VERSION").unwrap_or("development"); + - let cache_size: &u64 = if CONFIG.parseable.local_cache_path.is_none(){ - &0 - } else { - CONFIG.cache_size() - }; - let cache_enabled: &bool = if CONFIG.parseable.local_cache_path.is_none(){ - &false + + let cache_details: String; + if CONFIG.cache_dir().is_none(){ + + cache_details = "Disabled".to_string(); } else { - &true + let cache_dir: &Option = CONFIG.cache_dir(); + let cache_size: SpecificSize = SpecificSize::new(CONFIG.cache_size() as f64, human_size::Byte) + .unwrap() + .into(); + cache_details = format!("Enabled, Path: {} (Size: {})", cache_dir.as_ref().unwrap().display(), cache_size); }; - let cache_dir: &Option = CONFIG.cache_dir(); Json(json!({ "version": current_version, @@ -75,9 +78,7 @@ pub async fn about() -> Json { "license": "AGPL-3.0-only", "mode": mode, "staging": staging, - "cacheEnabled": cache_enabled, - "cacheDir": cache_dir, - "cacheSize": cache_size, + "cache": cache_details, "grpcPort": grpc_port, "store": store })) diff --git a/server/src/option.rs b/server/src/option.rs index 9a340d3b6..68fea5db2 100644 --- a/server/src/option.rs +++ b/server/src/option.rs @@ -112,8 +112,8 @@ impl Config { &self.parseable.local_staging_path } - pub fn cache_size(&self) -> &u64 { - &self.parseable.local_cache_size + pub fn cache_size(&self) -> u64 { + self.parseable.local_cache_size } pub fn cache_dir(&self) -> &Option { From 2cf8766b71b7b889c825cdd64fc5887589b47d62 Mon Sep 17 00:00:00 2001 From: Nikhil Sinha Date: Thu, 4 Jan 2024 12:43:09 +0530 Subject: [PATCH 4/5] fixed cargo format --- server/src/handlers/http/about.rs | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/server/src/handlers/http/about.rs b/server/src/handlers/http/about.rs index 2ee65f64e..5b866b148 100644 --- a/server/src/handlers/http/about.rs +++ b/server/src/handlers/http/about.rs @@ -49,22 +49,23 @@ pub async fn about() -> Json { let llm_provider = is_llm_active.then_some("OpenAI"); 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(){ - - cache_details = "Disabled".to_string(); + if CONFIG.cache_dir().is_none() { + cache_details = "Disabled".to_string(); } else { let cache_dir: &Option = CONFIG.cache_dir(); - let cache_size: SpecificSize = SpecificSize::new(CONFIG.cache_size() as f64, human_size::Byte) - .unwrap() - .into(); - cache_details = format!("Enabled, Path: {} (Size: {})", cache_dir.as_ref().unwrap().display(), cache_size); + let cache_size: SpecificSize = + SpecificSize::new(CONFIG.cache_size() as f64, human_size::Byte) + .unwrap() + .into(); + cache_details = format!( + "Enabled, Path: {} (Size: {})", + cache_dir.as_ref().unwrap().display(), + cache_size + ); }; - Json(json!({ "version": current_version, "uiVersion": ui_version, @@ -83,5 +84,3 @@ pub async fn about() -> Json { "store": store })) } - - From 77b8f1b964d38520339a8fe2f75495f8a1138438 Mon Sep 17 00:00:00 2001 From: Nikhil Sinha Date: Thu, 4 Jan 2024 12:50:49 +0530 Subject: [PATCH 5/5] cargo clippy suggestion fixed --- server/src/handlers/http/about.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/server/src/handlers/http/about.rs b/server/src/handlers/http/about.rs index 5b866b148..2c8db6b9a 100644 --- a/server/src/handlers/http/about.rs +++ b/server/src/handlers/http/about.rs @@ -50,20 +50,19 @@ pub async fn about() -> Json { 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() { - cache_details = "Disabled".to_string(); + let cache_details: String = if CONFIG.cache_dir().is_none() { + "Disabled".to_string() } else { let cache_dir: &Option = CONFIG.cache_dir(); let cache_size: SpecificSize = SpecificSize::new(CONFIG.cache_size() as f64, human_size::Byte) .unwrap() .into(); - cache_details = format!( + format!( "Enabled, Path: {} (Size: {})", cache_dir.as_ref().unwrap().display(), cache_size - ); + ) }; Json(json!({