tangled
alpha
login
or
join now
rooot.gay
/
embedthing
0
fork
atom
small bsky embedder @ boobsky.app - kinda mid but works - mirror of git.fomx.gay/rooot/embedthing
0
fork
atom
overview
issues
pulls
pipelines
feat: some code cleanup
Signed-off-by: rooot <hey@rooot.gay>
rooot.gay
1 year ago
74366b9d
efcc5291
+12
-40
1 changed file
expand all
collapse all
unified
split
src
bsky.rs
+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
37
-
depth: LimitedU16::try_from(0 as u16).ok(),
38
38
-
parent_height: LimitedU16::try_from(0 as u16).ok(),
37
37
+
depth: LimitedU16::try_from(0).ok(),
38
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
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
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
83
-
let text = ipld_to_string(record.get_key_value("text").ok_or(MissingElementError("text".into()))?.1.deref()).ok();
83
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
121
-
let video_blob = match bite_me {
122
122
-
Ok(video) => {
123
123
-
match &video.clone().video {
124
124
-
bsky_sdk::api::types::BlobRef::Typed(blob) => {
125
125
-
match blob {
126
126
-
Blob(blob) => Some(blob.clone()),
127
127
-
}
128
128
-
},
129
129
-
bsky_sdk::api::types::BlobRef::Untyped(_) => {
130
130
-
None
131
131
-
}
132
132
-
}
133
133
-
},
134
134
-
Err(_) => {
135
135
-
None
121
121
+
if let Ok(thing) = bite_me {
122
122
+
if let bsky_sdk::api::types::BlobRef::Typed(Blob(blob)) = &thing.video {
123
123
+
blobs.push(blob.clone());
136
124
}
137
137
-
};
138
138
-
if let Some(blob) = video_blob {
139
139
-
blobs.push(blob);
140
125
}
141
126
}
142
127
}
143
128
144
129
for image in images {
145
145
-
let image_embed = ImageData::try_from_unknown(Unknown::Other(DataModel::try_from(image)?))?;
146
146
-
147
147
-
let blob = match image_embed.image {
148
148
-
bsky_sdk::api::types::BlobRef::Typed(blob) => {
149
149
-
match blob {
150
150
-
Blob(blob) => Some(blob),
151
151
-
}
152
152
-
},
153
153
-
bsky_sdk::api::types::BlobRef::Untyped(_) => {
154
154
-
None
155
155
-
}
156
156
-
};
157
157
-
if let Some(blob) = blob {
130
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
194
-
match ipld {
195
195
-
Ipld::String(s) => {
196
196
-
Ok(s.clone()) // well guess what fuck you
197
197
-
}
198
198
-
_ => Err(()),
167
167
+
if let Ipld::String(s) = ipld {
168
168
+
Ok(s.clone())
169
169
+
} else {
170
170
+
Err(())
199
171
}
200
172
}