+pub const FEDERATION_HTTP_FETCH_LIMIT: u32 = 50;
+/// All incoming and outgoing federation actions read the blocklist/allowlist and slur filters
+/// multiple times. This causes a huge number of database reads if we hit the db directly. So we
+/// cache these values for a short time, which will already make a huge difference and ensures that
+/// changes take effect quickly.
+const BLOCKLIST_CACHE_DURATION: Duration = Duration::from_secs(60);
+
+static CONTEXT: Lazy<Vec<serde_json::Value>> = Lazy::new(|| {
+ serde_json::from_str(include_str!("../assets/lemmy/context.json")).expect("parse context")
+});
+
+#[derive(Clone)]
+pub struct VerifyUrlData(pub ActualDbPool);
+
+#[async_trait]
+impl UrlVerifier for VerifyUrlData {
+ async fn verify(&self, url: &Url) -> Result<(), &'static str> {
+ let local_site_data = local_site_data_cached(&mut (&self.0).into())
+ .await
+ .expect("read local site data");
+ check_apub_id_valid(url, &local_site_data).map_err(|err| match err {
+ LemmyError {
+ error_type: LemmyErrorType::FederationDisabled,
+ ..
+ } => "Federation disabled",
+ LemmyError {
+ error_type: LemmyErrorType::DomainBlocked(_),
+ ..
+ } => "Domain is blocked",
+ LemmyError {
+ error_type: LemmyErrorType::DomainNotInAllowList(_),
+ ..
+ } => "Domain is not in allowlist",
+ _ => "Failed validating apub id",
+ })?;
+ Ok(())
+ }
+}
+