aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/registry/src/list.rs23
-rw-r--r--server/registry/src/main.rs2
2 files changed, 19 insertions, 6 deletions
diff --git a/server/registry/src/list.rs b/server/registry/src/list.rs
index 06bafe3a..619700f7 100644
--- a/server/registry/src/list.rs
+++ b/server/registry/src/list.rs
@@ -32,33 +32,36 @@ use rocket::{
use std::sync::Arc;
use tokio::sync::RwLock;
-#[get("/v1/list")]
+#[get("/v1/list?<style>")]
pub(super) async fn r_list(
registry: &State<Arc<RwLock<Registry>>>,
json: AcceptJson,
+ style: Option<usize>,
) -> Cors<Either<RawJson<Arc<str>>, RawHtml<Arc<str>>>> {
Cors(if json.0 {
Either::Left(RawJson(registry.read().await.json_response.clone()))
} else {
- Either::Right(RawHtml(registry.read().await.html_response.clone()))
+ let v = style.filter(|&x| x < 4).unwrap_or(0);
+ Either::Right(RawHtml(registry.read().await.html_response[v].clone()))
})
}
pub(super) fn generate_json_list(entries: &[Entry]) -> Result<Arc<str>> {
Ok(serde_json::to_string(&entries)?.into())
}
-pub(super) fn generate_html_list(entries: &[Entry]) -> Result<Arc<str>> {
- Ok(ListPage { entries }.to_string().into())
+pub(super) fn generate_html_list(entries: &[Entry]) -> Result<[Arc<str>; 4]> {
+ Ok([0, 1, 2, 3].map(|style| ListPage { entries, style }.to_string().into()))
}
markup::define!(
- ListPage<'a>(entries: &'a [Entry]) {
+ ListPage<'a>(entries: &'a [Entry], style: usize) {
@markup::doctype()
html {
head {
title {
"Hurry Curry! Server Registry"
}
+ style { @variant_css(*style) }
}
body {
table {
@@ -77,6 +80,16 @@ markup::define!(
}
);
+fn variant_css(style: usize) -> &'static str {
+ match style {
+ 0 => "",
+ 1 => " * { font-family: sans-serif } ",
+ 2 => " * { color: white } ",
+ 3 => " * { color: white; font-family: sans-serif } ",
+ _ => "",
+ }
+}
+
pub struct AcceptJson(bool);
impl<'r> FromRequest<'r> for AcceptJson {
type Error = ();
diff --git a/server/registry/src/main.rs b/server/registry/src/main.rs
index b9cfbfe0..da7f404b 100644
--- a/server/registry/src/main.rs
+++ b/server/registry/src/main.rs
@@ -90,7 +90,7 @@ fn main() {
#[derive(Default)]
struct Registry {
json_response: Arc<str>,
- html_response: Arc<str>,
+ html_response: [Arc<str>; 4],
entries: Vec<Entry>,
servers: HashMap<u128, InternalEntry>,
}