From 93b211f7435091f616be5c7d1ec493e9a3c18419 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Th=C3=A9riault?= Date: Mon, 9 Mar 2020 15:22:13 -0400 Subject: [PATCH] ID conversion route --- src/main.rs | 1 + src/routes.rs | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/src/main.rs b/src/main.rs index 2a13af0..37582b4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -57,6 +57,7 @@ async fn main() { .route("/", web::get().to(routes::index)) .route("/logout", web::get().to(routes::logout)) .route("/config", web::get().to(routes::get_config)) + .route("/id/{id}", web::get().to(routes::id_to_str)) .service( web::resource("/f") .route(web::get().to(routes::files::select)) diff --git a/src/routes.rs b/src/routes.rs index d066ec2..07c0af8 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -252,6 +252,14 @@ pub async fn logout(identity: Identity) -> impl Responder { } } +pub async fn id_to_str(path: web::Path) -> impl Responder { + let id: i32 = match path.parse() { + Ok(id) => id, + Err(_) => return Err(HttpResponse::BadRequest().body("Invalid ID")), + }; + Ok(HttpResponse::Ok().body(radix_fmt::radix_36(id).to_string())) +} + pub mod files { use crate::routes::match_replace_result; use crate::{