#[get("/hello/{name}")]
async fn greet(name: web::Path<String>, req: HttpRequest) -> impl Responder {
println!("{:?}", req);
- format!("Hello {name}!")
+ format!("Hello {name}!\n{:?}", req.headers().get("user-agent"))
}
fn rgb_encode_to_canvas(mut canvas: Canvas, data: &mut dyn Iterator<Item = u8>) -> Result<Canvas, ImageError> {
.body(cursor.into_inner()))
}
+#[get("/gen/2/{dim_x}/{dim_y}/{scale}")]
+async fn img_gen2(req: HttpRequest, path: web::Path<(u32, u32, u32)>) -> Result<impl Responder> {
+ let (dim_x, dim_y, scale) = path.into_inner();
+ let data = match req.headers().get("user-agent") {
+ Some(header) => header.to_str().unwrap_or(""),
+ _ => ""
+ };
+ let cursor = make_png(dim_x, dim_y, scale, &mut data.bytes())?;
+ Ok(HttpResponse::build(StatusCode::OK)
+ .content_type("image/png")
+ .body(cursor.into_inner()))
+}
+
#[get("/pgen/0/{data}")]
async fn img_pgen0(req: HttpRequest, canvas0: web::Data<Arc<Mutex<Canvas0>>>) -> Result<impl Responder> {
let data = req.uri().path().split("/").skip(3).next().unwrap();
.body(cursor.into_inner()))
}
+#[get("/pgen/2/{dim_x}/{dim_y}/{scale}")]
+async fn img_pgen2(req: HttpRequest, path: web::Path<(u32, u32, u32)>, canvas1: web::Data<Arc<Mutex<Canvas1>>>) -> Result<impl Responder> {
+ let (dim_x, dim_y, scale) = path.into_inner();
+ let data = match req.headers().get("user-agent") {
+ Some(header) => header.to_str().unwrap_or(""),
+ _ => ""
+ };
+ let img: RgbImage = ({
+ let canvas_option = &mut *canvas1.lock().unwrap();
+ Ok(apply_to_canvas( |c, d| to_canvasresult(rgb_encode_to_canvas(c, d)), &mut canvas_option.0, Some((dim_x, dim_y)), data)?.img.clone())
+ } as Result<RgbImage, CanvasError>)?;
+ let cursor = image_to_cursor(img, scale)?;
+ Ok(HttpResponse::build(StatusCode::OK)
+ .content_type("image/png")
+ .body(cursor.into_inner()))
+}
+
#[get("/pdrop/{canvas_id}")]
async fn pdrop(canvas_id: web::Path<u8>, canvas0: web::Data<Arc<Mutex<Canvas0>>>, canvas1: web::Data<Arc<Mutex<Canvas1>>>) -> Result<impl Responder> {
let canvas_id = canvas_id.into_inner();
.service(greet)
.service(img_gen0)
.service(img_gen1)
+ .service(img_gen2)
.service(img_pgen0)
.service(img_pgen1)
+ .service(img_pgen2)
.service(pdrop)
.app_data(web::Data::new(canvas0.clone()))
.app_data(web::Data::new(canvas1.clone()))