summaryrefslogtreecommitdiff
path: root/packages/backend/src
diff options
context:
space:
mode:
authorHazelnoot <acomputerdog@gmail.com>2025-02-03 18:20:26 -0500
committerHazelnoot <acomputerdog@gmail.com>2025-02-03 18:20:26 -0500
commit19d3cdfa3705cfcaacda49ad63cbd9b0b17c8d79 (patch)
tree1bc8041a69a5afa0d4d266b998954a9230965781 /packages/backend/src
parentport FriendlyCaptcha to the new captcha infrastructure (diff)
downloadsharkey-19d3cdfa3705cfcaacda49ad63cbd9b0b17c8d79.tar.gz
sharkey-19d3cdfa3705cfcaacda49ad63cbd9b0b17c8d79.tar.bz2
sharkey-19d3cdfa3705cfcaacda49ad63cbd9b0b17c8d79.zip
fix "delete file when updating emoji" logic
Diffstat (limited to 'packages/backend/src')
-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) {