Make delete-emoji command accept emoji name and hostname instead of ID

This commit is contained in:
silverpill 2023-01-21 21:25:51 +00:00
parent f6026293a5
commit 97145efad9
5 changed files with 34 additions and 4 deletions

View file

@ -12,6 +12,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Added `import-emoji` command.
- Added support for emoji shortcodes.
### Changed
- Make `delete-emoji` command accept emoji name and hostname instead of ID.
### Security
- Validate emoji name before saving.

View file

@ -53,7 +53,7 @@ mitractl delete-post 55a3005f-f293-4168-ab70-6ab09a879679
Delete custom emoji:
```shell
mitractl delete-emoji 55a3005f-f293-4168-ab70-6ab09a879679
mitractl delete-emoji emoji_name example.org
```
Remove remote posts and media older than 30 days:
@ -77,7 +77,7 @@ mitractl delete-empty-profiles 100
Import custom emoji from another instance:
```shell
mitractl import-emoji emojiname example.org
mitractl import-emoji emoji_name example.org
```
Generate ethereum address:

View file

@ -19,6 +19,7 @@ use crate::ethereum::{
use crate::models::{
attachments::queries::delete_unused_attachments,
cleanup::find_orphaned_files,
emojis::helpers::get_emoji_by_name,
emojis::queries::{
create_emoji,
delete_emoji,
@ -267,7 +268,8 @@ impl DeletePost {
/// Delete custom emoji
#[derive(Parser)]
pub struct DeleteEmoji {
id: Uuid,
emoji_name: String,
hostname: Option<String>,
}
impl DeleteEmoji {
@ -276,7 +278,12 @@ impl DeleteEmoji {
config: &Config,
db_client: &impl DatabaseClient,
) -> Result<(), Error> {
let deletion_queue = delete_emoji(db_client, &self.id).await?;
let emoji = get_emoji_by_name(
db_client,
&self.emoji_name,
self.hostname.as_deref(),
).await?;
let deletion_queue = delete_emoji(db_client, &emoji.id).await?;
deletion_queue.process(config).await;
println!("emoji deleted");
Ok(())

View file

@ -0,0 +1,18 @@
use crate::database::{DatabaseClient, DatabaseError};
use super::types::DbEmoji;
use super::queries::{
get_local_emoji_by_name,
get_emoji_by_name_and_hostname,
};
pub async fn get_emoji_by_name(
db_client: &impl DatabaseClient,
emoji_name: &str,
maybe_hostname: Option<&str>,
) -> Result<DbEmoji, DatabaseError> {
if let Some(hostname) = maybe_hostname {
get_emoji_by_name_and_hostname(db_client, emoji_name, hostname).await
} else {
get_local_emoji_by_name(db_client, emoji_name).await
}
}

View file

@ -1,3 +1,4 @@
pub mod helpers;
pub mod queries;
pub mod types;
pub mod validators;