Make delete-emoji command accept emoji name and hostname instead of ID
This commit is contained in:
parent
f6026293a5
commit
97145efad9
5 changed files with 34 additions and 4 deletions
|
@ -12,6 +12,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
- Added `import-emoji` command.
|
- Added `import-emoji` command.
|
||||||
- Added support for emoji shortcodes.
|
- Added support for emoji shortcodes.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Make `delete-emoji` command accept emoji name and hostname instead of ID.
|
||||||
|
|
||||||
### Security
|
### Security
|
||||||
|
|
||||||
- Validate emoji name before saving.
|
- Validate emoji name before saving.
|
||||||
|
|
|
@ -53,7 +53,7 @@ mitractl delete-post 55a3005f-f293-4168-ab70-6ab09a879679
|
||||||
Delete custom emoji:
|
Delete custom emoji:
|
||||||
|
|
||||||
```shell
|
```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:
|
Remove remote posts and media older than 30 days:
|
||||||
|
@ -77,7 +77,7 @@ mitractl delete-empty-profiles 100
|
||||||
Import custom emoji from another instance:
|
Import custom emoji from another instance:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
mitractl import-emoji emojiname example.org
|
mitractl import-emoji emoji_name example.org
|
||||||
```
|
```
|
||||||
|
|
||||||
Generate ethereum address:
|
Generate ethereum address:
|
||||||
|
|
11
src/cli.rs
11
src/cli.rs
|
@ -19,6 +19,7 @@ use crate::ethereum::{
|
||||||
use crate::models::{
|
use crate::models::{
|
||||||
attachments::queries::delete_unused_attachments,
|
attachments::queries::delete_unused_attachments,
|
||||||
cleanup::find_orphaned_files,
|
cleanup::find_orphaned_files,
|
||||||
|
emojis::helpers::get_emoji_by_name,
|
||||||
emojis::queries::{
|
emojis::queries::{
|
||||||
create_emoji,
|
create_emoji,
|
||||||
delete_emoji,
|
delete_emoji,
|
||||||
|
@ -267,7 +268,8 @@ impl DeletePost {
|
||||||
/// Delete custom emoji
|
/// Delete custom emoji
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
pub struct DeleteEmoji {
|
pub struct DeleteEmoji {
|
||||||
id: Uuid,
|
emoji_name: String,
|
||||||
|
hostname: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DeleteEmoji {
|
impl DeleteEmoji {
|
||||||
|
@ -276,7 +278,12 @@ impl DeleteEmoji {
|
||||||
config: &Config,
|
config: &Config,
|
||||||
db_client: &impl DatabaseClient,
|
db_client: &impl DatabaseClient,
|
||||||
) -> Result<(), Error> {
|
) -> 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;
|
deletion_queue.process(config).await;
|
||||||
println!("emoji deleted");
|
println!("emoji deleted");
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
18
src/models/emojis/helpers.rs
Normal file
18
src/models/emojis/helpers.rs
Normal 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
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,3 +1,4 @@
|
||||||
|
pub mod helpers;
|
||||||
pub mod queries;
|
pub mod queries;
|
||||||
pub mod types;
|
pub mod types;
|
||||||
pub mod validators;
|
pub mod validators;
|
||||||
|
|
Loading…
Reference in a new issue