api
Some checks failed
ci/woodpecker/push/pkgbuild/2 Pipeline is pending
ci/woodpecker/push/pkgbuild/1 Pipeline was successful
ci/woodpecker/push/container Pipeline failed

This commit is contained in:
JMARyA 2025-06-28 03:49:27 +02:00
parent 67033785ad
commit e6362f69a7
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
8 changed files with 79 additions and 13 deletions

View file

@ -18,6 +18,7 @@ pub mod push;
pub mod ui;
pub mod user;
/// Main Index Route : Overview of repositories
#[get("/")]
pub async fn index_page(
ctx: RequestContext,
@ -64,6 +65,7 @@ pub async fn index_page(
shell.render_page(content, "Repositories", ctx).await
}
/// Download endpoint for package downloads and `pacman`
#[get("/pkg/<repo>/<arch>/<pkg_name>")]
pub async fn pkg_route(
repo: &str,

View file

@ -32,6 +32,7 @@ pub async fn tmp_file_to_vec<'r>(tmp: &TempFile<'r>) -> Vec<u8> {
buf
}
/// Upload route for pushing a package
#[post("/pkg/<repo>/upload", data = "<upload>")]
pub async fn upload_pkg(
repo: &str,

View file

@ -9,9 +9,32 @@ use pacco::pkg::package::PackageMetaInfo;
use rocket::{State, get};
use pacco::pkg::{Package, Repository, arch::Architecture, find_package_by_name};
use serde_json::json;
use super::take_out;
/// Package API Endpoint
#[get("/<repo>/<pkg_name>/json")]
pub async fn pkg_json(repo: &str, pkg_name: &str) -> serde_json::Value {
let repository = Repository::new(repo).unwrap();
let pkg = repository.get_pkg_by_name(pkg_name).unwrap();
let versions = pkg.versions();
let version = pkg.version.clone();
let arch = pkg.arch();
let pkginfo = pkg.pkginfo();
json!({
"repo": repo,
"pkg": pkg_name,
"versions": versions,
"version": version,
"arch": arch.iter().map(|x| x.to_string()).collect::<Vec<_>>(),
"info": pkginfo
})
}
/// Package overview UI
#[get("/<repo>/<pkg_name>?<ver>")]
pub async fn pkg_ui(
repo: &str,

View file

@ -6,10 +6,33 @@ use pacco::pkg::package::PackageMetaInfo;
use rocket::{State, get};
use pacco::pkg::{Repository, arch::Architecture};
use serde_json::json;
use crate::routes::ui::arch_card;
use pacco::config::Config;
/// Repository API Endpoint
#[get("/<repo>/<arch>/json")]
pub async fn repo_arch_json(
repo: &str,
ctx: RequestContext,
arch: &str,
config: &State<Config>,
) -> serde_json::Value {
let arch = Architecture::parse(arch).unwrap_or(Architecture::any);
let repo_name = repo;
let repo = Repository::new(repo_name).unwrap();
let packages = repo.list_pkg_arch(arch.clone());
json!({
"repo": repo_name,
"arch": arch.to_string(),
"packages": packages
})
}
/// Repository Overview UI
#[get("/<repo>?<arch>&<sort>")]
pub async fn repo_ui(
repo: &str,