2 use actix_web::web::Data;
3 use lemmy_api_common::{
5 request::purge_image_from_pictrs,
6 site::{PurgeItemResponse, PurgePost},
7 utils::{get_local_user_view_from_jwt, is_admin},
11 moderator::{AdminPurgePost, AdminPurgePostForm},
16 use lemmy_utils::{error::LemmyError, ConnectionId};
18 #[async_trait::async_trait(?Send)]
19 impl Perform for PurgePost {
20 type Response = PurgeItemResponse;
22 #[tracing::instrument(skip(context, _websocket_id))]
25 context: &Data<LemmyContext>,
26 _websocket_id: Option<ConnectionId>,
27 ) -> Result<Self::Response, LemmyError> {
28 let data: &Self = self;
30 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
32 // Only let admins purge an item
33 is_admin(&local_user_view)?;
35 let post_id = data.post_id;
37 // Read the post to get the community_id
38 let post = Post::read(context.pool(), post_id).await?;
41 if let Some(url) = post.url {
42 purge_image_from_pictrs(context.client(), context.settings(), &url)
47 if let Some(thumbnail_url) = post.thumbnail_url {
48 purge_image_from_pictrs(context.client(), context.settings(), &thumbnail_url)
53 let community_id = post.community_id;
55 Post::delete(context.pool(), post_id).await?;
58 let reason = data.reason.clone();
59 let form = AdminPurgePostForm {
60 admin_person_id: local_user_view.person.id,
65 AdminPurgePost::create(context.pool(), &form).await?;
67 Ok(PurgeItemResponse { success: true })