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.
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 not specified, all remote media will be deleted.
@ -815,6 +820,7 @@ impl Service {
RoomMessageEventContent::text_plain("Media deleted.")
}
AdminCommand::DeleteRemoteMedia {
dry_run,
origin,
} => {
if origin.as_deref() == Some(services().globals.server_name()) {
@ -851,12 +857,17 @@ impl Service {
}
count += 1;
services().media.delete(mxc).await?;
if !dry_run {
services().media.delete(mxc).await?;
}
}
RoomMessageEventContent::text_plain(format!(
"{count} media objects deleted."
))
let message = if dry_run {
format!("{count} media objects would be deleted.")
} else {
format!("{count} media objects deleted.")
};
RoomMessageEventContent::text_plain(message)
}
AdminCommand::DeactivateUser {
leave_rooms,