basic http_fe integration of backend
This commit is contained in:
@@ -31,7 +31,7 @@ use std::{
|
|||||||
};
|
};
|
||||||
use typed_path::{Utf8Component, Utf8UnixComponent, Utf8UnixPath, Utf8UnixPathBuf};
|
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};
|
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 struct Response<'a> {
|
||||||
pub status: Option<ResponseStatus<'a>>,
|
pub status: Option<ResponseStatus<'a>>,
|
||||||
pub headers: Vec<(&'a str, String)>,
|
pub headers: Vec<(&'a str, String)>,
|
||||||
pub body: Option<&'a [u8]>,
|
pub body: Vec<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Response<'_> {
|
impl Response<'_> {
|
||||||
@@ -222,7 +222,7 @@ impl Response<'_> {
|
|||||||
Self {
|
Self {
|
||||||
status: None,
|
status: None,
|
||||||
headers: Default::default(),
|
headers: Default::default(),
|
||||||
body: None,
|
body: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -248,7 +248,7 @@ impl<'a> From<&Response<'a>> for Vec<u8> {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
b"\r\n",
|
b"\r\n",
|
||||||
val.body.unwrap_or_default(),
|
&val.body,
|
||||||
]
|
]
|
||||||
.concat()
|
.concat()
|
||||||
}
|
}
|
||||||
@@ -381,7 +381,7 @@ impl<'a> ReqResp<'a> for (Request<'a>, Response<'_>) {
|
|||||||
("x-test1", "test1".to_string()),
|
("x-test1", "test1".to_string()),
|
||||||
("x-test2", "test2".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
|
self
|
||||||
} else {
|
} else {
|
||||||
response.status = Some(MethodNotAllowed { allow: vec![GET] });
|
response.status = Some(MethodNotAllowed { allow: vec![GET] });
|
||||||
@@ -407,9 +407,16 @@ impl<'a> ReqResp<'a> for (Request<'a>, Response<'_>) {
|
|||||||
self
|
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) {
|
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 {
|
} else {
|
||||||
response.status = Some(MethodNotAllowed { allow: vec![GET] });
|
response.status = Some(MethodNotAllowed { allow: vec![GET] });
|
||||||
self
|
self
|
||||||
|
|||||||
Reference in New Issue
Block a user