refactorisation in files
This commit is contained in:
parent
a562c4616c
commit
1950a5312e
|
@ -3,8 +3,8 @@ use std::ops::Add;
|
||||||
|
|
||||||
use git2::{Commit, ObjectType, Oid, Reference, Repository, Tree};
|
use git2::{Commit, ObjectType, Oid, Reference, Repository, Tree};
|
||||||
|
|
||||||
use crate::gitdir::GitDir;
|
use crate::gitutils::gitdir::GitDir;
|
||||||
use crate::gitfile::GitFile;
|
use crate::gitutils::gitfile::GitFile;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum GitBrowseEntry<'a> {
|
pub enum GitBrowseEntry<'a> {
|
||||||
|
|
|
@ -3,9 +3,9 @@ use std::ops::Add;
|
||||||
use git2::{ObjectType, Oid, Repository, BranchType};
|
use git2::{ObjectType, Oid, Repository, BranchType};
|
||||||
|
|
||||||
use crate::git::GitBrowseEntry;
|
use crate::git::GitBrowseEntry;
|
||||||
use crate::gitcommit::GitRef;
|
use crate::gitutils::gitcommit::GitRef;
|
||||||
use crate::gitdir::GitDir;
|
use crate::gitutils::gitdir::GitDir;
|
||||||
use crate::gitfile::GitFile;
|
use crate::gitutils::gitfile::GitFile;
|
||||||
use std::path::{PathBuf, Path};
|
use std::path::{PathBuf, Path};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
pub mod gitdir;
|
||||||
|
pub mod gitrepo;
|
||||||
|
pub mod gitcommit;
|
||||||
|
pub mod gitfile;
|
43
src/main.rs
43
src/main.rs
|
@ -7,13 +7,14 @@ use std::process::Stdio;
|
||||||
|
|
||||||
use actix_files::Files;
|
use actix_files::Files;
|
||||||
use actix_session::{CookieSession, Session};
|
use actix_session::{CookieSession, Session};
|
||||||
use actix_web::{App, Error, get, HttpMessage, HttpRequest, HttpResponse, HttpServer, post, Responder, web};
|
use actix_web::{App, Error, get, HttpMessage, HttpRequest, HttpResponse, HttpServer, post, Responder};
|
||||||
use actix_web::client::PayloadError;
|
use actix_web::client::PayloadError;
|
||||||
use actix_web::dev::ServiceRequest;
|
use actix_web::dev::ServiceRequest;
|
||||||
use actix_web::http::{header, StatusCode};
|
use actix_web::http::{header, StatusCode};
|
||||||
use actix_web::http::header::Header;
|
use actix_web::http::header::Header;
|
||||||
use actix_web::http::header::IntoHeaderValue;
|
use actix_web::http::header::IntoHeaderValue;
|
||||||
use actix_web::middleware::Logger;
|
use actix_web::middleware::Logger;
|
||||||
|
use actix_web::web as webx;
|
||||||
use actix_web::web::{Buf, Bytes};
|
use actix_web::web::{Buf, Bytes};
|
||||||
use actix_web_httpauth::extractors::AuthenticationError;
|
use actix_web_httpauth::extractors::AuthenticationError;
|
||||||
use actix_web_httpauth::extractors::basic::{BasicAuth, Config};
|
use actix_web_httpauth::extractors::basic::{BasicAuth, Config};
|
||||||
|
@ -27,27 +28,25 @@ use serde::Deserialize;
|
||||||
use tokio::io::{AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader};
|
use tokio::io::{AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader};
|
||||||
use tokio::process::{Child, ChildStdout, Command};
|
use tokio::process::{Child, ChildStdout, Command};
|
||||||
|
|
||||||
use gitcommit::GitRef;
|
use gitutils::gitcommit::GitRef;
|
||||||
use gitdir::GitDir;
|
use gitutils::gitdir::GitDir;
|
||||||
use gitrepo::GitRepo;
|
use gitutils::gitfile::GitFile;
|
||||||
|
use gitutils::gitrepo::GitRepo;
|
||||||
|
|
||||||
use crate::git::GitBrowseEntry;
|
use crate::git::GitBrowseEntry;
|
||||||
use crate::gitust::Gitust;
|
use crate::gitust::Gitust;
|
||||||
use crate::ite::SuperIterator;
|
use crate::ite::SuperIterator;
|
||||||
use crate::reader::ToStream;
|
use crate::reader::ToStream;
|
||||||
use crate::writer::Writer;
|
use crate::writer::Writer;
|
||||||
use crate::gitfile::GitFile;
|
|
||||||
|
|
||||||
mod git;
|
mod git;
|
||||||
mod ite;
|
mod ite;
|
||||||
mod reader;
|
mod reader;
|
||||||
mod writer;
|
mod writer;
|
||||||
mod gitust;
|
mod gitust;
|
||||||
mod gitdir;
|
|
||||||
mod gitrepo;
|
|
||||||
mod gitcommit;
|
|
||||||
mod gitfile;
|
|
||||||
mod error;
|
mod error;
|
||||||
|
mod web;
|
||||||
|
mod gitutils;
|
||||||
|
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
#[template(path = "hello.html")]
|
#[template(path = "hello.html")]
|
||||||
|
@ -148,9 +147,11 @@ async fn chunk() -> HttpResponse {
|
||||||
|
|
||||||
#[get("/git/{owner}/{repo}.git")]
|
#[get("/git/{owner}/{repo}.git")]
|
||||||
async fn git_main(
|
async fn git_main(
|
||||||
web::Path((ownername, reponame)): web::Path<(String, String)>,
|
webx::Path((ownername, reponame)): webx::Path<(String, String)>,
|
||||||
web::Query(GitWebQ{commit : commitnameopt, path : pathopt, branch : branchopt}) : web::Query<GitWebQ>,
|
webx::Query(GitWebQ{commit : commitnameopt, path : pathopt, branch : branchopt}) : webx::Query<GitWebQ>,
|
||||||
gitust : web::Data<Gitust>
|
gitust : webx::Data<Gitust>,
|
||||||
|
auth : Option<BasicAuth>,
|
||||||
|
//auth : BasicAuth,
|
||||||
) -> Result<GitMainTemplate<Vec<Entry>, Vec<(String, String)>>, error::Error> {
|
) -> Result<GitMainTemplate<Vec<Entry>, Vec<(String, String)>>, error::Error> {
|
||||||
let rootname = match pathopt {
|
let rootname = match pathopt {
|
||||||
None => {"".to_string()}
|
None => {"".to_string()}
|
||||||
|
@ -197,10 +198,10 @@ async fn git_main(
|
||||||
}
|
}
|
||||||
//#[get("/git/{owner}/{repo}.git/{path:.*}")]
|
//#[get("/git/{owner}/{repo}.git/{path:.*}")]
|
||||||
async fn git_proto(
|
async fn git_proto(
|
||||||
mut payload : web::Payload,
|
mut payload : webx::Payload,
|
||||||
web::Path((owner, reponame, path)): web::Path<(String, String, String)>,
|
webx::Path((owner, reponame, path)): webx::Path<(String, String, String)>,
|
||||||
mut req: HttpRequest,
|
mut req: HttpRequest,
|
||||||
gitust : web::Data<Gitust>,
|
gitust : webx::Data<Gitust>,
|
||||||
auth : BasicAuth,
|
auth : BasicAuth,
|
||||||
) -> io::Result<HttpResponse>{
|
) -> io::Result<HttpResponse>{
|
||||||
//println!("enter git_proto");
|
//println!("enter git_proto");
|
||||||
|
@ -294,7 +295,7 @@ async fn manual_hello() -> impl Responder {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/{id}/{name}/index.html")]
|
#[get("/{id}/{name}/index.html")]
|
||||||
async fn index(web::Path((id, name)): web::Path<(u32, String)>) -> impl Responder {
|
async fn index(webx::Path((id, name)): webx::Path<(u32, String)>) -> impl Responder {
|
||||||
format!("Hello {}! id:{}", name, id)
|
format!("Hello {}! id:{}", name, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -351,14 +352,14 @@ async fn main() -> std::io::Result<()> {
|
||||||
// .route("/", web::get().to(hello_auth))
|
// .route("/", web::get().to(hello_auth))
|
||||||
// )
|
// )
|
||||||
.service(
|
.service(
|
||||||
web::resource("/auth")
|
webx::resource("/auth")
|
||||||
.wrap(auth)
|
.wrap(auth)
|
||||||
.route(web::get().to(hello_auth))
|
.route(webx::get().to(hello_auth))
|
||||||
)
|
)
|
||||||
.service(
|
.service(
|
||||||
web::resource("/git/{user}/{repo}.git/{path:.*}")
|
webx::resource("/git/{user}/{repo}.git/{path:.*}")
|
||||||
// .wrap(auth)
|
// .wrap(auth)
|
||||||
.route(web::route().to(git_proto))
|
.route(webx::route().to(git_proto))
|
||||||
)
|
)
|
||||||
.service(
|
.service(
|
||||||
Files::new("/static", "static")
|
Files::new("/static", "static")
|
||||||
|
@ -366,7 +367,7 @@ async fn main() -> std::io::Result<()> {
|
||||||
.use_etag(true)
|
.use_etag(true)
|
||||||
// .show_files_listing()
|
// .show_files_listing()
|
||||||
)
|
)
|
||||||
.route("/hey", web::get().to(manual_hello))
|
.route("/hey", webx::get().to(manual_hello))
|
||||||
})
|
})
|
||||||
.bind("127.0.0.1:8080")?
|
.bind("127.0.0.1:8080")?
|
||||||
.run()
|
.run()
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
mod repo;
|
Loading…
Reference in New Issue