Compare commits
No commits in common. "ba19d67f66a51aebf7144bb46ca26cc82109c79b" and "5f6f7b7efed504edd81a4d6b971419de7338fb34" have entirely different histories.
ba19d67f66
...
5f6f7b7efe
|
@ -17,7 +17,6 @@ use crate::gitutils::gitdir::GitDir;
|
||||||
use crate::gitutils::gitfile::GitFile;
|
use crate::gitutils::gitfile::GitFile;
|
||||||
use crate::gitutils::gitrepo::GitRepo;
|
use crate::gitutils::gitrepo::GitRepo;
|
||||||
use crate::ite::SuperIterator;
|
use crate::ite::SuperIterator;
|
||||||
use std::fmt::{Display, Formatter};
|
|
||||||
|
|
||||||
struct User {
|
struct User {
|
||||||
name : String,
|
name : String,
|
||||||
|
@ -39,14 +38,13 @@ pub enum Entry {
|
||||||
|
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
#[template(path = "git.html")]
|
#[template(path = "git.html")]
|
||||||
pub struct GitMainTemplate<TS, BREADCRUMB>
|
pub struct GitMainTemplate<TS, ROOT>
|
||||||
where for <'a> &'a TS : IntoIterator<Item = &'a Entry>,
|
where for <'a> &'a TS : IntoIterator<Item = &'a Entry>,
|
||||||
for <'a> &'a BREADCRUMB: IntoIterator<Item = &'a (String, String)>,
|
for <'a> &'a ROOT : IntoIterator<Item = &'a (String, String)>,
|
||||||
{
|
{
|
||||||
repo : Repository,
|
repo : Repository,
|
||||||
browse : TS,
|
browse : TS,
|
||||||
query : GitWebQ,
|
root : ROOT,
|
||||||
breadcrumb: BREADCRUMB,
|
|
||||||
user_opt : Option<User>,
|
user_opt : Option<User>,
|
||||||
revisions_nbr : u32,
|
revisions_nbr : u32,
|
||||||
branches_nbr : u32,
|
branches_nbr : u32,
|
||||||
|
@ -55,67 +53,17 @@ where for <'a> &'a TS : IntoIterator<Item = &'a Entry>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone, Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct GitWebQ {
|
pub struct GitWebQ {
|
||||||
commit: Option<String>,
|
commit: Option<String>,
|
||||||
path: Option<String>,
|
path: Option<String>,
|
||||||
branch: Option<String>,
|
branch: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GitWebQ {
|
|
||||||
fn clone_with_commit(&self, commit : Option<String>) -> GitWebQ {
|
|
||||||
let mut res = self.clone();
|
|
||||||
res.commit = commit;
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn clone_with_path(&self, path : Option<String>) -> GitWebQ {
|
|
||||||
let mut res = self.clone();
|
|
||||||
res.path = path;
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn clone_with_branch(&self, branch : Option<String>) -> GitWebQ {
|
|
||||||
let mut res = self.clone();
|
|
||||||
res.branch = branch;
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn root_query(&self) -> GitWebQ {
|
|
||||||
self.clone_with_path(None)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn add_path(&self, name : &&String) -> GitWebQ {
|
|
||||||
match &self.path {
|
|
||||||
None => {self.clone_with_path(Some(name.to_string()))}
|
|
||||||
Some(path) => {self.clone_with_path()}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Display for GitWebQ{
|
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
||||||
write!(f, "?{}{}{}",
|
|
||||||
match &self.commit {
|
|
||||||
None => {"".to_string()}
|
|
||||||
Some(c) => {format!("commit={}", c)}
|
|
||||||
},
|
|
||||||
match &self.path {
|
|
||||||
None => {"".to_string()}
|
|
||||||
Some(p) => {format!("&path={}", p)}
|
|
||||||
},
|
|
||||||
match &self.branch {
|
|
||||||
None => {"".to_string()}
|
|
||||||
Some(b) => {format!("&branch={}", b)}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//#[get("/git/{owner}/{repo}.git")]
|
//#[get("/git/{owner}/{repo}.git")]
|
||||||
pub async fn git_main<T : AuthValidator>(
|
pub async fn git_main<T : AuthValidator>(
|
||||||
web::Path((ownername, reponame)): web::Path<(String, String)>,
|
web::Path((ownername, reponame)): web::Path<(String, String)>,
|
||||||
query : web::Query<GitWebQ>,
|
web::Query(GitWebQ{commit : commitnameopt, path : pathopt, branch : branchopt}) : web::Query<GitWebQ>,
|
||||||
gitust : web::Data<Gitust>,
|
gitust : web::Data<Gitust>,
|
||||||
auth : Option<basic::BasicAuth>,
|
auth : Option<basic::BasicAuth>,
|
||||||
validator : web::Data<T>,
|
validator : web::Data<T>,
|
||||||
|
@ -123,34 +71,31 @@ pub async fn git_main<T : AuthValidator>(
|
||||||
) -> Result<GitMainTemplate<Vec<Entry>, Vec<(String, String)>>, error::Error> {
|
) -> Result<GitMainTemplate<Vec<Entry>, Vec<(String, String)>>, error::Error> {
|
||||||
// let authtorization = auth.ok_or(error::Error::Unauthorized("safe repo".to_string()))?;
|
// 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 authorization = auth.and_then(|cred| validator.check_basic(&cred)).ok_or(error::Error::Unauthorized("safe repo".to_string()))?;
|
||||||
let web::Query(query_struct) = query;
|
let rootname = match pathopt {
|
||||||
// let GitWebQ{commit : commitnameopt, path : pathopt, branch : branchopt} = query_struct;
|
|
||||||
let rootname = match &query_struct.path {
|
|
||||||
None => {"".to_string()}
|
None => {"".to_string()}
|
||||||
Some(s) => {
|
Some(s) => {
|
||||||
if s.starts_with("/") {
|
if s.starts_with("/") {
|
||||||
(&s[1..]).to_string()
|
(&s[1..]).to_string()
|
||||||
} else {
|
} else {
|
||||||
s.clone()
|
s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let commit = match &query_struct.commit {
|
let commit = match commitnameopt {
|
||||||
None => {match &query_struct.branch {
|
None => {match branchopt {
|
||||||
None => {GitRef::Head}
|
None => {GitRef::Head}
|
||||||
Some(s) => {GitRef::Branch(s.clone())}
|
Some(s) => {GitRef::Branch(s)}
|
||||||
}}
|
}}
|
||||||
Some(s) => {GitRef::Commit(s.clone())}
|
Some(s) => {GitRef::Commit(s)}
|
||||||
};
|
};
|
||||||
let owner = Owner { name : ownername};
|
let owner = Owner { name : ownername};
|
||||||
let repo = Repository {name : reponame, owner};
|
let repo = Repository {name : reponame, owner};
|
||||||
// let user = User { name : "Hubert".to_string()};
|
// let user = User { name : "Hubert".to_string()};
|
||||||
let user = auth.map(|auth| User{name : auth.user_id().to_string()});
|
let user = auth.map(|auth| User{name : auth.user_id().to_string()});
|
||||||
// il faut ajouter le commit/branch dans la query
|
// il faut ajouter le commit/branch dans la query
|
||||||
let path = rootname.split("/").map_accum(query_struct.clone_with_path(Some("".to_string())), |direname, b| {
|
let path = rootname.split("/").map_accum("/git/".to_string() + &repo.owner.name + "/" + &repo.name, |str_ref, b| {
|
||||||
let newpath = (&b.path).as_ref().map(|path| {path.clone() + "/" + direname});
|
let href = b + "/" + str_ref;
|
||||||
let newb = b.clone_with_path(newpath);
|
((str_ref.to_string(), href.clone()), href)
|
||||||
((direname.to_string(), format!("{}", newb)), newb)
|
|
||||||
}).collect();
|
}).collect();
|
||||||
let gitrepo = GitRepo::new(format!("{}/{}/{}.git", &gitust.repo_root_path, &repo.owner.name, &repo.name).as_str())?;
|
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()))?;
|
let root = gitrepo.get_tree(&commit, Path::new(rootname.as_str()))?;
|
||||||
|
@ -171,8 +116,7 @@ pub async fn git_main<T : AuthValidator>(
|
||||||
Ok(GitMainTemplate {
|
Ok(GitMainTemplate {
|
||||||
repo,
|
repo,
|
||||||
browse : entries,
|
browse : entries,
|
||||||
query : query_struct,
|
root : path,
|
||||||
breadcrumb: path,
|
|
||||||
user_opt : user,
|
user_opt : user,
|
||||||
revisions_nbr : gitrepo.get_revisions_nbr(),
|
revisions_nbr : gitrepo.get_revisions_nbr(),
|
||||||
branches_nbr : gitrepo.get_branches_nbr(),
|
branches_nbr : gitrepo.get_branches_nbr(),
|
||||||
|
|
|
@ -60,8 +60,8 @@
|
||||||
<div class="w3-cell-row">
|
<div class="w3-cell-row">
|
||||||
<div class="w3-cell">
|
<div class="w3-cell">
|
||||||
<ul class="breadcrumb">
|
<ul class="breadcrumb">
|
||||||
<li><a href="{{query.root_query()}}">{{repo.name}}.git</a></li>
|
<li><a href="#">{{repo.name}}</a></li>
|
||||||
{% for (dir, prev) in breadcrumb %}
|
{% for (dir, prev) in root %}
|
||||||
<li><a href="{{prev}}">{{dir}}</a></li>
|
<li><a href="{{prev}}">{{dir}}</a></li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -77,7 +77,7 @@
|
||||||
{% for entry in browse %}
|
{% for entry in browse %}
|
||||||
{% match entry %}
|
{% match entry %}
|
||||||
{% when Entry::Dir with (name) %}
|
{% when Entry::Dir with (name) %}
|
||||||
<li><i class="fa fa-folder"></i> <a href="{{query.add_path(name)}}">{{ name }}</a></li>
|
<li><i class="fa fa-folder"></i> {{ name }}</li>
|
||||||
{% when Entry::File with (name) %}
|
{% when Entry::File with (name) %}
|
||||||
<li><i class="fa fa-file"></i> {{ name }}</li>
|
<li><i class="fa fa-file"></i> {{ name }}</li>
|
||||||
{% endmatch %}
|
{% endmatch %}
|
||||||
|
|
Loading…
Reference in New Issue