From ffeba7e69c143689f90f40a506fddec11b000cf0 Mon Sep 17 00:00:00 2001 From: Hubert Date: Wed, 7 Jul 2021 06:49:53 +0200 Subject: [PATCH] query --- Cargo.toml | 1 + src/main.rs | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5b5e45b..73b9b0e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,3 +14,4 @@ actix-files = "0.5.0" askama = "0.10.5" askama_actix = "0.11.1" env_logger = "0.8.4" +serde = "1.0.126" diff --git a/src/main.rs b/src/main.rs index 4cef649..af5e454 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,6 +17,7 @@ use env_logger::Env; use crate::ite::SuperIterator; use std::ops::Add; use std::path::{PathBuf, Path}; +use serde::Deserialize; #[derive(Template)] #[template(path = "hello.html")] @@ -83,8 +84,24 @@ async fn hello_auth(req : HttpRequest) -> impl Responder { } } -#[get("/git/{owner}/{repo}/{commit}/{path:.*}")] -async fn git_main(web::Path((owner, reponame, commitname, rootname)): web::Path<(String, String, String, String)>) -> impl Responder { + +#[derive(Deserialize)] +struct GitWebQ { + commit: Option, + path: Option, +} + + +#[get("/git/{owner}/{repo}.git")] +async fn git_main(web::Path((owner, reponame)): web::Path<(String, String)>, web::Query(GitWebQ{commit : commitnameopt, path : pathopt}) : web::Query) -> impl Responder { + let commitname = match commitnameopt { + None => {"master".to_string()} + Some(s) => {s} + }; + let rootname = match pathopt { + None => {"/".to_string()} + Some(s) => {s} + }; let repo = GitRepo::new(); let path : Vec<(String, String)> = rootname.split("/").map_accum("/git/".to_string() + &owner + "/" + &reponame + "/" + &commitname, |str_ref, b| { let href = b + "/" + str_ref;