tangled.org trending bluesky account

commented out chromiumoxide stuff

+93 -53
+93 -53
bot/src/main.rs
··· 5 5 use crate::constellation::fetch_constellation_count; 6 6 use atrium_api::app::bsky::embed::defs::AspectRatioData; 7 7 use atrium_api::app::bsky::feed::post::RecordEmbedRefs; 8 - use atrium_api::types::Collection; 8 + use atrium_api::app::bsky::richtext::facet::{ByteSliceData, LinkData, MainFeaturesItem}; 9 9 use atrium_api::types::string::Language; 10 + use atrium_api::types::{Collection, Union}; 10 11 use bsky_sdk::rich_text::RichText; 11 12 use chromiumoxide::browser::{Browser, BrowserConfig, HeadlessMode}; 12 13 use chromiumoxide::cdp::browser_protocol::page::{ ··· 110 111 let mut hbs = Handlebars::new(); 111 112 let _ = hbs.register_embed_templates::<Templates>(); 112 113 113 - let cfg = BrowserConfig::builder() 114 - .headless_mode(HeadlessMode::New) 115 - .no_sandbox() 116 - .build() 117 - .map_err(|e| anyhow::anyhow!(e)) 118 - .expect("build browser config"); 119 - let (mut browser, mut browser_handler) = Browser::launch(cfg).await.expect("launch browser"); 114 + // let cfg = BrowserConfig::builder() 115 + // .headless_mode(HeadlessMode::New) 116 + // .no_sandbox() 117 + // .build() 118 + // .map_err(|e| anyhow::anyhow!(e)) 119 + // .expect("build browser config"); 120 120 121 - let handle = tokio::spawn(async move { while let Some(_) = browser_handler.next().await {} }); 121 + // let handle = tokio::spawn(async move { while let Some(_) = browser_handler.next().await {} }); 122 122 123 123 // Ingestor for the star collection 124 124 let mut ingestors: HashMap<String, Box<dyn LexiconIngestor + Send + Sync>> = HashMap::new(); ··· 128 128 pool: pool.clone(), 129 129 bot: Arc::new(bot_api), 130 130 sling_shot: sling_shot.clone(), 131 - browser: Arc::new(browser), 131 + //Come back to this 132 + // browser: Arc::new(browser), 132 133 hbs: Arc::new(hbs), 133 134 timeframe_hours, 134 135 star_threshold, ··· 167 168 pool: SqlitePool, 168 169 bot: Arc<BotApi>, 169 170 sling_shot: Arc<Slingshot>, 170 - browser: Arc<Browser>, 171 + // browser: Arc<Browser>, 171 172 hbs: Arc<Handlebars<'static>>, 172 173 timeframe_hours: i64, 173 174 star_threshold: i64, ··· 283 284 284 285 let html = &self.hbs.render("repo_header.hbs", &ctx)?; 285 286 286 - let bytes = 287 - render_with_chromiumoxide(&html, 336, 114, &self.browser) 288 - .await?; 287 + // let bytes = render_with_chromiumoxide(&html, 336, 114).await?; 289 288 290 - let blob_upload = &self 291 - .bot 292 - .agent 293 - .api 294 - .com 295 - .atproto 296 - .repo 297 - .upload_blob(bytes) 298 - .await?; 289 + // let blob_upload = &self 290 + // .bot 291 + // .agent 292 + // .api 293 + // .com 294 + // .atproto 295 + // .repo 296 + // .upload_blob(bytes) 297 + // .await?; 299 298 300 - let rt = RichText::new_with_detect_facets(format!( 301 - "{handle_and_repo}{description}\n⭐️ {stars} {tangled_sh_url}" 302 - )) 303 - .await?; 304 - let image = atrium_api::app::bsky::embed::images::ImageData{ 305 - alt: "An image showing the same text inside of the post. Repo name, description and how many stars. Just a plain HTML page".to_string(), 306 - aspect_ratio: Some(atrium_api::app::bsky::embed::defs::AspectRatioData{ 307 - height: NonZeroU64::try_from(114_u64)?, 308 - width: NonZeroU64::try_from(336_u64)? 309 - }.into()), 310 - //Good lord how many clones is that 311 - image: blob_upload.clone().blob.clone(), 312 - }; 313 - let embed = Some(atrium_api::types::Union::Refs( 314 - RecordEmbedRefs::AppBskyEmbedImagesMain(Box::new( 315 - atrium_api::app::bsky::embed::images::MainData { 316 - images: vec![image.into()], 317 - } 318 - .into(), 319 - )), 320 - )); 299 + // let rt = RichText::new_with_detect_facets(format!( 300 + // "{handle_and_repo}{description}\n⭐️ {stars} {tangled_sh_url}" 301 + // )) 302 + // .await?; 303 + let post_text = 304 + format!("{handle_and_repo}{description}\n⭐️ {stars}"); 305 + 306 + // let image = atrium_api::app::bsky::embed::images::ImageData { 307 + // alt: format!( 308 + // "An image showing the same text inside of the post. {post_text}" 309 + // ), 310 + // aspect_ratio: Some( 311 + // atrium_api::app::bsky::embed::defs::AspectRatioData { 312 + // height: NonZeroU64::try_from(114_u64)?, 313 + // width: NonZeroU64::try_from(336_u64)?, 314 + // } 315 + // .into(), 316 + // ), 317 + // //Good lord how many clones is that 318 + // image: blob_upload.clone().blob.clone(), 319 + // }; 320 + // let embed = Some(atrium_api::types::Union::Refs( 321 + // RecordEmbedRefs::AppBskyEmbedImagesMain(Box::new( 322 + // atrium_api::app::bsky::embed::images::MainData { 323 + // images: vec![image.into()], 324 + // } 325 + // .into(), 326 + // )), 327 + // )); 321 328 322 329 let post = atrium_api::app::bsky::feed::post::RecordData { 323 330 created_at: atrium_api::types::string::Datetime::now(), 324 - embed, 331 + embed: None, 325 332 entities: None, 326 - facets: rt.facets, 333 + facets: Some(vec![ 334 + atrium_api::app::bsky::richtext::facet::MainData { 335 + features: vec![Union::Refs( 336 + MainFeaturesItem::Link(Box::new( 337 + LinkData { 338 + uri: tangled_sh_url, 339 + } 340 + .into(), 341 + )), 342 + )], 343 + index: ByteSliceData { 344 + byte_end: handle_and_repo.chars().count(), 345 + byte_start: 0, 346 + } 347 + .into(), 348 + } 349 + .into(), 350 + ]), 327 351 labels: None, 328 352 //You don't see a thing. No unwraps 329 353 langs: Some(vec![Language::new("en".to_string()).unwrap()]), 330 354 reply: None, 331 355 tags: None, 332 - text: rt.text, 356 + text: post_text, 333 357 }; 334 358 335 359 match self.bot.agent.create_record(post).await { ··· 373 397 html: &str, 374 398 width: u32, 375 399 height: u32, 376 - browser: &Browser, 377 400 ) -> Result<Vec<u8>, anyhow::Error> { 378 401 // Configure and launch the browser 379 402 380 - // Spawn the handler task to drive the connection 381 - // let handle = tokio::spawn(async move { while let Some(_) = handler.next().await {} }); 403 + let cfg = BrowserConfig::builder() 404 + .headless_mode(HeadlessMode::New) 405 + .no_sandbox() 406 + .build() 407 + .map_err(|e| anyhow::anyhow!(e)) 408 + .expect("build browser config"); 409 + 410 + let (mut browser, mut browser_handler) = Browser::launch(cfg).await.expect("launch browser"); 411 + 412 + let handle = tokio::task::spawn(async move { 413 + loop { 414 + match browser_handler.next().await { 415 + Some(h) => match h { 416 + Ok(_) => continue, 417 + Err(_) => break, 418 + }, 419 + None => break, 420 + } 421 + } 422 + }); 382 423 383 424 let page = browser.new_page("about:blank").await?; 384 425 ··· 405 446 406 447 // Close 407 448 page.close().await.ok(); 408 - // browser.close().await.ok(); 449 + browser.close().await.ok(); 409 450 // stop handler task 410 - // handle.abort(); 411 - 451 + handle.await?; 412 452 Ok(png_bytes) 413 453 }