From d93d4accba7aef297a21d3395277a66d417b9f92 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Tue, 23 May 2023 12:32:56 +0200 Subject: [PATCH] Added ability to list all domains --- TODO | 1 - src/service.rs | 31 +++++++++++++++++++++++++++++++ src/service/http_tpl/domains.html | 12 ++++++++++++ src/service/http_tpl/index.html | 2 +- 4 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 src/service/http_tpl/domains.html diff --git a/TODO b/TODO index 22eac60..035c319 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,3 @@ -- list existing domains - logging - expect statements (pretend it's "expected", not "expect") - map_unexpected annotation string diff --git a/src/service.rs b/src/service.rs index fc55149..f731c0f 100644 --- a/src/service.rs +++ b/src/service.rs @@ -288,6 +288,36 @@ where self.render_page("/domain_sync.html", response) } + + pub fn domains(&self) -> SvcResponse { + #[derive(Serialize)] + struct Response { + domains: Vec, + } + + let domains = match self.domain_manager.all_domains() { + Ok(domains) => domains, + Err(e) => { + return self.render_error_page(500, format!("failed get all domains: {e}").as_str()) + } + }; + + let domains: Vec = match domains.into_iter().try_collect() { + Ok(domains) => domains, + Err(e) => { + return self.render_error_page(500, format!("failed get all domains: {e}").as_str()) + } + }; + + let mut domains: Vec = domains + .into_iter() + .map(|domain| domain.as_str().to_string()) + .collect(); + + domains.sort(); + + self.render_page("/domains.html", Response { domains: domains }) + } } pub async fn handle_request( @@ -385,6 +415,7 @@ where }) .await } + (&Method::GET, "/domains.html") => svc.domains(), _ => svc.render_error_page(404, "Page not found!"), } } diff --git a/src/service/http_tpl/domains.html b/src/service/http_tpl/domains.html new file mode 100644 index 0000000..7779b4f --- /dev/null +++ b/src/service/http_tpl/domains.html @@ -0,0 +1,12 @@ +

All Domains

+ +

Below are listed all domains which this Domiply instance is currently +serving

+ +
    +{{ #each data.domains }} +
  • + {{ this }} +
  • +{{ /each }} +
diff --git a/src/service/http_tpl/index.html b/src/service/http_tpl/index.html index 7296380..6ed880e 100644 --- a/src/service/http_tpl/index.html +++ b/src/service/http_tpl/index.html @@ -29,7 +29,7 @@ been set up.

Or you can do any of the following alternative actions: