small bsky embedder @ boobsky.app - kinda mid but works - mirror of git.fomx.gay/rooot/embedthing

feat: some code cleanup

Signed-off-by: rooot <hey@rooot.gay>

Changed files
+12 -40
src
+12 -40
src/bsky.rs
··· 34 34 .feed 35 35 .get_post_thread( 36 36 bsky_sdk::api::app::bsky::feed::get_post_thread::ParametersData { 37 - depth: LimitedU16::try_from(0 as u16).ok(), 38 - parent_height: LimitedU16::try_from(0 as u16).ok(), 37 + depth: LimitedU16::try_from(0).ok(), 38 + parent_height: LimitedU16::try_from(0).ok(), 39 39 uri: atproto_uri.clone(), 40 40 } 41 41 .into(), ··· 78 78 }; 79 79 80 80 if let Unknown::Object(record) = data.record { 81 - if ipld_to_string(record.get_key_value("$type").ok_or(MissingElementError("$type".into()))?.1.deref()) == Ok("app.bsky.feed.post".to_string()) { 81 + if ipld_to_string(record.get_key_value("$type").ok_or(MissingElementError("$type".into()))?.1) == Ok("app.bsky.feed.post".to_string()) { 82 82 83 - let text = ipld_to_string(record.get_key_value("text").ok_or(MissingElementError("text".into()))?.1.deref()).ok(); 83 + let text = ipld_to_string(record.get_key_value("text").ok_or(MissingElementError("text".into()))?.1).ok(); 84 84 85 85 // todo: format text into markdown so we can embed it nicely 86 86 // for now we'll just return the text as is ··· 118 118 // this is also why we need those 2 checks above 119 119 let bite_me = video::Main::try_from_unknown(unknown_embed.clone()); 120 120 121 - let video_blob = match bite_me { 122 - Ok(video) => { 123 - match &video.clone().video { 124 - bsky_sdk::api::types::BlobRef::Typed(blob) => { 125 - match blob { 126 - Blob(blob) => Some(blob.clone()), 127 - } 128 - }, 129 - bsky_sdk::api::types::BlobRef::Untyped(_) => { 130 - None 131 - } 132 - } 133 - }, 134 - Err(_) => { 135 - None 121 + if let Ok(thing) = bite_me { 122 + if let bsky_sdk::api::types::BlobRef::Typed(Blob(blob)) = &thing.video { 123 + blobs.push(blob.clone()); 136 124 } 137 - }; 138 - if let Some(blob) = video_blob { 139 - blobs.push(blob); 140 125 } 141 126 } 142 127 } 143 128 144 129 for image in images { 145 - let image_embed = ImageData::try_from_unknown(Unknown::Other(DataModel::try_from(image)?))?; 146 - 147 - let blob = match image_embed.image { 148 - bsky_sdk::api::types::BlobRef::Typed(blob) => { 149 - match blob { 150 - Blob(blob) => Some(blob), 151 - } 152 - }, 153 - bsky_sdk::api::types::BlobRef::Untyped(_) => { 154 - None 155 - } 156 - }; 157 - if let Some(blob) = blob { 130 + if let bsky_sdk::api::types::BlobRef::Typed(Blob(blob)) = ImageData::try_from_unknown(Unknown::Other(DataModel::try_from(image)?))?.image { 158 131 blobs.push(blob); 159 132 } 160 133 }; ··· 191 164 } 192 165 193 166 fn ipld_to_string(ipld: &Ipld) -> Result<String, ()> { 194 - match ipld { 195 - Ipld::String(s) => { 196 - Ok(s.clone()) // well guess what fuck you 197 - } 198 - _ => Err(()), 167 + if let Ipld::String(s) = ipld { 168 + Ok(s.clone()) 169 + } else { 170 + Err(()) 199 171 } 200 172 }