add pds
This commit is contained in:
@@ -73,6 +73,35 @@ fn load_networks(networks_path: &str) -> Result<HashMap<String, Network>> {
|
||||
Ok(serde_json::from_str(DEFAULT_NETWORKS)?)
|
||||
}
|
||||
|
||||
/// Show current session info (PDS, DID, handle)
|
||||
pub fn show_session(is_bot: bool) -> Result<()> {
|
||||
use super::oauth;
|
||||
use super::token;
|
||||
|
||||
let has_oauth = oauth::has_oauth_session(is_bot);
|
||||
let session = if is_bot {
|
||||
token::load_bot_session()?
|
||||
} else {
|
||||
token::load_session()?
|
||||
};
|
||||
|
||||
let mut info = serde_json::json!({
|
||||
"did": session.did,
|
||||
"handle": session.handle,
|
||||
"pds": session.pds.as_deref().unwrap_or("bsky.social"),
|
||||
"auth": if has_oauth { "oauth" } else { "legacy" },
|
||||
});
|
||||
|
||||
if has_oauth {
|
||||
if let Ok(oauth_session) = oauth::load_oauth_session(is_bot) {
|
||||
info["issuer"] = serde_json::json!(oauth_session.issuer);
|
||||
}
|
||||
}
|
||||
|
||||
println!("{}", serde_json::to_string_pretty(&info)?);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn check_versions(networks_path: &str) -> Result<()> {
|
||||
let networks = load_networks(networks_path)?;
|
||||
|
||||
|
||||
10
src/main.rs
10
src/main.rs
@@ -362,6 +362,13 @@ enum PdsCommands {
|
||||
#[arg(short, long, default_value = "public/networks.json")]
|
||||
networks: String,
|
||||
},
|
||||
/// Show current session info (PDS, DID, handle)
|
||||
#[command(alias = "s")]
|
||||
Session {
|
||||
/// Show bot session
|
||||
#[arg(long)]
|
||||
bot: bool,
|
||||
},
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
@@ -468,6 +475,9 @@ async fn main() -> Result<()> {
|
||||
PdsCommands::Version { networks } => {
|
||||
commands::pds::check_versions(&networks).await?;
|
||||
}
|
||||
PdsCommands::Session { bot } => {
|
||||
commands::pds::show_session(bot)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
Commands::Oauth { handle, bot } => {
|
||||
|
||||
Reference in New Issue
Block a user