From 2b7e0dcb80fb5482dd4eedbb1ca2be18f6685162 Mon Sep 17 00:00:00 2001 From: strawberry Date: Sun, 25 Aug 2024 12:24:08 -0400 Subject: [PATCH] add admin command to delete all local media by a local user Signed-off-by: strawberry --- src/admin/media/commands.rs | 17 ++++++++++++++++- src/admin/media/mod.rs | 10 ++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/admin/media/commands.rs b/src/admin/media/commands.rs index 577d5aba..4d875635 100644 --- a/src/admin/media/commands.rs +++ b/src/admin/media/commands.rs @@ -1,7 +1,7 @@ use conduit::{debug, info, Result}; use ruma::{events::room::message::RoomMessageEventContent, EventId, MxcUri}; -use crate::admin_command; +use crate::{admin_command, utils::parse_local_user_id}; #[admin_command] pub(super) async fn delete( @@ -186,3 +186,18 @@ pub(super) async fn delete_past_remote_media(&self, duration: String, force: boo "Deleted {deleted_count} total files.", ))) } + +#[admin_command] +pub(super) async fn delete_all_from_user(&self, username: String, force: bool) -> Result { + let user_id = parse_local_user_id(self.services, &username)?; + + let deleted_count = self + .services + .media + .delete_from_user(&user_id, force) + .await?; + + Ok(RoomMessageEventContent::text_plain(format!( + "Deleted {deleted_count} total files.", + ))) +} diff --git a/src/admin/media/mod.rs b/src/admin/media/mod.rs index 31cbf810..3a1d4b11 100644 --- a/src/admin/media/mod.rs +++ b/src/admin/media/mod.rs @@ -32,8 +32,18 @@ pub(super) enum MediaCommand { /// - The duration (at or after), e.g. "5m" to delete all media in the /// past 5 minutes duration: String, + /// Continues deleting remote media if an undeletable object is found #[arg(short, long)] force: bool, }, + + /// - Deletes all the local media from a local user on our server + DeleteAllFromUser { + username: String, + + /// Continues deleting media if an undeletable object is found + #[arg(short, long)] + force: bool, + }, }