Download Count for Packages

This commit is contained in:
JMARyA 2025-01-26 11:08:03 +01:00
parent 6c1ca1e8c0
commit 13b0b6095e
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
4 changed files with 64 additions and 3 deletions

View file

@ -4,6 +4,7 @@ use based::ui::components::Shell;
use based::ui::{prelude::*, render_page};
use maud::{PreEscaped, Render, html};
use pacco::pkg::mirror::MirrorRepository;
use pacco::pkg::package::PackageMetaInfo;
use rocket::http::{ContentType, Status};
use rocket::{State, get};
@ -98,6 +99,7 @@ pub async fn pkg_route(
.unwrap();
if pkg_name.ends_with("pkg.tar.zst") {
pkg.increase_download_count().await;
return respond_with(
Status::Ok,
ContentType::new("application", "tar"),

View file

@ -4,6 +4,7 @@ use based::ui::primitives::space::SpaceBetweenWidget;
use based::ui::primitives::text::{Code, TextWidget};
use based::ui::{UIWidget, prelude::*};
use maud::{PreEscaped, Render, html};
use pacco::pkg::package::PackageMetaInfo;
use rocket::{State, get};
use pacco::pkg::{Package, Repository, arch::Architecture, find_package_by_name};
@ -30,6 +31,8 @@ pub async fn pkg_ui(
pkg.rel = rel;
}
let dl_count = pkg.download_amount().await;
let versions = pkg.versions();
let arch = pkg.arch();
let install_script = pkg.install_script();
@ -118,6 +121,9 @@ pub async fn pkg_ui(
take_out(&mut pkginfo, |x| { x.0 == "size" }).1,
|x: (String, String)| build_info(x.0, x.1)
)
.push(
build_info("download_amount".to_string(), dl_count.to_string())
)
.push_for_each(&pkginfo, |(key, val)| build_info(key.clone(), val.clone()))
).y(ScreenValue::_2)).all(ScreenValue::_4)).all(ScreenValue::_2)).size(Size::Large)))))
)).push(
@ -413,6 +419,9 @@ pub async fn repo_ui(
pub fn build_info(key: String, value: String) -> PreEscaped<String> {
match key.as_str() {
"download_amount" => {
return key_value("Downloads".to_string(), value);
}
"pkgname" => {}
"xdata" => {}
"arch" => {}