putz u in dhe washing machin and spins ur bsky pofile pictuer !!! :D
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

update profile record

did:plc:73gqgbnvpx5syidcponjri… 243c01b7 67672775

verified
+51 -7
+51 -7
src/main.rs
··· 1 - use image::{DynamicImage, open}; 1 + use image::{DynamicImage, ImageReader}; 2 2 use imageproc::geometric_transformations::{Interpolation, rotate}; 3 3 use jacquard::{ 4 4 client::{ ··· 6 6 credential_session::{CredentialSession, SessionKey}, 7 7 }, 8 8 cowstr::ToCowStr, 9 + types::{aturi::AtUri, blob::MimeType}, 9 10 }; 11 + use jacquard_api::app_bsky::actor::profile::Profile; 10 12 use jacquard_identity::JacquardResolver; 11 - use std::{env, process}; 13 + use std::{env, io::Cursor, process}; 12 14 13 15 type AgentType = 14 16 Agent<CredentialSession<MemorySessionStore<SessionKey, AtpSession>, JacquardResolver>>; ··· 36 38 rotated 37 39 } 38 40 39 - async fn update_avatar(image: image::RgbaImage, agent: &AgentType) { 40 - todo!() 41 + async fn update_avatar(image: image::RgbaImage, agent: &AgentType, format: &image::ImageFormat) { 42 + let mut buf = Cursor::new(Vec::new()); 43 + let dyn_img = DynamicImage::ImageRgba8(image); 44 + dyn_img.write_to(&mut buf, *format).unwrap_or_else(|e| { 45 + eprintln!("failed to encode image into {:?}: {}", format, e); 46 + process::exit(1); 47 + }); 48 + let encoded_bytes = buf.into_inner(); 49 + 50 + let format_string = format!("{:?}", format); 51 + let mime_string = format!("image/{}", format_string.to_lowercase()); 52 + let mime = MimeType::new_owned(mime_string); 53 + 54 + let blob = agent 55 + .upload_blob(encoded_bytes, mime) 56 + .await 57 + .unwrap_or_else(|e| { 58 + eprintln!("failed to upload avatar blob: {}", e); 59 + process::exit(1); 60 + }); 61 + 62 + let did = agent.info().await.unwrap().0; 63 + let at_uri = AtUri::new_owned(format!("at://{}/app.bsky.actor.profile/self", did)).unwrap(); 64 + 65 + agent 66 + .update_record::<Profile>(&at_uri, |profile| { 67 + profile.avatar = Some(blob.into()); 68 + }) 69 + .await 70 + .unwrap_or_else(|e| { 71 + eprintln!("failed to update profile: {}", e); 72 + process::exit(1); 73 + }); 74 + 75 + println!("successfully updated avatar"); 41 76 } 42 77 43 78 #[tokio::main] ··· 70 105 println!("authenticated as {}, hi!", auth.handle); 71 106 72 107 let input_path = input; 73 - let image = open(&input_path).unwrap_or_else(|e| { 108 + let reader = ImageReader::open(&input_path).unwrap_or_else(|e| { 74 109 eprintln!("failed to open '{}': {}", input_path.to_string(), e); 75 110 process::exit(1); 76 111 }); 77 112 78 - let rotated = rotate_image(image, 180.0); 113 + let mime_type = reader.format().unwrap_or_else(|| { 114 + eprintln!("failed to determine format of '{}'", input_path.to_string()); 115 + process::exit(1); 116 + }); 117 + let image = reader.decode().unwrap_or_else(|e| { 118 + eprintln!("failed to decode '{}': {}", input_path.to_string(), e); 119 + process::exit(1); 120 + }); 121 + 122 + let rotated = rotate_image(image, 1.0); 79 123 rotated.save(&output).unwrap_or_else(|e| { 80 124 eprintln!("failed to save '{}': {}", output.to_string(), e); 81 125 }); 82 126 83 - update_avatar(rotated, &agent).await; 127 + update_avatar(rotated, &agent, &mime_type).await; 84 128 }