diff --git a/src/bin/frontend/http_fe/mod.rs b/src/bin/frontend/http_fe/mod.rs index b5b1e1c..1972446 100644 --- a/src/bin/frontend/http_fe/mod.rs +++ b/src/bin/frontend/http_fe/mod.rs @@ -31,7 +31,7 @@ use std::{ }; use typed_path::{Utf8Component, Utf8UnixComponent, Utf8UnixPath, Utf8UnixPathBuf}; -use mintee::util::yapper::{eyap, yap}; +use mintee::{backend::{self, render::{Page, Repo, Revision}}, util::yapper::{eyap, yap}}; pub use super::manager::{Frontend, FrontendImpl}; @@ -210,11 +210,11 @@ impl fmt::Display for ResponseStatus<'_> { } } -#[derive(Debug, Clone)] +#[derive(Debug)] pub struct Response<'a> { pub status: Option>, pub headers: Vec<(&'a str, String)>, - pub body: Option<&'a [u8]>, + pub body: Vec, } impl Response<'_> { @@ -222,7 +222,7 @@ impl Response<'_> { Self { status: None, headers: Default::default(), - body: None, + body: Default::default(), } } } @@ -248,7 +248,7 @@ impl<'a> From<&Response<'a>> for Vec { }, ), b"\r\n", - val.body.unwrap_or_default(), + &val.body, ] .concat() } @@ -381,7 +381,7 @@ impl<'a> ReqResp<'a> for (Request<'a>, Response<'_>) { ("x-test1", "test1".to_string()), ("x-test2", "test2".to_string()), ]; - response.body = Some(b"totally cool and swag homepage"); + response.body = b"totally cool and swag homepage".to_vec(); self } else { response.status = Some(MethodNotAllowed { allow: vec![GET] }); @@ -407,9 +407,16 @@ impl<'a> ReqResp<'a> for (Request<'a>, Response<'_>) { self } } - (method, ["/", user, repo], _, _) if let Some(user) = user.strip_prefix('~') => { + (method, ["/", user, repo], params, _) if let Some(user) = user.strip_prefix('~') => { if matches!(method, GET) { - todo!() + let revision = match params.as_ref().and_then(|x| x.iter().filter_map(|y| ["branch", "commit", "tag"].contains(&y.0).then(|| y)).last()) { + Some(("branch", branch)) => Some(Revision::Branch(branch.to_string())), + Some(("commit", commit)) => Some(Revision::Commit(commit.to_string())), + Some(("tag", tag)) => Some(Revision::Tag(tag.to_string())), + _ => None + }; + Page::new(backend::render::PageKind::Repo(Repo::new(user.to_string(), repo.to_string(), revision, None)), None).render(&mut response.body).unwrap(); + self } else { response.status = Some(MethodNotAllowed { allow: vec![GET] }); self