From 0cc7eb8f40b2158c5fffeae05ecacbcd10988003 Mon Sep 17 00:00:00 2001 From: JMARyA Date: Sun, 12 Jan 2025 04:27:50 +0100 Subject: [PATCH] update --- src/pkg/mod.rs | 1 - src/pkg/package.rs | 6 +++++- src/pkg/repo.rs | 18 ++++++++++++++++++ src/routes/ui.rs | 47 +++++++++++++++++++++++++++++----------------- src/routes/user.rs | 2 -- 5 files changed, 53 insertions(+), 21 deletions(-) diff --git a/src/pkg/mod.rs b/src/pkg/mod.rs index db303be..6d7a305 100644 --- a/src/pkg/mod.rs +++ b/src/pkg/mod.rs @@ -1,5 +1,4 @@ // TODO : Read DB Info -// TODO : Read PKG Info + Content pub mod repo; pub use repo::Repository; diff --git a/src/pkg/package.rs b/src/pkg/package.rs index 54f3a3c..e626dd7 100644 --- a/src/pkg/package.rs +++ b/src/pkg/package.rs @@ -38,7 +38,11 @@ impl Package { } pub fn file_list(&self) -> Vec { - list_tar_file(&self.base_path().join(self.file_name())).unwrap() + list_tar_file(&self.base_path().join(self.file_name())) + .unwrap() + .into_iter() + .filter(|x| !x.ends_with("/")) + .collect() } pub fn binaries(&self) -> Vec { diff --git a/src/pkg/repo.rs b/src/pkg/repo.rs index 4a48698..3f854b0 100644 --- a/src/pkg/repo.rs +++ b/src/pkg/repo.rs @@ -89,6 +89,24 @@ impl Repository { .ok() } + pub fn list_pkg_arch(&self, arch: Architecture) -> Vec { + let mut packages = HashSet::new(); + + for entry in std::fs::read_dir(self.base_path(arch)).unwrap().flatten() { + let path = entry.path(); + let file_name = path.file_name().unwrap().to_str().unwrap().to_string(); + + if entry.metadata().unwrap().is_dir() { + packages.insert(file_name); + } + } + + let mut pkg: Vec<_> = packages.into_iter().collect(); + pkg.sort(); + + pkg + } + pub fn list_pkg(&self) -> Vec { let mut packages = HashSet::new(); diff --git a/src/routes/ui.rs b/src/routes/ui.rs index 4cd0c8a..0ee1672 100644 --- a/src/routes/ui.rs +++ b/src/routes/ui.rs @@ -5,7 +5,7 @@ use based::{ use maud::{PreEscaped, html}; use rocket::get; -use pacco::pkg::Repository; +use pacco::pkg::{Repository, arch::Architecture}; use super::render; @@ -13,9 +13,6 @@ use super::render; #[get("//")] pub async fn pkg_ui(repo: &str, pkg_name: &str, ctx: RequestContext) -> Option { - // TODO : Implement pkg UI - // pkgmeta display - let repo = Repository::new(repo).unwrap(); let pkg = repo.get_pkg_by_name(pkg_name)?; let versions = pkg.versions(); @@ -154,10 +151,10 @@ pub async fn pkg_ui(repo: &str, pkg_name: &str, ctx: RequestContext) -> Option Option")] -pub async fn repo_ui(repo: &str, ctx: RequestContext) -> StringResponse { - // TODO : Repo UI - // permissions - // pkg list +#[get("/?")] +pub async fn repo_ui(repo: &str, ctx: RequestContext, arch: Option<&str>) -> StringResponse { + // TODO : permissions + let arch = arch.map(|x| Architecture::parse(x).unwrap_or(Architecture::any)); let repo = Repository::new(repo).unwrap(); let architectures: Vec<_> = repo.arch().into_iter().map(|x| x.to_string()).collect(); - let packages = repo.list_pkg(); + let packages = if let Some(arch) = arch.clone() { + repo.list_pkg_arch(arch) + } else { + repo.list_pkg() + }; let content = html! { // Repository name and architectures @@ -186,10 +186,23 @@ pub async fn repo_ui(repo: &str, ctx: RequestContext) -> StringResponse { }; div class="flex gap-2 mt-2 md:mt-0" { - @for arch in architectures { - span class="px-3 py-1 text-sm font-medium bg-gray-200 dark:bg-gray-700 text-gray-600 dark:text-gray-300 rounded-full" { - (arch) - }; + @for a in architectures { + // TODO : Filter per arch with ?arch= + @if let Some(arch) = arch.as_ref() { + @if arch.to_string() == a { + (htmx_link(&format!("/{}", repo.name), "px-3 py-1 text-sm font-medium bg-blue-400 dark:bg-blue-500 text-gray-600 dark:text-gray-300 rounded-full", "", html! { + (a) + })); + } @else { + (htmx_link(&format!("/{}?arch={}", repo.name, a), "px-3 py-1 text-sm font-medium bg-gray-200 dark:bg-gray-700 text-gray-600 dark:text-gray-300 rounded-full", "", html! { + (a) + })); + } + } @else { + (htmx_link(&format!("/{}?arch={}", repo.name, a), "px-3 py-1 text-sm font-medium bg-gray-200 dark:bg-gray-700 text-gray-600 dark:text-gray-300 rounded-full", "", html! { + (a) + })); + } } } }; @@ -267,7 +280,7 @@ pub fn build_info(key: String, value: String) -> PreEscaped { pub fn key_value(key: String, value: String) -> PreEscaped { html! { - div class="flex" { + div class="flex items-center" { span class="font-bold w-32" { (format!("{key}: ")) }; span class="ml-2" { (value) }; }; diff --git a/src/routes/user.rs b/src/routes/user.rs index d8975b3..f3f5b64 100644 --- a/src/routes/user.rs +++ b/src/routes/user.rs @@ -173,8 +173,6 @@ pub struct PasswordChangeForm { csrf: String, } -// TODO : Change password pages - #[post("/passwd", data = "
")] pub async fn change_password_post(form: Form, user: User) -> Redirect { if form.password_new != form.password_new_repeat {