add cmd ver
This commit is contained in:
@@ -5,3 +5,4 @@ pub mod gen;
|
||||
pub mod lang;
|
||||
pub mod did;
|
||||
pub mod index;
|
||||
pub mod pds;
|
||||
|
||||
76
src/commands/pds.rs
Normal file
76
src/commands/pds.rs
Normal file
@@ -0,0 +1,76 @@
|
||||
use anyhow::Result;
|
||||
use serde::Deserialize;
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct Network {
|
||||
plc: String,
|
||||
bsky: String,
|
||||
#[allow(dead_code)]
|
||||
web: Option<String>,
|
||||
#[serde(rename = "handleDomains")]
|
||||
#[allow(dead_code)]
|
||||
handle_domains: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct HealthResponse {
|
||||
version: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct PackageJson {
|
||||
dependencies: Option<HashMap<String, String>>,
|
||||
}
|
||||
|
||||
const PDS_PACKAGE_URL: &str = "https://raw.githubusercontent.com/bluesky-social/pds/main/service/package.json";
|
||||
|
||||
async fn get_latest_version(client: &reqwest::Client) -> String {
|
||||
if let Ok(res) = client.get(PDS_PACKAGE_URL).send().await {
|
||||
if res.status().is_success() {
|
||||
if let Ok(pkg) = res.json::<PackageJson>().await {
|
||||
if let Some(deps) = pkg.dependencies {
|
||||
if let Some(v) = deps.get("@atproto/pds") {
|
||||
return v.clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
"N/A".to_string()
|
||||
}
|
||||
|
||||
pub async fn check_versions(networks_path: &str) -> Result<()> {
|
||||
// Read networks.json
|
||||
let content = std::fs::read_to_string(networks_path)?;
|
||||
let networks: HashMap<String, Network> = serde_json::from_str(&content)?;
|
||||
|
||||
let client = reqwest::Client::new();
|
||||
|
||||
// Get latest version from GitHub
|
||||
let latest = get_latest_version(&client).await;
|
||||
println!("latest: {}", latest);
|
||||
println!();
|
||||
|
||||
for (name, _network) in &networks {
|
||||
// Check PDS using network name as domain
|
||||
let url = format!("https://{}/xrpc/_health", name);
|
||||
let version = match client.get(&url).send().await {
|
||||
Ok(res) => {
|
||||
if res.status().is_success() {
|
||||
match res.json::<HealthResponse>().await {
|
||||
Ok(health) => health.version.unwrap_or_else(|| "-".to_string()),
|
||||
Err(_) => "-".to_string(),
|
||||
}
|
||||
} else {
|
||||
"-".to_string()
|
||||
}
|
||||
}
|
||||
Err(_) => "-".to_string(),
|
||||
};
|
||||
println!("{}: {}", name, version);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
31
src/main.rs
31
src/main.rs
@@ -152,6 +152,27 @@ enum Commands {
|
||||
#[arg(short, long, default_value = "public/content")]
|
||||
dir: String,
|
||||
},
|
||||
|
||||
/// Show ailog version
|
||||
#[command(alias = "v")]
|
||||
Version,
|
||||
|
||||
/// PDS commands
|
||||
Pds {
|
||||
#[command(subcommand)]
|
||||
command: PdsCommands,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum PdsCommands {
|
||||
/// Check PDS versions
|
||||
#[command(alias = "v")]
|
||||
Version {
|
||||
/// Networks JSON file
|
||||
#[arg(short, long, default_value = "public/networks.json")]
|
||||
networks: String,
|
||||
},
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
@@ -201,6 +222,16 @@ async fn main() -> Result<()> {
|
||||
Commands::Index { dir } => {
|
||||
commands::index::run(std::path::Path::new(&dir))?;
|
||||
}
|
||||
Commands::Version => {
|
||||
println!("{}", env!("CARGO_PKG_VERSION"));
|
||||
}
|
||||
Commands::Pds { command } => {
|
||||
match command {
|
||||
PdsCommands::Version { networks } => {
|
||||
commands::pds::check_versions(&networks).await?;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user