mirror of
https://gitlab.com/famedly/conduit.git
synced 2025-06-27 16:35:59 +00:00
refactor(service/admin): improve readability for command processing
This commit is contained in:
parent
39c09f865a
commit
d079df63c3
1 changed files with 10 additions and 11 deletions
|
@ -9,7 +9,6 @@ use std::{
|
||||||
use bytesize::ByteSize;
|
use bytesize::ByteSize;
|
||||||
use chrono::DateTime;
|
use chrono::DateTime;
|
||||||
use clap::{Args, Parser};
|
use clap::{Args, Parser};
|
||||||
use futures_util::future::Either;
|
|
||||||
use image::GenericImageView;
|
use image::GenericImageView;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use ruma::{
|
use ruma::{
|
||||||
|
@ -1252,9 +1251,8 @@ impl Service {
|
||||||
|
|
||||||
RoomMessageEventContent::text_html(markdown_message, html_message).into()
|
RoomMessageEventContent::text_html(markdown_message, html_message).into()
|
||||||
},
|
},
|
||||||
AdminCommand::PurgeMedia => media_from_body(body).map_or_else(
|
AdminCommand::PurgeMedia => match media_from_body(body) {
|
||||||
|message| Either::Left(async move { message }),
|
Ok(media) => {
|
||||||
|media| Either::Right(async move {
|
|
||||||
let failed_count = services().media.purge(&media, true).await.len();
|
let failed_count = services().media.purge(&media, true).await.len();
|
||||||
|
|
||||||
if failed_count == 0 {
|
if failed_count == 0 {
|
||||||
|
@ -1264,8 +1262,9 @@ impl Service {
|
||||||
"Failed to delete {failed_count} media, check logs for more details"
|
"Failed to delete {failed_count} media, check logs for more details"
|
||||||
))
|
))
|
||||||
}.into()
|
}.into()
|
||||||
}),
|
},
|
||||||
).await,
|
Err(message) => message,
|
||||||
|
}
|
||||||
AdminCommand::PurgeMediaFromUsers {
|
AdminCommand::PurgeMediaFromUsers {
|
||||||
from_last,
|
from_last,
|
||||||
force_filehash,
|
force_filehash,
|
||||||
|
@ -1331,9 +1330,8 @@ impl Service {
|
||||||
))
|
))
|
||||||
}.into()
|
}.into()
|
||||||
}
|
}
|
||||||
AdminCommand::BlockMedia { and_purge, reason } => media_from_body(body).map_or_else(
|
AdminCommand::BlockMedia { and_purge, reason } => match media_from_body(body) {
|
||||||
|message| Either::Left(async move { message }),
|
Ok(media) =>{
|
||||||
|media| Either::Right(async move {
|
|
||||||
let failed_count = services().media.block(&media, reason).len();
|
let failed_count = services().media.block(&media, reason).len();
|
||||||
let failed_purge_count = if and_purge {
|
let failed_purge_count = if and_purge {
|
||||||
services().media.purge(&media, true).await.len()
|
services().media.purge(&media, true).await.len()
|
||||||
|
@ -1353,8 +1351,9 @@ impl Service {
|
||||||
"Failed to block {failed_count}, and purge {failed_purge_count} media, check logs for more details"
|
"Failed to block {failed_count}, and purge {failed_purge_count} media, check logs for more details"
|
||||||
))
|
))
|
||||||
}.into()
|
}.into()
|
||||||
}),
|
},
|
||||||
).await,
|
Err(message) => message,
|
||||||
|
}
|
||||||
AdminCommand::BlockMediaFromUsers { from_last, reason } => {
|
AdminCommand::BlockMediaFromUsers { from_last, reason } => {
|
||||||
let after = from_last.map(unix_secs_from_duration).transpose()?;
|
let after = from_last.map(unix_secs_from_duration).transpose()?;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue