1 use crate::{check_is_apub_id_valid, APUB_JSON_CONTENT_TYPE};
3 use lemmy_utils::{request::retry, settings::structs::Settings, 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>(
23 recursion_counter: &mut i32,
24 ) -> Result<Response, LemmyError>
26 Response: for<'de> Deserialize<'de> + std::fmt::Debug,
28 *recursion_counter += 1;
29 if *recursion_counter > MAX_REQUEST_NUMBER {
30 return Err(anyhow!("Maximum recursion depth reached").into());
32 check_is_apub_id_valid(url, false, settings)?;
34 let timeout = Duration::from_secs(60);
39 .header("Accept", APUB_JSON_CONTENT_TYPE)
45 let object = res.json().await?;
46 info!("Fetched remote object {}", url);