Feat: cleanup and favicon
This commit is contained in:
parent
e12bec0b13
commit
3d32fa6bd8
5 changed files with 197 additions and 141 deletions
26
src/routes/favicon.rs
Normal file
26
src/routes/favicon.rs
Normal 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
42
src/routes/logo.rs
Normal 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
2
src/routes/mod.rs
Normal file
|
@ -0,0 +1,2 @@
|
|||
pub mod favicon;
|
||||
pub mod logo;
|
Loading…
Add table
Add a link
Reference in a new issue