summaryrefslogtreecommitdiff
path: root/packages/backend/src/core/CustomEmojiService.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/backend/src/core/CustomEmojiService.ts')
-rw-r--r--packages/backend/src/core/CustomEmojiService.ts24
1 files changed, 12 insertions, 12 deletions
diff --git a/packages/backend/src/core/CustomEmojiService.ts b/packages/backend/src/core/CustomEmojiService.ts
index 3f7ad5b947..165d58d1b2 100644
--- a/packages/backend/src/core/CustomEmojiService.ts
+++ b/packages/backend/src/core/CustomEmojiService.ts
@@ -147,7 +147,7 @@ export class CustomEmojiService implements OnApplicationShutdown {
@bindThis
public async update(data: (
{ id: MiEmoji['id'], name?: string; } | { name: string; id?: MiEmoji['id'], }
- ) & {
+ ) & {
originalUrl?: string;
publicUrl?: string;
fileType?: string;
@@ -175,17 +175,6 @@ export class CustomEmojiService implements OnApplicationShutdown {
if (isDuplicate) return 'SAME_NAME_EMOJI_EXISTS';
}
- // If we're changing the file, then we need to delete the old one
- if (data.originalUrl != null && data.originalUrl !== emoji.originalUrl) {
- const oldFile = await this.driveFilesRepository.findOneBy({ url: emoji.originalUrl, userHost: emoji.host ? emoji.host : IsNull() });
- const newFile = await this.driveFilesRepository.findOneBy({ url: data.originalUrl, userHost: emoji.host ? emoji.host : IsNull() });
-
- // But DON'T delete if this is the same file reference, otherwise we'll break the emoji!
- if (oldFile && newFile && oldFile.id !== newFile.id) {
- await this.driveService.deleteFile(oldFile, false, moderator ? moderator : undefined);
- }
- }
-
await this.emojisRepository.update(emoji.id, {
updatedAt: new Date(),
name: data.name,
@@ -202,6 +191,17 @@ export class CustomEmojiService implements OnApplicationShutdown {
this.localEmojisCache.refresh();
+ // If we're changing the file, then we need to delete the old one
+ if (data.originalUrl != null && data.originalUrl !== emoji.originalUrl) {
+ const oldFile = await this.driveFilesRepository.findOneBy({ url: emoji.originalUrl, userHost: emoji.host ? emoji.host : IsNull() });
+ const newFile = await this.driveFilesRepository.findOneBy({ url: data.originalUrl, userHost: emoji.host ? emoji.host : IsNull() });
+
+ // But DON'T delete if this is the same file reference, otherwise we'll break the emoji!
+ if (oldFile && newFile && oldFile.id !== newFile.id) {
+ await this.driveService.deleteFile(oldFile, false, moderator ? moderator : undefined);
+ }
+ }
+
const packed = await this.emojiEntityService.packDetailed(emoji.id);
if (!doNameUpdate) {