|
|
|
@ -42,7 +42,6 @@ use lemmy_utils::{
|
|
|
|
|
utils::slurs::build_slur_regex,
|
|
|
|
|
};
|
|
|
|
|
use regex::Regex;
|
|
|
|
|
use reqwest_middleware::ClientWithMiddleware;
|
|
|
|
|
use rosetta_i18n::{Language, LanguageId};
|
|
|
|
|
use tracing::warn;
|
|
|
|
|
use url::{ParseError, Url};
|
|
|
|
@ -529,19 +528,16 @@ pub fn check_private_instance_and_federation_enabled(
|
|
|
|
|
|
|
|
|
|
pub async fn purge_image_posts_for_person(
|
|
|
|
|
banned_person_id: PersonId,
|
|
|
|
|
pool: &mut DbPool<'_>,
|
|
|
|
|
settings: &Settings,
|
|
|
|
|
client: &ClientWithMiddleware,
|
|
|
|
|
context: &LemmyContext,
|
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
|
let pool = &mut context.pool();
|
|
|
|
|
let posts = Post::fetch_pictrs_posts_for_creator(pool, banned_person_id).await?;
|
|
|
|
|
for post in posts {
|
|
|
|
|
if let Some(url) = post.url {
|
|
|
|
|
purge_image_from_pictrs(client, settings, &url).await.ok();
|
|
|
|
|
purge_image_from_pictrs(&url, context).await.ok();
|
|
|
|
|
}
|
|
|
|
|
if let Some(thumbnail_url) = post.thumbnail_url {
|
|
|
|
|
purge_image_from_pictrs(client, settings, &thumbnail_url)
|
|
|
|
|
.await
|
|
|
|
|
.ok();
|
|
|
|
|
purge_image_from_pictrs(&thumbnail_url, context).await.ok();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -552,19 +548,16 @@ pub async fn purge_image_posts_for_person(
|
|
|
|
|
|
|
|
|
|
pub async fn purge_image_posts_for_community(
|
|
|
|
|
banned_community_id: CommunityId,
|
|
|
|
|
pool: &mut DbPool<'_>,
|
|
|
|
|
settings: &Settings,
|
|
|
|
|
client: &ClientWithMiddleware,
|
|
|
|
|
context: &LemmyContext,
|
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
|
let pool = &mut context.pool();
|
|
|
|
|
let posts = Post::fetch_pictrs_posts_for_community(pool, banned_community_id).await?;
|
|
|
|
|
for post in posts {
|
|
|
|
|
if let Some(url) = post.url {
|
|
|
|
|
purge_image_from_pictrs(client, settings, &url).await.ok();
|
|
|
|
|
purge_image_from_pictrs(&url, context).await.ok();
|
|
|
|
|
}
|
|
|
|
|
if let Some(thumbnail_url) = post.thumbnail_url {
|
|
|
|
|
purge_image_from_pictrs(client, settings, &thumbnail_url)
|
|
|
|
|
.await
|
|
|
|
|
.ok();
|
|
|
|
|
purge_image_from_pictrs(&thumbnail_url, context).await.ok();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -575,21 +568,16 @@ pub async fn purge_image_posts_for_community(
|
|
|
|
|
|
|
|
|
|
pub async fn remove_user_data(
|
|
|
|
|
banned_person_id: PersonId,
|
|
|
|
|
pool: &mut DbPool<'_>,
|
|
|
|
|
settings: &Settings,
|
|
|
|
|
client: &ClientWithMiddleware,
|
|
|
|
|
context: &LemmyContext,
|
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
|
let pool = &mut context.pool();
|
|
|
|
|
// Purge user images
|
|
|
|
|
let person = Person::read(pool, banned_person_id).await?;
|
|
|
|
|
if let Some(avatar) = person.avatar {
|
|
|
|
|
purge_image_from_pictrs(client, settings, &avatar)
|
|
|
|
|
.await
|
|
|
|
|
.ok();
|
|
|
|
|
purge_image_from_pictrs(&avatar, context).await.ok();
|
|
|
|
|
}
|
|
|
|
|
if let Some(banner) = person.banner {
|
|
|
|
|
purge_image_from_pictrs(client, settings, &banner)
|
|
|
|
|
.await
|
|
|
|
|
.ok();
|
|
|
|
|
purge_image_from_pictrs(&banner, context).await.ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update the fields to None
|
|
|
|
@ -608,7 +596,7 @@ pub async fn remove_user_data(
|
|
|
|
|
Post::update_removed_for_creator(pool, banned_person_id, None, true).await?;
|
|
|
|
|
|
|
|
|
|
// Purge image posts
|
|
|
|
|
purge_image_posts_for_person(banned_person_id, pool, settings, client).await?;
|
|
|
|
|
purge_image_posts_for_person(banned_person_id, context).await?;
|
|
|
|
|
|
|
|
|
|
// Communities
|
|
|
|
|
// Remove all communities where they're the top mod
|
|
|
|
@ -635,12 +623,10 @@ pub async fn remove_user_data(
|
|
|
|
|
|
|
|
|
|
// Delete the community images
|
|
|
|
|
if let Some(icon) = first_mod_community.community.icon {
|
|
|
|
|
purge_image_from_pictrs(client, settings, &icon).await.ok();
|
|
|
|
|
purge_image_from_pictrs(&icon, context).await.ok();
|
|
|
|
|
}
|
|
|
|
|
if let Some(banner) = first_mod_community.community.banner {
|
|
|
|
|
purge_image_from_pictrs(client, settings, &banner)
|
|
|
|
|
.await
|
|
|
|
|
.ok();
|
|
|
|
|
purge_image_from_pictrs(&banner, context).await.ok();
|
|
|
|
|
}
|
|
|
|
|
// Update the fields to None
|
|
|
|
|
Community::update(
|
|
|
|
@ -695,23 +681,18 @@ pub async fn remove_user_data_in_community(
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub async fn delete_user_account(
|
|
|
|
|
pub async fn purge_user_account(
|
|
|
|
|
person_id: PersonId,
|
|
|
|
|
pool: &mut DbPool<'_>,
|
|
|
|
|
settings: &Settings,
|
|
|
|
|
client: &ClientWithMiddleware,
|
|
|
|
|
context: &LemmyContext,
|
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
|
let pool = &mut context.pool();
|
|
|
|
|
// Delete their images
|
|
|
|
|
let person = Person::read(pool, person_id).await?;
|
|
|
|
|
if let Some(avatar) = person.avatar {
|
|
|
|
|
purge_image_from_pictrs(client, settings, &avatar)
|
|
|
|
|
.await
|
|
|
|
|
.ok();
|
|
|
|
|
purge_image_from_pictrs(&avatar, context).await.ok();
|
|
|
|
|
}
|
|
|
|
|
if let Some(banner) = person.banner {
|
|
|
|
|
purge_image_from_pictrs(client, settings, &banner)
|
|
|
|
|
.await
|
|
|
|
|
.ok();
|
|
|
|
|
purge_image_from_pictrs(&banner, context).await.ok();
|
|
|
|
|
}
|
|
|
|
|
// No need to update avatar and banner, those are handled in Person::delete_account
|
|
|
|
|
|
|
|
|
@ -726,7 +707,7 @@ pub async fn delete_user_account(
|
|
|
|
|
.with_lemmy_type(LemmyErrorType::CouldntUpdatePost)?;
|
|
|
|
|
|
|
|
|
|
// Purge image posts
|
|
|
|
|
purge_image_posts_for_person(person_id, pool, settings, client).await?;
|
|
|
|
|
purge_image_posts_for_person(person_id, context).await?;
|
|
|
|
|
|
|
|
|
|
// Leave communities they mod
|
|
|
|
|
CommunityModerator::leave_all_communities(pool, person_id).await?;
|
|
|
|
|