mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
refactor: ♻️ Rewrite media management code
This commit is contained in:
parent
d09f74e58a
commit
faf829437d
34 changed files with 1195 additions and 904 deletions
|
|
@ -2,12 +2,12 @@ import { Args } from "@oclif/core";
|
|||
import chalk from "chalk";
|
||||
import { and, eq, isNull } from "drizzle-orm";
|
||||
import ora from "ora";
|
||||
import { MediaManager } from "~/classes/media/media-manager";
|
||||
import { BaseCommand } from "~/cli/base";
|
||||
import { Emojis } from "~/drizzle/schema";
|
||||
import { config } from "~/packages/config-manager";
|
||||
import { Attachment } from "~/packages/database-interface/attachment";
|
||||
import { Emoji } from "~/packages/database-interface/emoji";
|
||||
import { MediaBackend } from "~/packages/media-manager";
|
||||
|
||||
export default class EmojiAdd extends BaseCommand<typeof EmojiAdd> {
|
||||
static override args = {
|
||||
|
|
@ -97,14 +97,11 @@ export default class EmojiAdd extends BaseCommand<typeof EmojiAdd> {
|
|||
);
|
||||
}
|
||||
|
||||
const media = await MediaBackend.fromBackendType(
|
||||
config.media.backend,
|
||||
config,
|
||||
);
|
||||
const mediaManager = new MediaManager(config);
|
||||
|
||||
const spinner = ora("Uploading emoji").start();
|
||||
|
||||
const uploaded = await media.addFile(file).catch((e: Error) => {
|
||||
const uploaded = await mediaManager.addFile(file).catch((e: Error) => {
|
||||
spinner.fail();
|
||||
this.log(`${chalk.red("✗")} Error: ${chalk.red(e.message)}`);
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -3,12 +3,12 @@ import { Flags } from "@oclif/core";
|
|||
import chalk from "chalk";
|
||||
import { eq } from "drizzle-orm";
|
||||
import ora from "ora";
|
||||
import { MediaManager } from "~/classes/media/media-manager";
|
||||
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
|
||||
|
|
@ -84,12 +84,9 @@ export default class EmojiDelete extends EmojiFinderCommand<
|
|||
emojis.findIndex((e) => e.id === emoji.id) + 1
|
||||
}/${emojis.length})`;
|
||||
|
||||
const mediaBackend = await MediaBackend.fromBackendType(
|
||||
config.media.backend,
|
||||
config,
|
||||
);
|
||||
const mediaManager = new MediaManager(config);
|
||||
|
||||
await mediaBackend.deleteFileByUrl(emoji.url);
|
||||
await mediaManager.deleteFileByUrl(emoji.url);
|
||||
|
||||
await db.delete(Emojis).where(eq(Emojis.id, emoji.id));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,12 +4,12 @@ import { and, inArray, isNull } from "drizzle-orm";
|
|||
import { lookup } from "mime-types";
|
||||
import ora from "ora";
|
||||
import { unzip } from "unzipit";
|
||||
import { MediaManager } from "~/classes/media/media-manager";
|
||||
import { BaseCommand } from "~/cli/base";
|
||||
import { Emojis } from "~/drizzle/schema";
|
||||
import { config } from "~/packages/config-manager";
|
||||
import { Attachment } from "~/packages/database-interface/attachment";
|
||||
import { Emoji } from "~/packages/database-interface/emoji";
|
||||
import { MediaBackend } from "~/packages/media-manager";
|
||||
|
||||
type MetaType = {
|
||||
emojis: {
|
||||
|
|
@ -169,10 +169,7 @@ export default class EmojiImport extends BaseCommand<typeof EmojiImport> {
|
|||
|
||||
const importSpinner = ora("Importing emojis").start();
|
||||
|
||||
const media = await MediaBackend.fromBackendType(
|
||||
config.media.backend,
|
||||
config,
|
||||
);
|
||||
const mediaManager = new MediaManager(config);
|
||||
|
||||
const successfullyImported: MetaType["emojis"] = [];
|
||||
|
||||
|
|
@ -200,14 +197,16 @@ export default class EmojiImport extends BaseCommand<typeof EmojiImport> {
|
|||
type: contentType,
|
||||
});
|
||||
|
||||
const uploaded = await media.addFile(newFile).catch((e: Error) => {
|
||||
this.log(
|
||||
`${chalk.red("✗")} Error uploading ${chalk.red(
|
||||
emoji.emoji.name,
|
||||
)}: ${chalk.red(e.message)}`,
|
||||
);
|
||||
return null;
|
||||
});
|
||||
const uploaded = await mediaManager
|
||||
.addFile(newFile)
|
||||
.catch((e: Error) => {
|
||||
this.log(
|
||||
`${chalk.red("✗")} Error uploading ${chalk.red(
|
||||
emoji.emoji.name,
|
||||
)}: ${chalk.red(e.message)}`,
|
||||
);
|
||||
return null;
|
||||
});
|
||||
|
||||
if (!uploaded) {
|
||||
continue;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue