Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the specification of alt-text on images when using CLI. #247

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bsky-cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ pub struct CreatePostArgs {
/// Images to embed
#[arg(short, long)]
pub(crate) images: Vec<PathBuf>,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is OK to change this to image.

/// Alt-Text for images
#[arg(short, long)]
pub(crate) alt_text: Vec<String>,
}

#[derive(Debug, Clone)]
Expand Down
20 changes: 13 additions & 7 deletions bsky-cli/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use bsky_sdk::api;
use bsky_sdk::BskyAgent;
use serde::Serialize;
use std::ffi::OsStr;
use std::path::PathBuf;
use tokio::fs::{create_dir_all, File};
use tokio::io::AsyncReadExt;
Expand Down Expand Up @@ -371,10 +370,10 @@
)
.await?,
)
}

Check warning on line 373 in bsky-cli/src/runner.rs

View workflow job for this annotation

GitHub Actions / Rust (1.75.0)

Diff in /home/runner/work/atrium/atrium/bsky-cli/src/runner.rs

Check warning on line 373 in bsky-cli/src/runner.rs

View workflow job for this annotation

GitHub Actions / Rust (stable)

Diff in /home/runner/work/atrium/atrium/bsky-cli/src/runner.rs
Command::CreatePost(args) => {
let mut images = Vec::new();
for image in &args.images {
for (idx,image) in args.images.iter().enumerate() {
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");
Expand All @@ -384,16 +383,23 @@
.com
.atproto
.repo
.upload_blob(buf)

Check warning on line 386 in bsky-cli/src/runner.rs

View workflow job for this annotation

GitHub Actions / Rust (1.75.0)

Diff in /home/runner/work/atrium/atrium/bsky-cli/src/runner.rs

Check warning on line 386 in bsky-cli/src/runner.rs

View workflow job for this annotation

GitHub Actions / Rust (stable)

Diff in /home/runner/work/atrium/atrium/bsky-cli/src/runner.rs
.await
.expect("upload blob");
images.push(
api::app::bsky::embed::images::ImageData {
alt: image
let alt= match args.alt_text.get(idx) {
Copy link
Owner

@sugyan sugyan Nov 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest adding .filter(|s| !s.is_empty()) or something like that, since an empty string will be assumed to be unspecified and the default filename will be used.

Some(text) => text.to_owned(),
None => {
image
.file_name()
.map(OsStr::to_string_lossy)
.map(|s| s.to_string_lossy().into_owned())
.unwrap_or_default()
.into(),

}

};
images.push(
api::app::bsky::embed::images::ImageData {
alt,
aspect_ratio: None,
image: output.data.blob,
}
Expand Down
Loading