From 6c6ce8ff499039383043213e39690c0f7be04a58 Mon Sep 17 00:00:00 2001 From: sugyan Date: Tue, 20 Feb 2024 09:39:08 +0900 Subject: [PATCH 1/3] Add CLI commands --- atrium-cli/README.md | 15 ++++--- atrium-cli/src/commands.rs | 18 ++++++-- atrium-cli/src/runner.rs | 86 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+), 9 deletions(-) diff --git a/atrium-cli/README.md b/atrium-cli/README.md index 40af6db0..b1b9b78f 100644 --- a/atrium-cli/README.md +++ b/atrium-cli/README.md @@ -1,16 +1,21 @@ -# CLI +# ATrium CLI ``` Usage: atrium-cli [OPTIONS] Commands: login Login (Create an authentication session) - get-timeline Get a view of the actor's home timeline + get-timeline Get a view of an actor's home timeline get-author-feed Get a view of an actor's feed - get-likes Get the list of likes - get-reposted-by Get a list of reposts - get-follows Get a list of who the actor follows + get-likes Get a list of likes for a given post + get-reposted-by Get a list of reposts for a given post + get-actor-feeds Get a list of feeds created by an actor + get-feed Get a view of a hydrated feed + get-list-feed Get a view of a specified list, + get-follows Get a list of who an actor follows get-followers Get a list of an actor's followers + get-lists Get a list of the list created by an actor + get-list Get detailed info of a specified list get-profile Get detailed profile view of an actor list-notifications Get a list of notifications create-post Create a new post diff --git a/atrium-cli/src/commands.rs b/atrium-cli/src/commands.rs index dcb7ef92..e298bfea 100644 --- a/atrium-cli/src/commands.rs +++ b/atrium-cli/src/commands.rs @@ -6,18 +6,28 @@ use std::str::FromStr; pub enum Command { /// Login (Create an authentication session). Login(LoginArgs), - /// Get a view of the actor's home timeline. + /// Get a view of an actor's home timeline. GetTimeline, /// Get a view of an actor's feed. GetAuthorFeed(ActorArgs), - /// Get the list of likes. + /// Get a list of likes for a given post. GetLikes(UriArgs), - /// Get a list of reposts. + /// Get a list of reposts for a given post. GetRepostedBy(UriArgs), - /// Get a list of who the actor follows. + /// Get a list of feeds created by an actor. + GetActorFeeds(ActorArgs), + /// Get a view of a hydrated feed. + GetFeed(UriArgs), + /// Get a view of a specified list, + GetListFeed(UriArgs), + /// Get a list of who an actor follows. GetFollows(ActorArgs), /// Get a list of an actor's followers. GetFollowers(ActorArgs), + /// Get a list of the list created by an actor. + GetLists(ActorArgs), + /// Get detailed info of a specified list. + GetList(UriArgs), /// Get detailed profile view of an actor. GetProfile(ActorArgs), /// Get a list of notifications. diff --git a/atrium-cli/src/runner.rs b/atrium-cli/src/runner.rs index 603ad9c5..8002c081 100644 --- a/atrium-cli/src/runner.rs +++ b/atrium-cli/src/runner.rs @@ -119,6 +119,57 @@ impl Runner { .await, ); } + Command::GetActorFeeds(args) => { + self.print( + &self + .agent + .api + .app + .bsky + .feed + .get_actor_feeds(atrium_api::app::bsky::feed::get_actor_feeds::Parameters { + actor: args + .actor + .or(self.handle.clone().map(AtIdentifier::Handle)) + .unwrap(), + cursor: None, + limit: Some(limit), + }) + .await, + ); + } + Command::GetFeed(args) => { + self.print( + &self + .agent + .api + .app + .bsky + .feed + .get_feed(atrium_api::app::bsky::feed::get_feed::Parameters { + cursor: None, + feed: args.uri.to_string(), + limit: Some(limit), + }) + .await, + ); + } + Command::GetListFeed(args) => { + self.print( + &self + .agent + .api + .app + .bsky + .feed + .get_list_feed(atrium_api::app::bsky::feed::get_list_feed::Parameters { + cursor: None, + limit: Some(limit), + list: args.uri.to_string(), + }) + .await, + ); + } Command::GetFollows(args) => { self.print( &self @@ -157,6 +208,41 @@ impl Runner { .await, ); } + Command::GetLists(args) => { + self.print( + &self + .agent + .api + .app + .bsky + .graph + .get_lists(atrium_api::app::bsky::graph::get_lists::Parameters { + actor: args + .actor + .or(self.handle.clone().map(AtIdentifier::Handle)) + .unwrap(), + cursor: None, + limit: Some(limit), + }) + .await, + ); + } + Command::GetList(args) => { + self.print( + &self + .agent + .api + .app + .bsky + .graph + .get_list(atrium_api::app::bsky::graph::get_list::Parameters { + cursor: None, + limit: Some(limit), + list: args.uri.to_string(), + }) + .await, + ); + } Command::GetProfile(args) => { self.print( &self From b27520c480924c98951e63dbe85eddfe07f74e1c Mon Sep 17 00:00:00 2001 From: sugyan Date: Tue, 20 Feb 2024 23:21:57 +0900 Subject: [PATCH 2/3] Add create-post with images --- atrium-cli/src/commands.rs | 6 +++++- atrium-cli/src/runner.rs | 38 +++++++++++++++++++++++++++++++++++--- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/atrium-cli/src/commands.rs b/atrium-cli/src/commands.rs index e298bfea..c7c77b86 100644 --- a/atrium-cli/src/commands.rs +++ b/atrium-cli/src/commands.rs @@ -1,5 +1,6 @@ use atrium_api::types::string::AtIdentifier; use clap::Parser; +use std::path::PathBuf; use std::str::FromStr; #[derive(Parser, Debug)] @@ -65,8 +66,11 @@ pub struct UriArgs { #[derive(Parser, Debug)] pub struct CreatePostArgs { /// Post text - #[arg(short, long, value_parser)] + #[arg(short, long)] pub(crate) text: String, + /// Images to embed + #[arg(short, long)] + pub(crate) images: Vec, } #[derive(Debug, Clone)] diff --git a/atrium-cli/src/runner.rs b/atrium-cli/src/runner.rs index 8002c081..d67f4691 100644 --- a/atrium-cli/src/runner.rs +++ b/atrium-cli/src/runner.rs @@ -5,8 +5,10 @@ use atrium_api::types::string::{AtIdentifier, Datetime, Handle}; use atrium_api::xrpc::error::{Error, XrpcErrorKind}; use atrium_xrpc_client::reqwest::ReqwestClient; use serde::Serialize; +use std::ffi::OsStr; use std::path::PathBuf; -use tokio::fs; +use tokio::fs::{create_dir_all, File}; +use tokio::io::AsyncReadExt; pub struct Runner { agent: AtpAgent, @@ -19,7 +21,7 @@ impl Runner { pub async fn new(pds_host: String, debug: bool) -> Result> { let config_dir = dirs::config_dir().unwrap(); let dir = config_dir.join("atrium-cli"); - fs::create_dir_all(&dir).await?; + create_dir_all(&dir).await?; let session_path = dir.join("session.json"); let store = SimpleJsonFileSessionStore::new(session_path.clone()); let session = store.get_session().await; @@ -279,6 +281,36 @@ impl Runner { ); } Command::CreatePost(args) => { + let mut images = Vec::new(); + for image in &args.images { + if let Ok(mut file) = File::open(image).await { + let mut buf = Vec::new(); + file.read_to_end(&mut buf).await.expect("read image file"); + let output = self + .agent + .api + .com + .atproto + .repo + .upload_blob(buf) + .await + .expect("upload blob"); + images.push(atrium_api::app::bsky::embed::images::Image { + alt: image + .file_name() + .map(OsStr::to_string_lossy) + .unwrap_or_default() + .into(), + aspect_ratio: None, + image: output.blob, + }) + } + } + let embed = Some( + atrium_api::app::bsky::feed::post::RecordEmbedEnum::AppBskyEmbedImagesMain( + Box::new(atrium_api::app::bsky::embed::images::Main { images }), + ), + ); self.print( &self .agent @@ -291,7 +323,7 @@ impl Runner { record: atrium_api::records::Record::AppBskyFeedPost(Box::new( atrium_api::app::bsky::feed::post::Record { created_at: Datetime::now(), - embed: None, + embed, entities: None, facets: None, labels: None, From a1d17fc6d41ea08e9f58d1fc0194bc966899028f Mon Sep 17 00:00:00 2001 From: sugyan Date: Tue, 20 Feb 2024 23:27:55 +0900 Subject: [PATCH 3/3] Ready to publish --- atrium-cli/Cargo.toml | 5 +++++ atrium-cli/README.md | 2 ++ release-plz.toml | 7 +++++++ 3 files changed, 14 insertions(+) diff --git a/atrium-cli/Cargo.toml b/atrium-cli/Cargo.toml index 7f05ba85..02687f57 100644 --- a/atrium-cli/Cargo.toml +++ b/atrium-cli/Cargo.toml @@ -4,6 +4,11 @@ version = "0.1.0" authors = ["sugyan "] edition.workspace = true rust-version.workspace = true +description = "CLI application for AT Protocol using ATrium API" +readme = "README.md" +repository.workspace = true +license.workspace = true +keywords.workspace = true [dependencies] async-trait.workspace = true diff --git a/atrium-cli/README.md b/atrium-cli/README.md index b1b9b78f..61f87633 100644 --- a/atrium-cli/README.md +++ b/atrium-cli/README.md @@ -1,5 +1,7 @@ # ATrium CLI +CLI application for AT Protocol using ATrium API + ``` Usage: atrium-cli [OPTIONS] diff --git a/release-plz.toml b/release-plz.toml index ef351391..ab09386d 100644 --- a/release-plz.toml +++ b/release-plz.toml @@ -11,6 +11,13 @@ git_release_enable = true git_tag_enable = true changelog_update = true +[[package]] +name = "atrium-cli" +publish = true +git_release_enable = true +git_tag_enable = true +changelog_update = true + [[package]] name = "atrium-xrpc" publish = true