From 718beb13758db71b59b48253232e9ec519051b51 Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Sat, 11 May 2024 00:18:42 -0400 Subject: [PATCH] Add more debug info to webpages --- src/main.rs | 7 +++++-- src/not_decky/index.rs | 15 ++++++++++++--- src/storage/cache.rs | 4 ++++ src/storage/filesystem.rs | 4 ++++ src/storage/interface.rs | 8 ++++++++ src/storage/merge.rs | 10 ++++++++++ src/storage/proxy.rs | 4 ++++ src/storage/standard_sort.rs | 4 ++++ 8 files changed, 51 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index b45aaaa..a70bf6d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,9 +6,12 @@ mod storage; use actix_web::{get, web, App, HttpResponse, HttpServer, Responder}; use simplelog::{LevelFilter, WriteLogger}; +static ARGS: std::sync::OnceLock = std::sync::OnceLock::new(); + #[get("/version_info")] async fn hello() -> impl Responder { - HttpResponse::Ok().body(format!("{} v{}", consts::PACKAGE_NAME, consts::PACKAGE_VERSION)) + let args = ARGS.get_or_init(|| cli::CliArgs::get()); + HttpResponse::Ok().body(format!("{} v{} {}", consts::PACKAGE_NAME, consts::PACKAGE_VERSION, args.storage.clone().to_descriptor())) } fn build_storage_box(storage: &cli::StorageArgs) -> Box { @@ -43,7 +46,7 @@ fn build_storage_box(storage: &cli::StorageArgs) -> Box { #[actix_web::main] async fn main() -> std::io::Result<()> { - let args = cli::CliArgs::get(); + let args = ARGS.get_or_init(|| cli::CliArgs::get()); let log_filepath = std::path::Path::new("/tmp").join(format!("{}.log", consts::PACKAGE_NAME)); #[cfg(debug_assertions)] let log_level = LevelFilter::Debug; diff --git a/src/not_decky/index.rs b/src/not_decky/index.rs index e4f1e28..3e2af26 100644 --- a/src/not_decky/index.rs +++ b/src/not_decky/index.rs @@ -1,14 +1,21 @@ +use std::sync::OnceLock; + use actix_web::{get, HttpResponse, Responder, HttpRequest, Either}; +use crate::storage::IStorage; + +static DESCRIPTOR: OnceLock = OnceLock::new(); + #[get("/")] -pub async fn decky_index(req: HttpRequest) -> impl Responder { +pub async fn decky_index(req: HttpRequest, data: actix_web::web::Data>) -> impl Responder { if req.headers().contains_key("X-Decky-Version") { // a real store request Either::Left(actix_web::web::Redirect::to("/plugins").temporary()) } else { + let descriptor = DESCRIPTOR.get_or_init(|| data.descriptor()); Either::Right(HttpResponse::Ok() .insert_header(("Content-Type", "text/html")) - .body(r##" + .body(format!(r##" @@ -28,9 +35,11 @@ pub async fn decky_index(req: HttpRequest) -> impl Responder {

Maybe one day this page will display plugins in a human readable way...


plugins + | version | code | GPL v3.0 + | {} -"##)) +"##, descriptor))) } } diff --git a/src/storage/cache.rs b/src/storage/cache.rs index 730d6d5..d502482 100644 --- a/src/storage/cache.rs +++ b/src/storage/cache.rs @@ -115,4 +115,8 @@ impl + Send + Sync> IStorage for CachedStorage { fn get_statistics(&self) -> std::collections::HashMap { self.statistics_cache.get(|| self.fallback.as_ref().get_statistics()) } + + fn descriptor(&self) -> String { + format!("cached {}", self.fallback.as_ref().descriptor()) + } } diff --git a/src/storage/filesystem.rs b/src/storage/filesystem.rs index 32272ec..591a7ad 100644 --- a/src/storage/filesystem.rs +++ b/src/storage/filesystem.rs @@ -302,4 +302,8 @@ impl IStorage for FileStorage { } Err(std::io::Error::new(std::io::ErrorKind::NotFound, "Plugin version not found")) } + + fn descriptor(&self) -> String { + format!("filesystem {} @ {} ? {}", self.root.display(), &self.domain_root, self.query_handler.descriptor()) + } } diff --git a/src/storage/interface.rs b/src/storage/interface.rs index d32308b..935d1e8 100644 --- a/src/storage/interface.rs +++ b/src/storage/interface.rs @@ -16,6 +16,8 @@ pub trait IStorage: Send + Sync { fn increment_statistic(&self, _name: &str, _version: &str, _query: &decky_api::StorePluginIncrement) -> Result { Err(std::io::Error::new(std::io::ErrorKind::InvalidInput, "Statistics increment not supported")) } + + fn descriptor(&self) -> String; } pub struct EmptyStorage; @@ -24,6 +26,10 @@ impl IStorage for EmptyStorage { fn plugins(&self, _query: &str) -> decky_api::StorePluginList { Vec::new() } + + fn descriptor(&self) -> String { + "empty".to_owned() + } } pub trait IQueryHandler: Send + Sync { @@ -33,4 +39,6 @@ pub trait IQueryHandler: Send + Sync { fn supported_params(&self, query: &str) -> String { query.to_owned() } + + fn descriptor(&self) -> String; } diff --git a/src/storage/merge.rs b/src/storage/merge.rs index baa7f0b..ba7910b 100644 --- a/src/storage/merge.rs +++ b/src/storage/merge.rs @@ -148,4 +148,14 @@ impl + Send + Sync> IStorage for MergedStorage { stats } + + fn descriptor(&self) -> String { + use std::fmt::Write; + let mut desc = String::from("merged: "); + for store in &self.stores { + write!(desc, "{}, ", store.as_ref().descriptor()).unwrap() + } + desc.truncate(desc.len() - 2); + desc + } } diff --git a/src/storage/proxy.rs b/src/storage/proxy.rs index 7291be9..a7cb765 100644 --- a/src/storage/proxy.rs +++ b/src/storage/proxy.rs @@ -154,4 +154,8 @@ impl IStorage for ProxiedStorage { fn get_statistics(&self) -> std::collections::HashMap { self.fallback.get_statistics() }*/ + + fn descriptor(&self) -> String { + format!("proxy {} @ {} ? proxied", &self.store_url, &self.domain_root) + } } diff --git a/src/storage/standard_sort.rs b/src/storage/standard_sort.rs index c856649..22a3e96 100644 --- a/src/storage/standard_sort.rs +++ b/src/storage/standard_sort.rs @@ -54,4 +54,8 @@ impl IQueryHandler for StandardPostRetrievalSort { Err(_) => "".to_owned() } } + + fn descriptor(&self) -> String { + "standard_post_retrieval".to_owned() + } }