You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
1.0 KiB
Rust
23 lines
1.0 KiB
Rust
use std::error::Error;
|
|
use std::fs::{File, OpenOptions};
|
|
use std::io::BufRead;
|
|
use std::path::Path;
|
|
use reqwest::StatusCode;
|
|
use toml::toml;
|
|
|
|
pub async fn find_package_in_repositories(package: String, installed: Option<u64>) -> Vec<String> {
|
|
let mut hits: Vec<String> = vec!();
|
|
let client = reqwest::Client::new();
|
|
let repo_file = File::open("/var/gaypack/repositories.list").expect("Failed to open repository list");
|
|
for repository in std::io::BufReader::new(repo_file).lines() {
|
|
let repository = repository.expect("Unexpected error"); // i find this line kinda funny for some reason
|
|
let resp = client.get(format!("{}/gaypack/{}/latest/Package.toml", repository, package)).send().await.unwrap();
|
|
if installed.is_some() {
|
|
let package_data: crate::package::PackageData = toml::from_str(resp.text().await.expect("Failed to read text").as_str()).expect("Failed to parse toml");
|
|
}
|
|
if resp.status() == StatusCode::from_u16(200).unwrap() {
|
|
hits.push(repository);
|
|
}
|
|
};
|
|
return hits;
|
|
} |