let first_line = html
.trim_start()
.lines()
- .into_iter()
.next()
.ok_or_else(|| LemmyError::from_message("No lines in html"))?
.to_lowercase();
.opengraph
.properties
.get("description")
- .map(|t| t.to_string());
+ .map(std::string::ToString::to_string);
let og_title = page
.opengraph
.properties
.get("title")
- .map(|t| t.to_string());
+ .map(std::string::ToString::to_string);
let og_image = page
.opengraph
.images
- .get(0)
+ .first()
.and_then(|ogo| Url::parse(&ogo.url).ok());
let og_embed_url = page
.opengraph
is_image_content_type(client, image_url).await?;
let fetch_url = format!(
- "{}/image/download?url={}",
+ "{}image/download?url={}",
pictrs_config.url,
utf8_percent_encode(image_url.as_str(), NON_ALPHANUMERIC) // TODO this might not be needed
);
// Warning, this may ignore SSL errors
let metadata_option = fetch_site_metadata(client, url).await.ok();
+ let missing_pictrs_file =
+ |r: PictrsResponse| r.files.first().expect("missing pictrs file").file.clone();
+
// Fetch pictrs thumbnail
let pictrs_hash = match &metadata_option {
Some(metadata_res) => match &metadata_res.image {
// Try to generate a small thumbnail if there's a full sized one from post-links
Some(metadata_image) => fetch_pictrs(client, settings, metadata_image)
.await
- .map(|r| r.files[0].file.to_owned()),
+ .map(missing_pictrs_file),
// Metadata, but no image
None => fetch_pictrs(client, settings, url)
.await
- .map(|r| r.files[0].file.to_owned()),
+ .map(missing_pictrs_file),
},
// No metadata, try to fetch the URL as an image
None => fetch_pictrs(client, settings, url)
.await
- .map(|r| r.files[0].file.to_owned()),
+ .map(missing_pictrs_file),
};
// The full urls are necessary for federation
use url::Url;
// These helped with testing
- #[actix_rt::test]
+ #[tokio::test]
async fn test_site_metadata() {
- let settings = &SETTINGS.to_owned();
+ let settings = &SETTINGS.clone();
let client = reqwest::Client::builder()
.user_agent(build_user_agent(settings))
.build()