fix(backend): カスタム絵文字のインポート時の動作を修正 (#12360)
Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
This commit is contained in:
parent
c190b720d3
commit
8968bfd309
2 changed files with 23 additions and 23 deletions
|
@ -6,11 +6,10 @@
|
||||||
import { Inject, Injectable } from '@nestjs/common';
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
import { Endpoint } from '@/server/api/endpoint-base.js';
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
||||||
import type { EmojisRepository } from '@/models/_.js';
|
import type { EmojisRepository } from '@/models/_.js';
|
||||||
import { IdService } from '@/core/IdService.js';
|
|
||||||
import type { MiDriveFile } from '@/models/DriveFile.js';
|
import type { MiDriveFile } from '@/models/DriveFile.js';
|
||||||
import { DI } from '@/di-symbols.js';
|
import { DI } from '@/di-symbols.js';
|
||||||
import { DriveService } from '@/core/DriveService.js';
|
import { DriveService } from '@/core/DriveService.js';
|
||||||
import { GlobalEventService } from '@/core/GlobalEventService.js';
|
import { CustomEmojiService } from '@/core/CustomEmojiService.js';
|
||||||
import { EmojiEntityService } from '@/core/entities/EmojiEntityService.js';
|
import { EmojiEntityService } from '@/core/entities/EmojiEntityService.js';
|
||||||
import { ApiError } from '../../../error.js';
|
import { ApiError } from '../../../error.js';
|
||||||
|
|
||||||
|
@ -26,6 +25,11 @@ export const meta = {
|
||||||
code: 'NO_SUCH_EMOJI',
|
code: 'NO_SUCH_EMOJI',
|
||||||
id: 'e2785b66-dca3-4087-9cac-b93c541cc425',
|
id: 'e2785b66-dca3-4087-9cac-b93c541cc425',
|
||||||
},
|
},
|
||||||
|
duplicateName: {
|
||||||
|
message: 'Duplicate name.',
|
||||||
|
code: 'DUPLICATE_NAME',
|
||||||
|
id: 'f7a3462c-4e6e-4069-8421-b9bd4f4c3975',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
res: {
|
res: {
|
||||||
|
@ -56,15 +60,12 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(DI.emojisRepository)
|
@Inject(DI.emojisRepository)
|
||||||
private emojisRepository: EmojisRepository,
|
private emojisRepository: EmojisRepository,
|
||||||
|
|
||||||
private emojiEntityService: EmojiEntityService,
|
private emojiEntityService: EmojiEntityService,
|
||||||
private idService: IdService,
|
private customEmojiService: CustomEmojiService,
|
||||||
private globalEventService: GlobalEventService,
|
|
||||||
private driveService: DriveService,
|
private driveService: DriveService,
|
||||||
) {
|
) {
|
||||||
super(meta, paramDef, async (ps, me) => {
|
super(meta, paramDef, async (ps, me) => {
|
||||||
const emoji = await this.emojisRepository.findOneBy({ id: ps.emojiId });
|
const emoji = await this.emojisRepository.findOneBy({ id: ps.emojiId });
|
||||||
|
|
||||||
if (emoji == null) {
|
if (emoji == null) {
|
||||||
throw new ApiError(meta.errors.noSuchEmoji);
|
throw new ApiError(meta.errors.noSuchEmoji);
|
||||||
}
|
}
|
||||||
|
@ -75,28 +76,27 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
// Create file
|
// Create file
|
||||||
driveFile = await this.driveService.uploadFromUrl({ url: emoji.originalUrl, user: null, force: true });
|
driveFile = await this.driveService.uploadFromUrl({ url: emoji.originalUrl, user: null, force: true });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
// TODO: need to return Drive Error
|
||||||
throw new ApiError();
|
throw new ApiError();
|
||||||
}
|
}
|
||||||
|
|
||||||
const copied = await this.emojisRepository.insert({
|
// Duplication Check
|
||||||
id: this.idService.gen(),
|
const isDuplicate = await this.customEmojiService.checkDuplicate(emoji.name);
|
||||||
updatedAt: new Date(),
|
if (isDuplicate) throw new ApiError(meta.errors.duplicateName);
|
||||||
|
|
||||||
|
const addedEmoji = await this.customEmojiService.add({
|
||||||
|
driveFile,
|
||||||
name: emoji.name,
|
name: emoji.name,
|
||||||
|
category: emoji.category,
|
||||||
|
aliases: emoji.aliases,
|
||||||
host: null,
|
host: null,
|
||||||
aliases: [],
|
|
||||||
originalUrl: driveFile.url,
|
|
||||||
publicUrl: driveFile.webpublicUrl ?? driveFile.url,
|
|
||||||
type: driveFile.webpublicType ?? driveFile.type,
|
|
||||||
license: emoji.license,
|
license: emoji.license,
|
||||||
}).then(x => this.emojisRepository.findOneByOrFail(x.identifiers[0]));
|
isSensitive: emoji.isSensitive,
|
||||||
|
localOnly: emoji.localOnly,
|
||||||
|
roleIdsThatCanBeUsedThisEmojiAsReaction: emoji.roleIdsThatCanBeUsedThisEmojiAsReaction,
|
||||||
|
}, me);
|
||||||
|
|
||||||
this.globalEventService.publishBroadcastStream('emojiAdded', {
|
return this.emojiEntityService.packDetailed(addedEmoji);
|
||||||
emoji: await this.emojiEntityService.packDetailed(copied.id),
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
id: copied.id,
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -155,7 +155,7 @@ const edit = (emoji) => {
|
||||||
}, 'closed');
|
}, 'closed');
|
||||||
};
|
};
|
||||||
|
|
||||||
const im = (emoji) => {
|
const importEmoji = (emoji) => {
|
||||||
os.apiWithDialog('admin/emoji/copy', {
|
os.apiWithDialog('admin/emoji/copy', {
|
||||||
emojiId: emoji.id,
|
emojiId: emoji.id,
|
||||||
});
|
});
|
||||||
|
@ -168,7 +168,7 @@ const remoteMenu = (emoji, ev: MouseEvent) => {
|
||||||
}, {
|
}, {
|
||||||
text: i18n.ts.import,
|
text: i18n.ts.import,
|
||||||
icon: 'ti ti-plus',
|
icon: 'ti ti-plus',
|
||||||
action: () => { im(emoji); },
|
action: () => { importEmoji(emoji); },
|
||||||
}], ev.currentTarget ?? ev.target);
|
}], ev.currentTarget ?? ev.target);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue