-async fn fetch_iframely_and_pictrs_data(
- client: &Client,
- url: Option<String>,
-) -> (
- Option<String>,
- Option<String>,
- Option<String>,
- Option<String>,
-) {
- match &url {
- Some(url) => {
- // Fetch iframely data
- let (iframely_title, iframely_description, iframely_thumbnail_url, iframely_html) =
- match fetch_iframely(client, url).await {
- Ok(res) => (res.title, res.description, res.thumbnail_url, res.html),
- Err(e) => {
- error!("iframely err: {}", e);
- (None, None, None, None)
- }
- };
-
- // Fetch pictrs thumbnail
- let pictrs_hash = match iframely_thumbnail_url {
- Some(iframely_thumbnail_url) => match fetch_pictrs(client, &iframely_thumbnail_url).await {
- Ok(res) => Some(res.files[0].file.to_owned()),
- Err(e) => {
- error!("pictrs err: {}", e);
- None
- }
- },
- // Try to generate a small thumbnail if iframely is not supported
- None => match fetch_pictrs(client, &url).await {
- Ok(res) => Some(res.files[0].file.to_owned()),
- Err(e) => {
- error!("pictrs err: {}", e);
- None
- }
- },
- };
-
- // The full urls are necessary for federation
- let pictrs_thumbnail = if let Some(pictrs_hash) = pictrs_hash {
- Some(format!(
- "{}://{}/pictrs/image/{}",
- get_apub_protocol_string(),
- Settings::get().hostname,
- pictrs_hash
- ))
- } else {
- None
- };
-
- (
- iframely_title,
- iframely_description,
- iframely_html,
- pictrs_thumbnail,
- )
- }
- None => (None, None, None, None),
- }
-}
+ let user_agent = build_user_agent(&settings);
+ let reqwest_client = Client::builder()
+ .user_agent(user_agent.clone())
+ .timeout(REQWEST_TIMEOUT)
+ .connect_timeout(REQWEST_TIMEOUT)
+ .build()?;
+
+ let client = ClientBuilder::new(reqwest_client.clone())
+ .with(TracingMiddleware::default())
+ .build();
+
+ // Pictrs cannot use the retry middleware
+ let pictrs_client = ClientBuilder::new(reqwest_client.clone())
+ .with(TracingMiddleware::default())
+ .build();
+
+ let context = LemmyContext::create(
+ pool.clone(),
+ client.clone(),
+ secret.clone(),
+ rate_limit_cell.clone(),
+ );