This commit is contained in:
2021-07-02 06:31:43 +02:00
parent 4ac443c986
commit a2e7be3d7c
3 changed files with 46 additions and 8 deletions

View File

@@ -23,16 +23,29 @@ struct HelloTemplate<'a> {
name: &'a str,
}
struct User {
name : String,
}
struct Owner {
name : String,
}
struct Repository {
name : String,
owner : Owner,
}
#[derive(Template)]
#[template(path = "git.html")]
struct GitMainTemplate<TS, ROOT>
where for <'a> &'a TS : IntoIterator<Item = &'a GitBrowseEntry>,
for <'a> &'a ROOT : IntoIterator<Item = &'a (String, String)>,
{
user: String,
repo : String,
repo : Repository,
browse : TS,
root : ROOT,
user_opt : Option<User>,
}
#[get("/")]
@@ -69,17 +82,20 @@ async fn hello_auth(req : HttpRequest) -> impl Responder {
}
}
#[get("/git/{user}/{repo}/{commit}/{path:.*}")]
async fn git_main(web::Path((user, reponame, commitname, rootname)): web::Path<(String, String, String, String)>) -> 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 {
let repo = GitRepo::new();
let path : Vec<(String, String)> = rootname.split("/").map_accum("/git/".to_string() + &user + "/" + &reponame + "/" + &commitname, |str_ref, b| {
let path : Vec<(String, String)> = rootname.split("/").map_accum("/git/".to_string() + &owner + "/" + &reponame + "/" + &commitname, |str_ref, b| {
let href = b + "/" + str_ref;
((str_ref.to_string(), href.clone()), href)
}).collect();
let commit = GitCommit::new(commitname);
let root = GitBrowseDir::new(rootname);
let browse = repo.browse(&commit, &root).await;
GitMainTemplate { user, repo : reponame, browse : browse, root : path}
let owner = Owner { name : owner};
let repo = Repository {name : reponame, owner};
let user = User { name : "Hubert".to_string()};
GitMainTemplate { repo, browse : browse, root : path, user_opt : Some(user)}
}
#[post("/echo")]