This commit is contained in:
parent
3fabc91438
commit
0cc7eb8f40
5 changed files with 53 additions and 21 deletions
|
@ -1,5 +1,4 @@
|
||||||
// TODO : Read DB Info
|
// TODO : Read DB Info
|
||||||
// TODO : Read PKG Info + Content
|
|
||||||
|
|
||||||
pub mod repo;
|
pub mod repo;
|
||||||
pub use repo::Repository;
|
pub use repo::Repository;
|
||||||
|
|
|
@ -38,7 +38,11 @@ impl Package {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn file_list(&self) -> Vec<String> {
|
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> {
|
pub fn binaries(&self) -> Vec<String> {
|
||||||
|
|
|
@ -89,6 +89,24 @@ impl Repository {
|
||||||
.ok()
|
.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> {
|
pub fn list_pkg(&self) -> Vec<String> {
|
||||||
let mut packages = HashSet::new();
|
let mut packages = HashSet::new();
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ use based::{
|
||||||
use maud::{PreEscaped, html};
|
use maud::{PreEscaped, html};
|
||||||
use rocket::get;
|
use rocket::get;
|
||||||
|
|
||||||
use pacco::pkg::Repository;
|
use pacco::pkg::{Repository, arch::Architecture};
|
||||||
|
|
||||||
use super::render;
|
use super::render;
|
||||||
|
|
||||||
|
@ -13,9 +13,6 @@ use super::render;
|
||||||
|
|
||||||
#[get("/<repo>/<pkg_name>")]
|
#[get("/<repo>/<pkg_name>")]
|
||||||
pub async fn pkg_ui(repo: &str, pkg_name: &str, ctx: RequestContext) -> Option<StringResponse> {
|
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 repo = Repository::new(repo).unwrap();
|
||||||
let pkg = repo.get_pkg_by_name(pkg_name)?;
|
let pkg = repo.get_pkg_by_name(pkg_name)?;
|
||||||
let versions = pkg.versions();
|
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 {
|
@if let Some(install_script) = install_script {
|
||||||
div class="space-y-4 pt-6" {
|
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" {
|
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)
|
(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)
|
Some(render(content, pkg_name, ctx).await)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/<repo>")]
|
#[get("/<repo>?<arch>")]
|
||||||
pub async fn repo_ui(repo: &str, ctx: RequestContext) -> StringResponse {
|
pub async fn repo_ui(repo: &str, ctx: RequestContext, arch: Option<&str>) -> StringResponse {
|
||||||
// TODO : Repo UI
|
// TODO : permissions
|
||||||
// permissions
|
let arch = arch.map(|x| Architecture::parse(x).unwrap_or(Architecture::any));
|
||||||
// pkg list
|
|
||||||
|
|
||||||
let repo = Repository::new(repo).unwrap();
|
let repo = Repository::new(repo).unwrap();
|
||||||
let architectures: Vec<_> = repo.arch().into_iter().map(|x| x.to_string()).collect();
|
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! {
|
let content = html! {
|
||||||
// Repository name and architectures
|
// 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" {
|
div class="flex gap-2 mt-2 md:mt-0" {
|
||||||
@for arch in architectures {
|
@for a 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" {
|
// TODO : Filter per arch with ?arch=
|
||||||
(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> {
|
pub fn key_value(key: String, value: String) -> PreEscaped<String> {
|
||||||
html! {
|
html! {
|
||||||
div class="flex" {
|
div class="flex items-center" {
|
||||||
span class="font-bold w-32" { (format!("{key}: ")) };
|
span class="font-bold w-32" { (format!("{key}: ")) };
|
||||||
span class="ml-2" { (value) };
|
span class="ml-2" { (value) };
|
||||||
};
|
};
|
||||||
|
|
|
@ -173,8 +173,6 @@ pub struct PasswordChangeForm {
|
||||||
csrf: String,
|
csrf: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO : Change password pages
|
|
||||||
|
|
||||||
#[post("/passwd", data = "<form>")]
|
#[post("/passwd", data = "<form>")]
|
||||||
pub async fn change_password_post(form: Form<PasswordChangeForm>, user: User) -> Redirect {
|
pub async fn change_password_post(form: Form<PasswordChangeForm>, user: User) -> Redirect {
|
||||||
if form.password_new != form.password_new_repeat {
|
if form.password_new != form.password_new_repeat {
|
||||||
|
|
Loading…
Add table
Reference in a new issue