From 91c33b241877c98e460b2541e761f4e3a13e9ff7 Mon Sep 17 00:00:00 2001 From: Peter Grace Date: Thu, 14 Nov 2024 17:43:07 -0500 Subject: [PATCH 1/2] allow the specification of alt-text on images when using CLI. --- bsky-cli/src/commands.rs | 3 +++ bsky-cli/src/runner.rs | 19 +++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/bsky-cli/src/commands.rs b/bsky-cli/src/commands.rs index d9e23874..279c8274 100644 --- a/bsky-cli/src/commands.rs +++ b/bsky-cli/src/commands.rs @@ -87,6 +87,9 @@ pub struct CreatePostArgs { /// Images to embed #[arg(short, long)] pub(crate) images: Vec, + /// Alt-Text for images + #[arg(short, long)] + pub(crate) alt_text: Vec, } #[derive(Debug, Clone)] diff --git a/bsky-cli/src/runner.rs b/bsky-cli/src/runner.rs index 2f93406d..990a91da 100644 --- a/bsky-cli/src/runner.rs +++ b/bsky-cli/src/runner.rs @@ -374,7 +374,7 @@ impl Runner { } 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"); @@ -387,13 +387,20 @@ impl Runner { .upload_blob(buf) .await .expect("upload blob"); - images.push( - api::app::bsky::embed::images::ImageData { - alt: image + let alt= match args.alt_text.get(idx) { + 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, } From 19696eaab748800c086b12fa0d66206593693a34 Mon Sep 17 00:00:00 2001 From: Peter Grace Date: Thu, 14 Nov 2024 21:14:07 -0500 Subject: [PATCH 2/2] remove OsStr include to satisfy linter --- bsky-cli/src/runner.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/bsky-cli/src/runner.rs b/bsky-cli/src/runner.rs index 990a91da..ec57e7a7 100644 --- a/bsky-cli/src/runner.rs +++ b/bsky-cli/src/runner.rs @@ -7,7 +7,6 @@ use bsky_sdk::agent::config::{Config, FileStore}; 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;