1 use crate::{check_is_apub_id_valid, APUB_JSON_CONTENT_TYPE};
3 use lemmy_utils::{request::retry, LemmyError};
6 use serde::Deserialize;
7 use std::time::Duration;
10 /// Maximum number of HTTP requests allowed to handle a single incoming activity (or a single object
11 /// fetch through the search).
13 /// A community fetch will load the outbox with up to 20 items, and fetch the creator for each item.
14 /// So we are looking at a maximum of 22 requests (rounded up just to be safe).
15 static MAX_REQUEST_NUMBER: i32 = 25;
17 /// Fetch any type of ActivityPub object, handling things like HTTP headers, deserialisation,
19 pub(in crate::fetcher) async fn fetch_remote_object<Response>(
22 recursion_counter: &mut i32,
23 ) -> Result<Response, LemmyError>
25 Response: for<'de> Deserialize<'de> + std::fmt::Debug,
27 *recursion_counter += 1;
28 if *recursion_counter > MAX_REQUEST_NUMBER {
29 return Err(anyhow!("Maximum recursion depth reached").into());
31 check_is_apub_id_valid(url, false)?;
33 let timeout = Duration::from_secs(60);
38 .header("Accept", APUB_JSON_CONTENT_TYPE)
44 let object = res.json().await?;
45 info!("Fetched remote object {}", url);