diff options
author | metamuffin <metamuffin@disroot.org> | 2025-09-14 20:38:16 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-09-14 20:38:20 +0200 |
commit | 2a43519723e9550bfdf67f0bace9511a07e1fb45 (patch) | |
tree | f7cc0dd12041dc36b16f1aa39f8c1dc4257776a8 /server | |
parent | e7564920d87ed047dc5af3e6a88b1709a48ce7c3 (diff) | |
download | hurrycurry-2a43519723e9550bfdf67f0bace9511a07e1fb45.tar hurrycurry-2a43519723e9550bfdf67f0bace9511a07e1fb45.tar.bz2 hurrycurry-2a43519723e9550bfdf67f0bace9511a07e1fb45.tar.zst |
registry: query option for multiple styles
Diffstat (limited to 'server')
-rw-r--r-- | server/registry/src/list.rs | 23 | ||||
-rw-r--r-- | server/registry/src/main.rs | 2 |
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>, } |