tangled.org trending bluesky account

Some error handling from vendor resources

Changed files
+56 -38
bot
src
+4 -1
.env.template
··· 9 9 STAR_THRESHOLD=1 10 10 11 11 # Timeframe in hours to gate posts after a threshold is met (default 24) 12 - POST_WINDOW_HOURS=24 12 + POST_WINDOW_HOURS=24 13 + 14 + DATABASE_URL=./stitch_counter.sqlite 15 + JETSTREAM_URL="wss://jetstream1.us-east.fire.hose.cam/subscribe"
+52 -37
bot/src/main.rs
··· 6 6 use atrium_api::types::{Collection, Union}; 7 7 use dotenv::dotenv; 8 8 use logic::BotApi; 9 + use rocketman::endpoints::JetstreamEndpoints; 9 10 use rocketman::{ 10 11 connection::JetstreamConnection, handler, ingestion::LexiconIngestor, 11 12 options::JetstreamOptions, types::event::Operation, ··· 71 72 // Run migrations from ./migrations 72 73 sqlx::migrate!("./migrations").run(&pool).await?; 73 74 75 + let jet_stream = match std::env::var("JETSTREAM_URL") { 76 + Ok(url) => JetstreamEndpoints::Custom(url.into()), 77 + Err(_) => JetstreamEndpoints::default(), 78 + }; 74 79 // Configure Jetstream to listen to sh.tangled.feed.star 75 80 let opts = JetstreamOptions::builder() 81 + .ws_url(jet_stream) 76 82 .wanted_collections(vec![atproto_api::sh::tangled::feed::Star::NSID.to_string()]) 77 83 .build(); 78 84 ··· 235 241 236 242 let parsed = parse_uri(&repo_subject)?; 237 243 let cloned_repo_owner = parsed.did.clone(); 238 - let stars = fetch_constellation_count(&repo_subject).await?; 244 + let stars = fetch_constellation_count(&repo_subject) 245 + .await 246 + .unwrap_or_else(|err| { 247 + log::error!("Error calling constellation: {:?}", err); 248 + 0 249 + }); 239 250 let repo_record = &self 240 251 .sling_shot 241 252 .get_record::<atproto_api::sh::tangled::repo::RecordData>( ··· 269 280 "https://tangled-search.bigmoves.deno.net/repo-image/{}", 270 281 encoded_subject 271 282 ); 272 - let bytes = reqwest::get(url).await?.bytes().await?.to_vec(); 273 - 274 - let blob_upload = &self 275 - .bot 276 - .agent 277 - .api 278 - .com 279 - .atproto 280 - .repo 281 - .upload_blob(bytes) 282 - .await?; 283 + log::info!("Attempting to get the picture at: {url}"); 283 284 284 - // let rt = RichText::new_with_detect_facets(format!( 285 - // "{handle_and_repo}{description}\n⭐️ {stars} {tangled_sh_url}" 286 - // )) 287 - // .await?; 288 285 let post_text = 289 286 format!("{handle_and_repo}{description}\n⭐️ {stars}"); 290 287 291 - let image = atrium_api::app::bsky::embed::images::ImageData { 292 - alt: format!( 293 - "An image showing the same text inside of the post. {post_text}" 294 - ), 295 - aspect_ratio: Some( 296 - atrium_api::app::bsky::embed::defs::AspectRatioData { 297 - height: NonZeroU64::try_from(400_u64)?, 298 - width: NonZeroU64::try_from(800_u64)?, 299 - } 300 - .into(), 301 - ), 302 - //Good lord how many clones is that 303 - image: blob_upload.clone().blob.clone(), 288 + let response = reqwest::get(url).await?; 289 + 290 + let embed = match response.status().is_success() { 291 + true => { 292 + let bytes = response.bytes().await?.to_vec(); 293 + let blob_upload = &self 294 + .bot 295 + .agent 296 + .api 297 + .com 298 + .atproto 299 + .repo 300 + .upload_blob(bytes) 301 + .await?; 302 + 303 + let image = atrium_api::app::bsky::embed::images::ImageData { 304 + alt: format!( 305 + "An image showing the same text inside of the post. {post_text}" 306 + ), 307 + aspect_ratio: Some( 308 + atrium_api::app::bsky::embed::defs::AspectRatioData { 309 + height: NonZeroU64::try_from(400_u64)?, 310 + width: NonZeroU64::try_from(800_u64)?, 311 + } 312 + .into(), 313 + ), 314 + //Good lord how many clones is that 315 + image: blob_upload.clone().blob.clone(), 316 + }; 317 + Some(atrium_api::types::Union::Refs( 318 + RecordEmbedRefs::AppBskyEmbedImagesMain(Box::new( 319 + atrium_api::app::bsky::embed::images::MainData { 320 + images: vec![image.into()], 321 + } 322 + .into(), 323 + )), 324 + )) 325 + } 326 + false => None, 304 327 }; 305 - let embed = Some(atrium_api::types::Union::Refs( 306 - RecordEmbedRefs::AppBskyEmbedImagesMain(Box::new( 307 - atrium_api::app::bsky::embed::images::MainData { 308 - images: vec![image.into()], 309 - } 310 - .into(), 311 - )), 312 - )); 313 328 314 329 let post = atrium_api::app::bsky::feed::post::RecordData { 315 330 created_at: atrium_api::types::string::Datetime::now(),