This commit is contained in:
JMARyA 2024-12-26 00:37:50 +01:00
commit 221b2a82e7
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
7 changed files with 3817 additions and 0 deletions

72
src/routes/mod.rs Normal file
View file

@ -0,0 +1,72 @@
use based::page::{Shell, render_page};
use based::request::{RawResponse, RequestContext, StringResponse, respond_with};
use maud::html;
use rocket::get;
use rocket::http::{ContentType, Status};
use crate::pkg::Repository;
// /pkg/<repo>/<arch>/<pkg_name>
// /pkg/<repo>/<arch>/
#[get("/pkg/<repo>/<arch>/<pkg_name>")]
pub async fn pkg_route(repo: &str, arch: &str, pkg_name: &str, ctx: RequestContext) -> RawResponse {
if let Some(repo) = Repository::new(repo) {
if pkg_name.ends_with("db.tar.gz")
|| pkg_name.ends_with("db")
|| pkg_name.ends_with("db.tar.gz.sig")
|| pkg_name.ends_with("db.sig")
{
if pkg_name.ends_with("sig") {
return respond_with(
Status::Ok,
ContentType::new("application", "pgp-signature"),
repo.sig_content(arch).unwrap(),
);
} else {
return respond_with(
Status::Ok,
ContentType::new("application", "tar"),
repo.db_content(arch).unwrap(),
);
}
}
let pkg = repo.get_pkg(arch, pkg_name).unwrap();
if pkg_name.ends_with("pkg.tar.zst") {
return respond_with(
Status::Ok,
ContentType::new("application", "tar"),
pkg.pkg_content().unwrap(),
);
} else if pkg_name.ends_with("pkg.tar.zst.sig") {
return respond_with(
Status::Ok,
ContentType::new("application", "pgp-signature"),
pkg.sig_content().unwrap(),
);
}
}
respond_with(
Status::Ok,
ContentType::Plain,
"Not found".as_bytes().to_vec(),
)
}
#[get("/")]
pub async fn index_page(ctx: RequestContext) -> StringResponse {
let content = html!(
h1 { "Hello World!" };
);
render_page(
content,
"Hello World",
ctx,
&Shell::new(html! {}, html! {}, Some(String::new())),
)
.await
}