Feat: cleanup and favicon

This commit is contained in:
Dorian Zedler 2023-03-11 21:44:17 +01:00
parent e12bec0b13
commit 3d32fa6bd8
Signed by: dozedler
GPG key ID: 989DE36109AFA354
5 changed files with 197 additions and 141 deletions

26
src/routes/favicon.rs Normal file
View file

@ -0,0 +1,26 @@
use axum::{routing::get, Router};
use cairo::{Context, Format, ImageSurface};
use crate::{polygon, SharedState};
async fn handler() -> impl axum::response::IntoResponse {
let surface = ImageSurface::create(Format::ARgb32, 100, 100).unwrap();
let context = Context::new(&surface).unwrap();
context.set_source_rgba(0.0, 0.0, 0.0, 0.0);
context.fill().unwrap();
polygon::draw_polygon_of_polygons((50.0, 50.0), 65.0, 6, &context, false);
let mut data: Vec<u8> = Vec::new();
surface.write_to_png(&mut data).unwrap();
(
axum::response::AppendHeaders([(axum::http::header::CONTENT_TYPE, "image/png")]),
data,
)
}
pub fn routes() -> Router<SharedState> {
Router::new().route("/", get(handler))
}

42
src/routes/logo.rs Normal file
View file

@ -0,0 +1,42 @@
use axum::{extract::Query, routing::get, Router};
use cairo::{Context, Format, ImageSurface};
use serde::Deserialize;
use crate::{polygon, SharedState};
fn default_as_false() -> bool {
false
}
#[derive(Deserialize)]
struct ImageProperties {
#[serde(default = "default_as_false")]
dark_mode: bool,
}
async fn handler(Query(properties): Query<ImageProperties>) -> impl axum::response::IntoResponse {
let surface = ImageSurface::create(Format::ARgb32, 400, 400).unwrap();
let context = Context::new(&surface).unwrap();
if properties.dark_mode {
context.set_source_rgb(0.0, 0.0, 0.0);
} else {
context.set_source_rgb(1.0, 1.0, 1.0);
}
context.paint().unwrap();
polygon::draw_polygon_of_polygons((200.0, 200.0), 200.0, 6, &context, properties.dark_mode);
let mut data: Vec<u8> = Vec::new();
surface.write_to_png(&mut data).unwrap();
(
axum::response::AppendHeaders([(axum::http::header::CONTENT_TYPE, "image/png")]),
data,
)
}
pub fn routes() -> Router<SharedState> {
Router::new().route("/", get(handler))
}

2
src/routes/mod.rs Normal file
View file

@ -0,0 +1,2 @@
pub mod favicon;
pub mod logo;