initial version

This commit is contained in:
2025-03-24 15:33:29 +01:00
parent 39c5d71557
commit 696f92bb1b
10 changed files with 1862 additions and 0 deletions

8
.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

13
.idea/alhp_checker.iml generated Normal file
View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="EMPTY_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/crates/alhp_api/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target" />
<excludeFolder url="file://$MODULE_DIR$/crates/alhp_api/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

8
.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/alhp_checker.iml" filepath="$PROJECT_DIR$/.idea/alhp_checker.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

1599
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

8
Cargo.toml Normal file
View File

@@ -0,0 +1,8 @@
[package]
name = "alhp_checker"
version = "0.1.0"
edition = "2024"
[dependencies]
alhp_api = {path = "crates/alhp_api"}

96
crates/alhp_api/Cargo.lock generated Normal file
View File

@@ -0,0 +1,96 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "alhp_api"
version = "0.1.0"
dependencies = [
"serde",
"serde_json",
]
[[package]]
name = "itoa"
version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
[[package]]
name = "memchr"
version = "2.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
[[package]]
name = "proc-macro2"
version = "1.0.94"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
dependencies = [
"proc-macro2",
]
[[package]]
name = "ryu"
version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
[[package]]
name = "serde"
version = "1.0.219"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.219"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "serde_json"
version = "1.0.140"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373"
dependencies = [
"itoa",
"memchr",
"ryu",
"serde",
]
[[package]]
name = "syn"
version = "2.0.100"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "unicode-ident"
version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"

View File

@@ -0,0 +1,10 @@
[package]
name = "alhp_api"
version = "0.1.0"
edition = "2024"
authors = ["mpuchstein"]
[dependencies]
serde = { version = "1.0.219", features = ["derive"] }
serde_json = "1.0.140"
reqwest = { version = "0.12.15" , features = ["blocking"] }

View File

@@ -0,0 +1,83 @@
use std::fmt;
use serde::{Serialize, Deserialize};
use reqwest::blocking::Client;
#[derive(Debug, Clone, Copy, Serialize, Deserialize, Eq, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum PackageStatus{
Latest,
Failed,
Built,
Skipped,
Delayed,
Building,
Signing,
Unknown,
Queued,
}
impl fmt::Display for PackageStatus {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", serde_json::to_string(self).unwrap().trim_matches('"'))
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Package {
pkgbase: String,
repo: String,
split_packages: Vec<String>,
status: PackageStatus,
lto: String,
debug_symbols: String,
arch_version: String,
repo_version: String,
build_date: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PackageResponse {
pub total: usize,
pub offset: usize,
pub limit: usize,
pub packages: Vec<Package>
}
#[derive(Debug, Serialize, Default)]
pub struct PackageRequest {
pub status: Vec<PackageStatus>,
pub pkgbase: Option<String>,
pub exact: bool,
pub repo: Option<String>,
pub offset: usize,
pub limit: usize,
}
impl PackageRequest {
fn query_string(&self) -> String {
let mut params = Vec::new();
for status in &self.status {
params.push(format!("status={}", status));
}
if let Some(pkgbase) = &self.pkgbase {
params.push(format!("pkgbase={}", pkgbase));
}
if self.exact {
params.push("exact".to_string());
}
if let Some(repo) = &self.repo {
params.push(format!("repo={}", repo));
}
params.push(format!("offset={}", self.offset));
params.push(format!("limit={}", self.limit));
params.join("&")
}
pub fn response(&self) -> Result<PackageResponse, reqwest::Error> {
let client = Client::new();
let query_string = self.query_string();
let url = format!("https://api.alhp.dev/packages?{}", query_string);
println!("{}", url);
let response = client.get(url).send()?.text()?;
let response: PackageResponse = serde_json::from_str(&response).unwrap();
Ok(response)
}
}

31
src/main.rs Normal file
View File

@@ -0,0 +1,31 @@
use alhp_api;
use std::process::Command;
use alhp_api::{PackageRequest, PackageStatus};
fn pacman_query_installed_packages() -> Vec<String> {
match Command::new("pacman").arg("-Qqn").output() {
Ok(packages) => String::from_utf8_lossy(&packages.stdout)
.lines()
.map(|s| s.to_string())
.collect(),
_ => {
panic!("pacman query failed");
}
}
}
fn main() {
let installed_packages = pacman_query_installed_packages();
println!("installed packages: {:?}", installed_packages);
let status = vec!();
let pkg = PackageRequest{
status,
pkgbase: Some("go".to_string()),
exact: true,
repo: Some("extra-x86-64-v3".to_string()),
offset: 0,
limit: 0,
};
let pkg = pkg.response().unwrap();
println!("pkg: {:?}", pkg);
}