add dry-run mode to delete-remote-media-files admin command

This commit is contained in:
Benjamin Lee 2024-09-15 01:04:39 -07:00
parent 9d14c5d461
commit ba7b224c38
No known key found for this signature in database
GPG key ID: FB9624E2885D55A4

View file

@ -189,6 +189,11 @@ enum AdminCommand {
/// ///
/// This media may still be fetched and cached again in the future. /// This media may still be fetched and cached again in the future.
DeleteRemoteMedia { DeleteRemoteMedia {
/// Output the number of media objects that would be deleted, but do
/// not actually delete anything.
#[clap(short, long)]
dry_run: bool,
/// If specified, only delete remote media from this origin. /// If specified, only delete remote media from this origin.
/// ///
/// If not specified, all remote media will be deleted. /// If not specified, all remote media will be deleted.
@ -815,6 +820,7 @@ impl Service {
RoomMessageEventContent::text_plain("Media deleted.") RoomMessageEventContent::text_plain("Media deleted.")
} }
AdminCommand::DeleteRemoteMedia { AdminCommand::DeleteRemoteMedia {
dry_run,
origin, origin,
} => { } => {
if origin.as_deref() == Some(services().globals.server_name()) { if origin.as_deref() == Some(services().globals.server_name()) {
@ -851,12 +857,17 @@ impl Service {
} }
count += 1; count += 1;
if !dry_run {
services().media.delete(mxc).await?; services().media.delete(mxc).await?;
} }
}
RoomMessageEventContent::text_plain(format!( let message = if dry_run {
"{count} media objects deleted." format!("{count} media objects would be deleted.")
)) } else {
format!("{count} media objects deleted.")
};
RoomMessageEventContent::text_plain(message)
} }
AdminCommand::DeactivateUser { AdminCommand::DeactivateUser {
leave_rooms, leave_rooms,