+18
-3
src/meow.rs
+18
-3
src/meow.rs
···
35
35
}
36
36
37
37
impl<'r, 'o: 'r> Responder<'r, 'o> for EmbedThingy {
38
-
fn respond_to(self, _req: &'r Request<'_>) -> response::Result<'o> {
38
+
fn respond_to(self, req: &'r Request<'_>) -> response::Result<'o> {
39
39
let mut html = String::new();
40
40
html.push_str("<!DOCTYPE html>\n<html>\n<head>\n");
41
41
html.push_str("<meta charset=\"UTF-8\">\n");
···
122
122
html.push('\n');
123
123
124
124
// push oembed - we only do this for videos bcs discord is stupid
125
-
// todo: use rocket request guard to grab the Host header instead of hardcoding the url
125
+
let host = req.host().map_or_else(
126
+
|| {
127
+
eprintln!(
128
+
"WARNING: couldn't get host from request - oembed won't work!"
129
+
);
130
+
"".to_string()
131
+
},
132
+
|host| {
133
+
let is_https = req
134
+
.headers()
135
+
.get_one("x-forwarded-proto")
136
+
.map_or(false, |x| x == "https");
137
+
format!("{}://{}", if is_https { "https" } else { "http" }, host)
138
+
},
139
+
);
140
+
126
141
let mut oembed_url =
127
-
Url::parse("https://dev.boobsky.app/api/v1/oembed").unwrap();
142
+
Url::parse(format!("{}/api/v1/oembed", host).as_str()).unwrap();
128
143
if let Some(ref text) = self.text {
129
144
oembed_url.set_query(Some(&format!("desc={}", text)));
130
145
} else {