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
chore: clean up code
Signed-off-by: rooot <hey@rooot.gay>
rooot.gay
5 months ago
d01f4ce6
f138d357
+19
-22
3 changed files
expand all
collapse all
unified
split
src
bsky.rs
main.rs
meow.rs
+9
-11
src/bsky.rs
···
1
1
+
use crate::ManagedBskyAgent;
1
2
use crate::meow::{
2
3
BotCheck, DidPlcResponse, EmbedAuthor, EmbedMedia, EmbedResponse, EmbedSource, EmbedThingy,
3
4
GenericError, MissingElementError,
4
5
};
5
5
-
use crate::ManagedBskyAgent;
6
6
use bsky_sdk::api::app::bsky::embed::images::ImageData;
7
7
use bsky_sdk::api::app::bsky::embed::video;
8
8
use bsky_sdk::api::types::TypedBlobRef::Blob;
9
9
use bsky_sdk::api::types::Union::Refs;
10
10
use bsky_sdk::api::types::{DataModel, LimitedU16, TryFromUnknown, Unknown};
11
11
use ipld_core::ipld::Ipld;
12
12
-
use rocket::{get, State};
12
12
+
use rocket::{State, get};
13
13
use std::ops::Deref;
14
14
15
15
#[get("/profile/<name>/post/<post>")]
···
77
77
}
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) == Ok("app.bsky.feed.post".to_string()) {
80
80
+
if let Unknown::Object(record) = data.record
81
81
+
&& 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).ok();
84
84
···
121
121
let unknown_embed = Unknown::Other(embeds.clone());
122
122
let mut blobs = Vec::new();
123
123
124
124
-
if let Ipld::Map(map) = embeds.clone().deref() {
125
125
-
if ipld_to_string(map.get_key_value("$type").ok_or(MissingElementError("$type".into()))?.1) == Ok("app.bsky.embed.video".to_string()) {
124
124
+
if let Ipld::Map(map) = embeds.clone().deref()
125
125
+
&& ipld_to_string(map.get_key_value("$type").ok_or(MissingElementError("$type".into()))?.1) == Ok("app.bsky.embed.video".to_string()) {
126
126
// bug: this crashes at runtime. error handling my asshole
127
127
// this is also why we need those 2 checks above
128
128
let bite_me = video::Main::try_from_unknown(unknown_embed);
129
129
130
130
-
if let Ok(thing) = bite_me {
131
131
-
if let bsky_sdk::api::types::BlobRef::Typed(Blob(blob)) = &thing.video {
130
130
+
if let Ok(thing) = bite_me
131
131
+
&& let bsky_sdk::api::types::BlobRef::Typed(Blob(blob)) = &thing.video {
132
132
blobs.push(blob.clone());
133
133
}
134
134
-
}
135
135
-
}
136
134
}
137
135
138
136
for image in images {
···
158
156
source,
159
157
}));
160
158
}
161
161
-
}
159
159
+
162
160
}
163
161
bsky_sdk::api::app::bsky::feed::get_post_thread::OutputThreadRefs::AppBskyFeedDefsNotFoundPost(_) => {
164
162
return Err(GenericError::TooTired);
+2
-2
src/main.rs
···
3
3
mod meow;
4
4
mod srv;
5
5
6
6
-
use bsky_sdk::agent::config::FileStore;
7
6
use bsky_sdk::BskyAgent;
8
8
-
use rocket::{routes, Config};
7
7
+
use bsky_sdk::agent::config::FileStore;
8
8
+
use rocket::{Config, routes};
9
9
use std::net::Ipv4Addr;
10
10
use std::path::Path;
11
11
+8
-9
src/meow.rs
···
3
3
use rocket::http::{ContentType, RawStr, Status};
4
4
use rocket::request::{FromRequest, Outcome};
5
5
use rocket::response::{Redirect, Responder};
6
6
-
use rocket::{response, Request, Response};
6
6
+
use rocket::{Request, Response, response};
7
7
use serde::ser::SerializeMap;
8
8
use serde::{Deserialize, Serialize};
9
9
use thiserror::Error;
···
148
148
"".to_string()
149
149
},
150
150
|host| {
151
151
-
let is_https = req
152
152
-
.headers()
153
153
-
.get_one("x-forwarded-proto")
154
154
-
.map_or(false, |x| x == "https");
151
151
+
let is_https =
152
152
+
req.headers().get_one("x-forwarded-proto") == Some("https");
155
153
format!("{}://{}", if is_https { "https" } else { "http" }, host)
156
154
},
157
155
);
···
308
306
type Error = ();
309
307
310
308
async fn from_request(req: &'r Request<'_>) -> Outcome<Self, Self::Error> {
311
311
-
if let Some(user_agent) = req.headers().get_one("user-agent") {
312
312
-
if !is_bot(user_agent) {
313
313
-
return Outcome::Success(Self(true));
314
314
-
}
309
309
+
if let Some(user_agent) = req.headers().get_one("user-agent")
310
310
+
&& !is_bot(user_agent)
311
311
+
{
312
312
+
return Outcome::Success(Self(true));
315
313
}
314
314
+
316
315
Outcome::Success(Self(false))
317
316
}
318
317
}