mirror of
https://forge.pointfixe.fr/hubert/gitust.git
synced 2026-02-04 19:07:29 +01:00
save
This commit is contained in:
28
src/main.rs
28
src/main.rs
@@ -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")]
|
||||
|
||||
Reference in New Issue
Block a user