Add more debug info to webpages
This commit is contained in:
parent
8211caf2f0
commit
718beb1375
8 changed files with 51 additions and 5 deletions
|
@ -6,9 +6,12 @@ mod storage;
|
|||
use actix_web::{get, web, App, HttpResponse, HttpServer, Responder};
|
||||
use simplelog::{LevelFilter, WriteLogger};
|
||||
|
||||
static ARGS: std::sync::OnceLock<cli::CliArgs> = 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<dyn storage::IStorage> {
|
||||
|
@ -43,7 +46,7 @@ fn build_storage_box(storage: &cli::StorageArgs) -> Box<dyn storage::IStorage> {
|
|||
|
||||
#[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;
|
||||
|
|
|
@ -1,14 +1,21 @@
|
|||
use std::sync::OnceLock;
|
||||
|
||||
use actix_web::{get, HttpResponse, Responder, HttpRequest, Either};
|
||||
|
||||
use crate::storage::IStorage;
|
||||
|
||||
static DESCRIPTOR: OnceLock<String> = OnceLock::new();
|
||||
|
||||
#[get("/")]
|
||||
pub async fn decky_index(req: HttpRequest) -> impl Responder {
|
||||
pub async fn decky_index(req: HttpRequest, data: actix_web::web::Data<Box<dyn IStorage>>) -> 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##"
|
||||
<!DOCTYTPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
|
@ -28,9 +35,11 @@ pub async fn decky_index(req: HttpRequest) -> impl Responder {
|
|||
<h3>Maybe one day this page will display plugins in a human readable way...</h3>
|
||||
<br/>
|
||||
<a href="/plugins">plugins</a>
|
||||
| <a href="/version_info">version</a>
|
||||
| <a href="https://git.ngni.us/NG-SD-Plugins/not-decky-store">code</a>
|
||||
| GPL v3.0
|
||||
| <code>{}</code>
|
||||
</body>
|
||||
</html>"##))
|
||||
</html>"##, descriptor)))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -115,4 +115,8 @@ impl<S: AsRef<dyn IStorage> + Send + Sync> IStorage for CachedStorage<S> {
|
|||
fn get_statistics(&self) -> std::collections::HashMap<String, u64> {
|
||||
self.statistics_cache.get(|| self.fallback.as_ref().get_statistics())
|
||||
}
|
||||
|
||||
fn descriptor(&self) -> String {
|
||||
format!("cached {}", self.fallback.as_ref().descriptor())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@ pub trait IStorage: Send + Sync {
|
|||
fn increment_statistic(&self, _name: &str, _version: &str, _query: &decky_api::StorePluginIncrement) -> Result<decky_api::StorePluginVersion, std::io::Error> {
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -148,4 +148,14 @@ impl<S: AsRef<dyn IStorage> + Send + Sync> IStorage for MergedStorage<S> {
|
|||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -154,4 +154,8 @@ impl IStorage for ProxiedStorage {
|
|||
fn get_statistics(&self) -> std::collections::HashMap<String, u64> {
|
||||
self.fallback.get_statistics()
|
||||
}*/
|
||||
|
||||
fn descriptor(&self) -> String {
|
||||
format!("proxy {} @ {} ? proxied", &self.store_url, &self.domain_root)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,4 +54,8 @@ impl IQueryHandler for StandardPostRetrievalSort {
|
|||
Err(_) => "".to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
fn descriptor(&self) -> String {
|
||||
"standard_post_retrieval".to_owned()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue