From: MegaBrutal Date: Sat, 25 Jun 2022 22:45:00 +0000 (+0200) Subject: Implement /gen/1 X-Git-Url: http://git.megabrutal.com/?p=litoprism.git;a=commitdiff_plain;h=7f15d921bf3b6ddf74f4cc4677a66944e306cb51 Implement /gen/1 --- diff --git a/src/main.rs b/src/main.rs index 7b0f6b5..f46e88f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,7 +8,7 @@ use percent_encoding::percent_decode_str; use actix_web::{get, web, App, HttpServer, HttpRequest, HttpResponse, Responder, ResponseError, Result}; use actix_web::body::BoxBody; use actix_web::http::StatusCode; -use image::{ImageBuffer, ColorType, Pixel, Rgb, RgbImage, write_buffer_with_format}; +use image::{ImageBuffer, ColorType, Rgb, RgbImage, write_buffer_with_format}; use image::ImageOutputFormat::Png; use image::imageops::{FilterType, resize}; @@ -97,8 +97,13 @@ async fn img_gen0(req: HttpRequest) -> Result { } #[get("/gen/1/{dim_x}/{dim_y}/{scale}/{data}")] -async fn img_gen1(req: HttpRequest, dim_x: web::Path, dim_y: web::Path, scale: web::Path) -> Result { - Ok(HttpResponse::build(StatusCode::OK)) +async fn img_gen1(req: HttpRequest, path: web::Path<(u32, u32, u32)>) -> Result { + let (dim_x, dim_y, scale) = path.into_inner(); + let data = req.uri().path().split("/").skip(6).next().unwrap(); + let cursor = make_png(dim_x, dim_y, scale, percent_decode_str(&data).into_iter().borrow_mut())?; + Ok(HttpResponse::build(StatusCode::OK) + .content_type("image/png") + .body(cursor.into_inner())) } #[actix_web::main] // or #[tokio::main]