update
All checks were successful
ci/woodpecker/push/build Pipeline was successful

This commit is contained in:
JMARyA 2025-01-12 04:27:50 +01:00
parent 3fabc91438
commit 0cc7eb8f40
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
5 changed files with 53 additions and 21 deletions

View file

@ -1,5 +1,4 @@
// TODO : Read DB Info
// TODO : Read PKG Info + Content
pub mod repo;
pub use repo::Repository;

View file

@ -38,7 +38,11 @@ impl Package {
}
pub fn file_list(&self) -> Vec<String> {
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<String> {

View file

@ -89,6 +89,24 @@ impl Repository {
.ok()
}
pub fn list_pkg_arch(&self, arch: Architecture) -> Vec<String> {
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<String> {
let mut packages = HashSet::new();

View file

@ -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("/<repo>/<pkg_name>")]
pub async fn pkg_ui(repo: &str, pkg_name: &str, ctx: RequestContext) -> Option<StringResponse> {
// 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<S
};
};
// Install Scripts
// Install Script
@if let Some(install_script) = install_script {
div class="space-y-4 pt-6" {
h2 class="text-3xl font-semibold text-gray-700 dark:text-gray-300" { "Install Scripts" }
h2 class="text-3xl font-semibold text-gray-700 dark:text-gray-300" { "Install Script" }
pre class="bg-gray-100 dark:bg-gray-700 p-4 rounded-lg text-gray-800 dark:text-gray-100 overflow-x-auto text-sm" {
(install_script)
}
@ -168,15 +165,18 @@ pub async fn pkg_ui(repo: &str, pkg_name: &str, ctx: RequestContext) -> Option<S
Some(render(content, pkg_name, ctx).await)
}
#[get("/<repo>")]
pub async fn repo_ui(repo: &str, ctx: RequestContext) -> StringResponse {
// TODO : Repo UI
// permissions
// pkg list
#[get("/<repo>?<arch>")]
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<String> {
pub fn key_value(key: String, value: String) -> PreEscaped<String> {
html! {
div class="flex" {
div class="flex items-center" {
span class="font-bold w-32" { (format!("{key}: ")) };
span class="ml-2" { (value) };
};

View file

@ -173,8 +173,6 @@ pub struct PasswordChangeForm {
csrf: String,
}
// TODO : Change password pages
#[post("/passwd", data = "<form>")]
pub async fn change_password_post(form: Form<PasswordChangeForm>, user: User) -> Redirect {
if form.password_new != form.password_new_repeat {