Fix fetch_local_site_data

This commit is contained in:
dull b 2023-07-04 03:25:02 +00:00
parent 53a1837f38
commit b375b693be
10 changed files with 15 additions and 19 deletions

View File

@ -118,10 +118,7 @@ impl SiteOrCommunity {
}
}
async fn generate_cc(
target: &SiteOrCommunity,
mut conn: impl DbConn,
) -> Result<Vec<Url>, LemmyError> {
async fn generate_cc(target: &SiteOrCommunity, conn: impl DbConn) -> Result<Vec<Url>, LemmyError> {
Ok(match target {
SiteOrCommunity::Site(_) => Site::read_remote_sites(conn)
.await?

View File

@ -33,7 +33,7 @@ pub async fn resolve_object(
async fn convert_response(
object: SearchableObjects,
user_id: PersonId,
mut conn: impl DbConn,
conn: impl DbConn,
) -> Result<Json<ResolveObjectResponse>, LemmyError> {
use SearchableObjects::*;
let removed_or_deleted;

View File

@ -9,7 +9,7 @@ use lemmy_db_schema::{
local_site::LocalSite,
},
traits::Crud,
utils::{get_conn, DbConn, DbPool},
utils::{get_conn, DbPool},
};
use lemmy_utils::{error::LemmyError, settings::structs::Settings};
use once_cell::sync::Lazy;
@ -38,8 +38,7 @@ pub struct VerifyUrlData(pub DbPool);
#[async_trait]
impl UrlVerifier for VerifyUrlData {
async fn verify(&self, url: &Url) -> Result<(), &'static str> {
let mut conn = get_conn(&self.0).await.expect("get connection");
let local_site_data = fetch_local_site_data(&mut *conn)
let local_site_data = fetch_local_site_data(&self.0)
.await
.expect("read local site data");
check_apub_id_valid(url, &local_site_data)?;
@ -99,12 +98,12 @@ pub(crate) struct LocalSiteData {
}
pub(crate) async fn fetch_local_site_data(
mut conn: impl DbConn,
pool: &DbPool,
) -> Result<LocalSiteData, diesel::result::Error> {
// LocalSite may be missing
let local_site = LocalSite::read(&mut *conn).await.ok();
let allowed_instances = Instance::allowlist(&mut *conn).await?;
let blocked_instances = Instance::blocklist(&mut *conn).await?;
let local_site = LocalSite::read(get_conn(pool).await?).await.ok();
let allowed_instances = Instance::allowlist(get_conn(pool).await?).await?;
let blocked_instances = Instance::blocklist(get_conn(pool).await?).await?;
Ok(LocalSiteData {
local_site,

View File

@ -132,7 +132,7 @@ impl Object for ApubComment {
verify_domains_match(note.attributed_to.inner(), note.id.inner())?;
verify_is_public(&note.to, &note.cc)?;
let community = note.community(context).await?;
let local_site_data = fetch_local_site_data(context.conn().await?).await?;
let local_site_data = fetch_local_site_data(context.pool()).await?;
check_apub_id_valid_with_strictness(
note.id.inner(),

View File

@ -188,7 +188,7 @@ impl ApubCommunity {
) -> Result<Vec<Url>, LemmyError> {
let id = self.id;
let local_site_data = fetch_local_site_data(context.conn().await?).await?;
let local_site_data = fetch_local_site_data(context.pool()).await?;
let follows = CommunityFollowerView::for_community(context.conn().await?, id).await?;
let inboxes: Vec<Url> = follows
.into_iter()

View File

@ -113,7 +113,7 @@ impl Object for ApubSite {
expected_domain: &Url,
data: &Data<Self::DataType>,
) -> Result<(), LemmyError> {
let local_site_data = fetch_local_site_data(data.conn().await?).await?;
let local_site_data = fetch_local_site_data(data.pool()).await?;
check_apub_id_valid_with_strictness(apub.id.inner(), true, &local_site_data, data.settings())?;
verify_domains_match(expected_domain, apub.id.inner())?;

View File

@ -118,7 +118,7 @@ impl Object for ApubPerson {
expected_domain: &Url,
context: &Data<Self::DataType>,
) -> Result<(), LemmyError> {
let local_site_data = fetch_local_site_data(context.conn().await?).await?;
let local_site_data = fetch_local_site_data(context.pool()).await?;
let slur_regex = &local_site_opt_to_slur_regex(&local_site_data.local_site);
check_slurs(&person.preferred_username, slur_regex)?;

View File

@ -143,7 +143,7 @@ impl Object for ApubPost {
verify_is_remote_object(page.id.inner(), context.settings())?;
};
let local_site_data = fetch_local_site_data(context.conn().await?).await?;
let local_site_data = fetch_local_site_data(context.pool()).await?;
let community = page.community(context).await?;
check_apub_id_valid_with_strictness(

View File

@ -102,7 +102,7 @@ impl Object for ApubPrivateMessage {
verify_domains_match(note.id.inner(), expected_domain)?;
verify_domains_match(note.attributed_to.inner(), note.id.inner())?;
let local_site_data = fetch_local_site_data(context.conn().await?).await?;
let local_site_data = fetch_local_site_data(context.pool()).await?;
check_apub_id_valid_with_strictness(
note.id.inner(),

View File

@ -80,7 +80,7 @@ impl Group {
expected_domain: &Url,
context: &LemmyContext,
) -> Result<(), LemmyError> {
let local_site_data = fetch_local_site_data(context.conn().await?).await?;
let local_site_data = fetch_local_site_data(context.pool()).await?;
check_apub_id_valid_with_strictness(
self.id.inner(),