2 use actix_web::web::Data;
3 use lemmy_api_common::{
5 request::purge_image_from_pictrs,
6 site::{PurgeItemResponse, PurgePost},
7 utils::{is_top_admin, local_user_view_from_jwt},
11 moderator::{AdminPurgePost, AdminPurgePostForm},
16 use lemmy_utils::error::LemmyError;
18 #[async_trait::async_trait(?Send)]
19 impl Perform for PurgePost {
20 type Response = PurgeItemResponse;
22 #[tracing::instrument(skip(context))]
23 async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
24 let data: &Self = self;
25 let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
27 // Only let the top admin purge an item
28 is_top_admin(context.pool(), local_user_view.person.id).await?;
30 let post_id = data.post_id;
32 // Read the post to get the community_id
33 let post = Post::read(context.pool(), post_id).await?;
36 if let Some(url) = post.url {
37 purge_image_from_pictrs(context.client(), context.settings(), &url)
42 if let Some(thumbnail_url) = post.thumbnail_url {
43 purge_image_from_pictrs(context.client(), context.settings(), &thumbnail_url)
48 let community_id = post.community_id;
50 Post::delete(context.pool(), post_id).await?;
53 let reason = data.reason.clone();
54 let form = AdminPurgePostForm {
55 admin_person_id: local_user_view.person.id,
60 AdminPurgePost::create(context.pool(), &form).await?;
62 Ok(PurgeItemResponse { success: true })