mirror of
https://codeberg.org/yeentown/barkey.git
synced 2025-04-30 10:46:55 +00:00
fix "delete file when updating emoji" logic
This commit is contained in:
parent
5781e99861
commit
19d3cdfa37
1 changed files with 12 additions and 12 deletions
|
@ -175,17 +175,6 @@ export class CustomEmojiService implements OnApplicationShutdown {
|
||||||
if (isDuplicate) return 'SAME_NAME_EMOJI_EXISTS';
|
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, {
|
await this.emojisRepository.update(emoji.id, {
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
name: data.name,
|
name: data.name,
|
||||||
|
@ -202,6 +191,17 @@ export class CustomEmojiService implements OnApplicationShutdown {
|
||||||
|
|
||||||
this.localEmojisCache.refresh();
|
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);
|
const packed = await this.emojiEntityService.packDetailed(emoji.id);
|
||||||
|
|
||||||
if (!doNameUpdate) {
|
if (!doNameUpdate) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue