feat: /info endpoint

This commit is contained in:
Compositr 2024-11-02 17:33:44 +11:00
parent cd56355603
commit b297785dd5
4 changed files with 48 additions and 1 deletions

View file

@ -2,3 +2,4 @@ luciders
skia skia
usvg usvg
resvg resvg
indoc

7
Cargo.lock generated
View file

@ -185,6 +185,12 @@ version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "edcd27d72f2f071c64249075f42e205ff93c9a4c5f6c6da53e79ed9f9832c285" checksum = "edcd27d72f2f071c64249075f42e205ff93c9a4c5f6c6da53e79ed9f9832c285"
[[package]]
name = "indoc"
version = "2.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b248f5224d1d606005e02c97f5aa4e88eeb230488bcc03bc9ca4d7991399f2b5"
[[package]] [[package]]
name = "kurbo" name = "kurbo"
version = "0.11.1" version = "0.11.1"
@ -218,6 +224,7 @@ name = "luciders"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"ctrlc", "ctrlc",
"indoc",
"regex", "regex",
"resvg", "resvg",
] ]

View file

@ -5,5 +5,6 @@ edition = "2021"
[dependencies] [dependencies]
ctrlc = "3.4.5" ctrlc = "3.4.5"
indoc = "2.0.5"
regex = "1.11.1" regex = "1.11.1"
resvg = "0.44.0" resvg = "0.44.0"

View file

@ -8,6 +8,8 @@ use resvg::{
usvg, usvg,
}; };
use indoc::indoc;
mod handlers; mod handlers;
mod http; mod http;
mod icons; mod icons;
@ -44,6 +46,35 @@ fn main() {
Response::new(req, 200, Body::Static("OK - luciders is running")) Response::new(req, 200, Body::Static("OK - luciders is running"))
}); });
const INFO: &str = indoc!(
"
luciders - Lucide SVG icons server <https://lucide.dev/>
GET /info - Get server information
GET /icons/[icon].svg - Get an icon in SVG format (equivalent to fetching them directly from Lucide)
GET /icons/[icon].png - Get an icon rendered in PNG format
Query parameters:
scale - integer - Scale the icon (default: 1, min: 1, max: 100)
padding - integer - Add padding (px) around the icon (default: 0, min: 0, max: 100)
background - hex - Set the background color in hex w/o the hashtag (e.g. FFFFFF) (default: transparent)
discord_compatibility - boolean - Set padding to 8px for Discord compatibility. Typically for use in embed author icons as these have a circle clip applied by Discord. Overrides padding if set. (default: false)
cache_key - string - Technically this can have any name. The server does not interpret this at all. Useful for cache busting. (default: none)
Example:
/icons/apple.png?scale=2&background=FF0000&discord_compatibility
*** mantained with by Compositr (Jim) ***
"
);
handlers.add_handler("/info", |req| {
if req.method != "GET" {
return Response::new(req, 405, Body::Static("Method Not Allowed"));
}
Response::new(req, 200, Body::Static(INFO))
});
handlers.add_handler("/icons/[icon].svg", { handlers.add_handler("/icons/[icon].svg", {
let icons = Rc::clone(&icons_rc); let icons = Rc::clone(&icons_rc);
move |req| { move |req| {
@ -142,6 +173,13 @@ fn main() {
None => {} None => {}
} }
match req.url.query.get("discord_compatibility") {
Some(_) => {
padding = 8;
}
None => {}
}
let mut background = Color::TRANSPARENT; let mut background = Color::TRANSPARENT;
match req.url.query.get("background") { match req.url.query.get("background") {
Some(background_str) => { Some(background_str) => {