diff --git a/src/git.rs b/src/git.rs index 28a4ea6..d808d8e 100644 --- a/src/git.rs +++ b/src/git.rs @@ -3,8 +3,8 @@ use std::ops::Add; use git2::{Commit, ObjectType, Oid, Reference, Repository, Tree}; -use crate::gitdir::GitDir; -use crate::gitfile::GitFile; +use crate::gitutils::gitdir::GitDir; +use crate::gitutils::gitfile::GitFile; #[derive(Debug)] pub enum GitBrowseEntry<'a> { diff --git a/src/gitcommit.rs b/src/gitutils/gitcommit.rs similarity index 100% rename from src/gitcommit.rs rename to src/gitutils/gitcommit.rs diff --git a/src/gitdir.rs b/src/gitutils/gitdir.rs similarity index 100% rename from src/gitdir.rs rename to src/gitutils/gitdir.rs diff --git a/src/gitfile.rs b/src/gitutils/gitfile.rs similarity index 100% rename from src/gitfile.rs rename to src/gitutils/gitfile.rs diff --git a/src/gitrepo.rs b/src/gitutils/gitrepo.rs similarity index 96% rename from src/gitrepo.rs rename to src/gitutils/gitrepo.rs index 2db541c..a47dc5f 100644 --- a/src/gitrepo.rs +++ b/src/gitutils/gitrepo.rs @@ -3,9 +3,9 @@ use std::ops::Add; use git2::{ObjectType, Oid, Repository, BranchType}; use crate::git::GitBrowseEntry; -use crate::gitcommit::GitRef; -use crate::gitdir::GitDir; -use crate::gitfile::GitFile; +use crate::gitutils::gitcommit::GitRef; +use crate::gitutils::gitdir::GitDir; +use crate::gitutils::gitfile::GitFile; use std::path::{PathBuf, Path}; use std::str::FromStr; diff --git a/src/gitutils/mod.rs b/src/gitutils/mod.rs new file mode 100644 index 0000000..0ba6f8c --- /dev/null +++ b/src/gitutils/mod.rs @@ -0,0 +1,4 @@ +pub mod gitdir; +pub mod gitrepo; +pub mod gitcommit; +pub mod gitfile; diff --git a/src/main.rs b/src/main.rs index 580cca0..9d7c4b6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,13 +7,14 @@ use std::process::Stdio; use actix_files::Files; 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::dev::ServiceRequest; use actix_web::http::{header, StatusCode}; use actix_web::http::header::Header; use actix_web::http::header::IntoHeaderValue; use actix_web::middleware::Logger; +use actix_web::web as webx; use actix_web::web::{Buf, Bytes}; use actix_web_httpauth::extractors::AuthenticationError; use actix_web_httpauth::extractors::basic::{BasicAuth, Config}; @@ -27,27 +28,25 @@ use serde::Deserialize; use tokio::io::{AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader}; use tokio::process::{Child, ChildStdout, Command}; -use gitcommit::GitRef; -use gitdir::GitDir; -use gitrepo::GitRepo; +use gitutils::gitcommit::GitRef; +use gitutils::gitdir::GitDir; +use gitutils::gitfile::GitFile; +use gitutils::gitrepo::GitRepo; use crate::git::GitBrowseEntry; use crate::gitust::Gitust; use crate::ite::SuperIterator; use crate::reader::ToStream; use crate::writer::Writer; -use crate::gitfile::GitFile; mod git; mod ite; mod reader; mod writer; mod gitust; -mod gitdir; -mod gitrepo; -mod gitcommit; -mod gitfile; mod error; +mod web; +mod gitutils; #[derive(Template)] #[template(path = "hello.html")] @@ -148,9 +147,11 @@ async fn chunk() -> HttpResponse { #[get("/git/{owner}/{repo}.git")] async fn git_main( - web::Path((ownername, reponame)): web::Path<(String, String)>, - web::Query(GitWebQ{commit : commitnameopt, path : pathopt, branch : branchopt}) : web::Query, - gitust : web::Data + webx::Path((ownername, reponame)): webx::Path<(String, String)>, + webx::Query(GitWebQ{commit : commitnameopt, path : pathopt, branch : branchopt}) : webx::Query, + gitust : webx::Data, + auth : Option, + //auth : BasicAuth, ) -> Result, Vec<(String, String)>>, error::Error> { let rootname = match pathopt { None => {"".to_string()} @@ -197,10 +198,10 @@ async fn git_main( } //#[get("/git/{owner}/{repo}.git/{path:.*}")] async fn git_proto( - mut payload : web::Payload, - web::Path((owner, reponame, path)): web::Path<(String, String, String)>, + mut payload : webx::Payload, + webx::Path((owner, reponame, path)): webx::Path<(String, String, String)>, mut req: HttpRequest, - gitust : web::Data, + gitust : webx::Data, auth : BasicAuth, ) -> io::Result{ //println!("enter git_proto"); @@ -294,7 +295,7 @@ async fn manual_hello() -> impl Responder { } #[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) } @@ -351,14 +352,14 @@ async fn main() -> std::io::Result<()> { // .route("/", web::get().to(hello_auth)) // ) .service( - web::resource("/auth") + webx::resource("/auth") .wrap(auth) - .route(web::get().to(hello_auth)) + .route(webx::get().to(hello_auth)) ) .service( - web::resource("/git/{user}/{repo}.git/{path:.*}") + webx::resource("/git/{user}/{repo}.git/{path:.*}") // .wrap(auth) - .route(web::route().to(git_proto)) + .route(webx::route().to(git_proto)) ) .service( Files::new("/static", "static") @@ -366,7 +367,7 @@ async fn main() -> std::io::Result<()> { .use_etag(true) // .show_files_listing() ) - .route("/hey", web::get().to(manual_hello)) + .route("/hey", webx::get().to(manual_hello)) }) .bind("127.0.0.1:8080")? .run() diff --git a/src/web/mod.rs b/src/web/mod.rs new file mode 100644 index 0000000..ffdecad --- /dev/null +++ b/src/web/mod.rs @@ -0,0 +1 @@ +mod repo; \ No newline at end of file diff --git a/src/web/repo.rs b/src/web/repo.rs new file mode 100644 index 0000000..e69de29