mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
fix(api): 🐛 Deleting emojis now removes them from object storage
This commit is contained in:
parent
7846a03bcf
commit
29d7b09677
5 changed files with 119 additions and 11 deletions
|
|
@ -7,6 +7,8 @@ import { EmojiFinderCommand } from "~cli/classes";
|
|||
import { formatArray } from "~cli/utils/format";
|
||||
import { db } from "~drizzle/db";
|
||||
import { Emojis } from "~drizzle/schema";
|
||||
import { config } from "~packages/config-manager";
|
||||
import { MediaBackend } from "~packages/media-manager";
|
||||
|
||||
export default class EmojiDelete extends EmojiFinderCommand<
|
||||
typeof EmojiDelete
|
||||
|
|
@ -77,16 +79,22 @@ export default class EmojiDelete extends EmojiFinderCommand<
|
|||
|
||||
const spinner = ora("Deleting emoji(s)").start();
|
||||
|
||||
await db.delete(Emojis).where(
|
||||
inArray(
|
||||
Emojis.id,
|
||||
emojis.map((e) => e.id),
|
||||
),
|
||||
);
|
||||
for (const emoji of emojis) {
|
||||
spinner.text = `Deleting emoji ${chalk.gray(emoji.shortcode)} (${
|
||||
emojis.findIndex((e) => e.id === emoji.id) + 1
|
||||
}/${emojis.length})`;
|
||||
|
||||
spinner.succeed();
|
||||
const mediaBackend = await MediaBackend.fromBackendType(
|
||||
config.media.backend,
|
||||
config,
|
||||
);
|
||||
|
||||
this.log(chalk.bold(`${chalk.green("✓")} Emoji(s) deleted`));
|
||||
await mediaBackend.deleteFileByUrl(emoji.url);
|
||||
|
||||
await db.delete(Emojis).where(eq(Emojis.id, emoji.id));
|
||||
}
|
||||
|
||||
spinner.succeed("Emoji(s) deleted");
|
||||
|
||||
this.exit(0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { and, eq, getTableColumns, isNotNull, isNull } from "drizzle-orm";
|
|||
import { BaseCommand } from "~cli/base";
|
||||
import { formatArray } from "~cli/utils/format";
|
||||
import { db } from "~drizzle/db";
|
||||
import { Emojis, Instances } from "~drizzle/schema";
|
||||
import { Emojis, Instances, Users } from "~drizzle/schema";
|
||||
|
||||
export default class EmojiList extends BaseCommand<typeof EmojiList> {
|
||||
static override args = {};
|
||||
|
|
@ -36,6 +36,10 @@ export default class EmojiList extends BaseCommand<typeof EmojiList> {
|
|||
description: "Limit the number of emojis",
|
||||
default: 200,
|
||||
}),
|
||||
username: Flags.string({
|
||||
char: "u",
|
||||
description: "Filter by username",
|
||||
}),
|
||||
};
|
||||
|
||||
public async run(): Promise<void> {
|
||||
|
|
@ -45,17 +49,29 @@ export default class EmojiList extends BaseCommand<typeof EmojiList> {
|
|||
.select({
|
||||
...getTableColumns(Emojis),
|
||||
instanceUrl: Instances.baseUrl,
|
||||
owner: Users.username,
|
||||
})
|
||||
.from(Emojis)
|
||||
.leftJoin(Instances, eq(Emojis.instanceId, Instances.id))
|
||||
.leftJoin(Users, eq(Emojis.ownerId, Users.id))
|
||||
.where(
|
||||
and(
|
||||
flags.local ? isNull(Emojis.instanceId) : undefined,
|
||||
flags.remote ? isNotNull(Emojis.instanceId) : undefined,
|
||||
flags.username
|
||||
? eq(Users.username, flags.username)
|
||||
: undefined,
|
||||
),
|
||||
);
|
||||
|
||||
const keys = ["id", "shortcode", "alt", "contentType", "instanceUrl"];
|
||||
const keys = [
|
||||
"id",
|
||||
"shortcode",
|
||||
"alt",
|
||||
"contentType",
|
||||
"instanceUrl",
|
||||
"owner",
|
||||
];
|
||||
|
||||
this.log(
|
||||
formatArray(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue