refactorisation in files

This commit is contained in:
2021-07-19 13:30:25 +02:00
parent a562c4616c
commit 1950a5312e
9 changed files with 32 additions and 26 deletions

View File

@@ -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<GitWebQ>,
gitust : web::Data<Gitust>
webx::Path((ownername, reponame)): webx::Path<(String, String)>,
webx::Query(GitWebQ{commit : commitnameopt, path : pathopt, branch : branchopt}) : webx::Query<GitWebQ>,
gitust : webx::Data<Gitust>,
auth : Option<BasicAuth>,
//auth : BasicAuth,
) -> Result<GitMainTemplate<Vec<Entry>, 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>,
gitust : webx::Data<Gitust>,
auth : BasicAuth,
) -> io::Result<HttpResponse>{
//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()