From 7f15d921bf3b6ddf74f4cc4677a66944e306cb51 Mon Sep 17 00:00:00 2001 From: MegaBrutal Date: Sun, 26 Jun 2022 00:45:00 +0200 Subject: [PATCH] Implement /gen/1 --- src/main.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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] -- 2.34.1