♻️ refactor
All checks were successful
ci/woodpecker/push/build Pipeline was successful

This commit is contained in:
JMARyA 2025-03-04 19:02:05 +01:00
parent 1815d9f461
commit af7b74319a
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
8 changed files with 205 additions and 177 deletions

View file

@ -1,7 +1,7 @@
use based::asset::AssetRoutes;
use based::auth::User;
use based::get_pg;
use based::ui::components::Shell;
use based::ui::components::prelude::Shell;
use based::ui::prelude::*;
use config::Config;
use rocket::routes;

View file

@ -429,6 +429,20 @@ impl Package {
versions
}
pub fn pkg_content_path(&self) -> Option<String> {
if self.exists() {
return Some(
self.base_path()
.join(self.file_name())
.to_str()
.unwrap()
.to_string(),
);
}
None
}
/// Get the content of the `.pkg.tar.zst`
pub fn pkg_content(&self) -> Option<Vec<u8>> {
if self.exists() {

View file

@ -1,6 +1,7 @@
use based::auth::MaybeUser;
use based::request::assets::DataResponse;
use based::request::{RawResponse, RequestContext, StringResponse, respond_with};
use based::ui::components::Shell;
use based::ui::components::prelude::Shell;
use based::ui::prelude::*;
use maud::{Render, html};
use pacco::pkg::mirror::MirrorRepository;
@ -69,27 +70,30 @@ pub async fn pkg_route(
arch: &str,
pkg_name: &str,
config: &State<Config>,
) -> RawResponse {
) -> DataResponse {
let arch = Architecture::parse(arch).unwrap();
let cache_duration = Some(60 * 60 * 24);
if config.is_mirrored_repo(repo) {
let repo = MirrorRepository::new(repo);
if is_repo_db(pkg_name) {
// TODO : Impl db cache (valid for 5min example)
if pkg_name.ends_with("sig") {
return respond_with(
Status::Ok,
ContentType::new("application", "pgp-signature"),
return DataResponse::new(
repo.sig_content(arch, config.mirrorlist().unwrap())
.await
.unwrap(),
"application/pgp-signature".to_string(),
cache_duration,
);
} else {
return respond_with(
Status::Ok,
ContentType::new("application", "tar"),
return DataResponse::new(
repo.db_content(arch, config.mirrorlist().unwrap())
.await
.unwrap(),
"application/tar".to_string(),
cache_duration,
);
}
}
@ -101,39 +105,39 @@ pub async fn pkg_route(
if pkg_name.ends_with("pkg.tar.zst") {
pkg.increase_download_count().await;
return respond_with(
Status::Ok,
ContentType::new("application", "tar"),
pkg.pkg_content().unwrap(),
return DataResponse::new_file(
&pkg.pkg_content_path().unwrap(),
"application/tar".to_string(),
cache_duration,
);
} else if pkg_name.ends_with("pkg.tar.zst.sig") {
return respond_with(
Status::Ok,
ContentType::new("application", "pgp-signature"),
return DataResponse::new(
pkg.sig_content().unwrap(),
"application/pgp-signature".to_string(),
cache_duration,
);
}
return respond_with(
Status::Ok,
ContentType::Plain,
return DataResponse::new(
"Not found".as_bytes().to_vec(),
"text/plain".to_string(),
cache_duration,
);
}
if let Some(repo) = Repository::new(repo) {
if is_repo_db(pkg_name) {
if pkg_name.ends_with("sig") {
return respond_with(
Status::Ok,
ContentType::new("application", "pgp-signature"),
return DataResponse::new(
repo.sig_content(arch).unwrap(),
"application/pgp-signature".to_string(),
cache_duration,
);
} else {
return respond_with(
Status::Ok,
ContentType::new("application", "tar"),
return DataResponse::new(
repo.db_content(arch).unwrap(),
"application/tar".to_string(),
cache_duration,
);
}
}
@ -141,24 +145,24 @@ pub async fn pkg_route(
let pkg = repo.get_pkg(pkg_name).unwrap();
if pkg_name.ends_with("pkg.tar.zst") {
return respond_with(
Status::Ok,
ContentType::new("application", "tar"),
pkg.pkg_content().unwrap(),
return DataResponse::new_file(
&pkg.pkg_content_path().unwrap(),
"application/tar".to_string(),
cache_duration,
);
} else if pkg_name.ends_with("pkg.tar.zst.sig") {
return respond_with(
Status::Ok,
ContentType::new("application", "pgp-signature"),
return DataResponse::new(
pkg.sig_content().unwrap(),
"application/pgp-signature".to_string(),
cache_duration,
);
}
}
respond_with(
Status::Ok,
ContentType::Plain,
DataResponse::new(
"Not found".as_bytes().to_vec(),
"text/plain".to_string(),
cache_duration,
)
}

View file

@ -1,5 +1,5 @@
use based::request::{RequestContext, StringResponse};
use based::ui::components::Shell;
use based::ui::components::prelude::Shell;
use based::ui::primitives::flex::Strategy;
use based::ui::primitives::space::SpaceBetweenWidget;
use based::ui::primitives::text::{Code, TextWidget};
@ -562,7 +562,8 @@ pub fn InfoCard<T: UIWidget + 'static>(inner: T) -> SpaceBetweenWidget {
}
pub fn pkg_list_info(key: &str, value: &str) -> PreEscaped<String> {
let pkgs = value.split_whitespace().map(|pkg| {
// TODO : Impl opt deps
let pkgs = value.split(';').map(|pkg| {
if let Some(pkg_url) = find_pkg_url(pkg) {
Margin(Link(&pkg_url, Text(&pkg).color(&Blue::_400)).use_htmx()).left(ScreenValue::_6)
} else {

View file

@ -1,7 +1,8 @@
use based::request::{RequestContext, StringResponse};
use based::ui::components::Shell;
use based::ui::components::prelude::Shell;
use based::ui::prelude::*;
use maud::{PreEscaped, Render, html};
use pacco::pkg::package::PackageMetaInfo;
use rocket::{State, get};
use pacco::pkg::{Repository, arch::Architecture};
@ -9,11 +10,12 @@ use pacco::pkg::{Repository, arch::Architecture};
use crate::config::Config;
use crate::routes::ui::arch_card;
#[get("/<repo>?<arch>")]
#[get("/<repo>?<arch>&<sort>")]
pub async fn repo_ui(
repo: &str,
ctx: RequestContext,
arch: Option<&str>,
sort: Option<&str>,
config: &State<Config>,
shell: &State<Shell>,
) -> StringResponse {
@ -27,6 +29,8 @@ pub async fn repo_ui(
repo.list_pkg()
};
// TODO : sortable pkg list
// Repository name and architectures
let repo_info = Margin(
Flex(

View file

@ -1,7 +1,7 @@
use based::{
auth::{Session, Sessions, User, csrf::CSRF},
request::{RequestContext, StringResponse, api::to_uuid, respond_html},
ui::{AttrExtendable, components::Shell},
ui::{AttrExtendable, components::prelude::Shell},
};
use maud::{PreEscaped, html};
use rocket::{