This commit is contained in:
Hubert 2021-07-24 07:07:03 +02:00
parent edf6f9f81a
commit dbba11a416
1 changed files with 5 additions and 4 deletions

View File

@ -63,7 +63,7 @@ pub struct GitWebQ {
//#[get("/git/{owner}/{repo}.git")]
pub async fn git_main<T : AuthValidator>(
web::Path((ownername, reponame)): web::Path<(String, String)>,
web::Query(GitWebQ{commit : commitnameopt, path : pathopt, branch : branchopt}) : web::Query<GitWebQ>,
query : web::Query<GitWebQ>,
gitust : web::Data<Gitust>,
auth : Option<basic::BasicAuth>,
validator : web::Data<T>,
@ -71,6 +71,7 @@ pub async fn git_main<T : AuthValidator>(
) -> Result<GitMainTemplate<Vec<Entry>, Vec<(String, String)>>, error::Error> {
// let authtorization = auth.ok_or(error::Error::Unauthorized("safe repo".to_string()))?;
//let authorization = auth.and_then(|cred| validator.check_basic(&cred)).ok_or(error::Error::Unauthorized("safe repo".to_string()))?;
let web::Query(GitWebQ{commit : commitnameopt, path : pathopt, branch : branchopt}) = query;
let rootname = match pathopt {
None => {"".to_string()}
Some(s) => {
@ -93,9 +94,9 @@ pub async fn git_main<T : AuthValidator>(
// let user = User { name : "Hubert".to_string()};
let user = auth.map(|auth| User{name : auth.user_id().to_string()});
// il faut ajouter le commit/branch dans la query
let path = rootname.split("/").map_accum("/git/".to_string() + &repo.owner.name + "/" + &repo.name, |str_ref, b| {
let href = b + "/" + str_ref;
((str_ref.to_string(), href.clone()), href)
let path = rootname.split("/").map_accum("/git/".to_string() + &repo.owner.name + "/" + &repo.name, |direname, b| {
let href = b + "/" + direname;
((direname.to_string(), href.clone()), href)
}).collect();
let gitrepo = GitRepo::new(format!("{}/{}/{}.git", &gitust.repo_root_path, &repo.owner.name, &repo.name).as_str())?;
let root = gitrepo.get_tree(&commit, Path::new(rootname.as_str()))?;