Skip to content

Commit

Permalink
fix(backend): カスタム絵文字のインポート時の動作を修正 (#12360)
Browse files Browse the repository at this point in the history
Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
  • Loading branch information
camilla-ett and syuilo authored Dec 2, 2023
1 parent c190b72 commit 8968bfd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
42 changes: 21 additions & 21 deletions packages/backend/src/server/api/endpoints/admin/emoji/copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
import { Inject, Injectable } from '@nestjs/common';
import { Endpoint } from '@/server/api/endpoint-base.js';
import type { EmojisRepository } from '@/models/_.js';
import { IdService } from '@/core/IdService.js';
import type { MiDriveFile } from '@/models/DriveFile.js';
import { DI } from '@/di-symbols.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 { ApiError } from '../../../error.js';

Expand All @@ -26,6 +25,11 @@ export const meta = {
code: 'NO_SUCH_EMOJI',
id: 'e2785b66-dca3-4087-9cac-b93c541cc425',
},
duplicateName: {
message: 'Duplicate name.',
code: 'DUPLICATE_NAME',
id: 'f7a3462c-4e6e-4069-8421-b9bd4f4c3975',
},
},

res: {
Expand Down Expand Up @@ -56,15 +60,12 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
constructor(
@Inject(DI.emojisRepository)
private emojisRepository: EmojisRepository,

private emojiEntityService: EmojiEntityService,
private idService: IdService,
private globalEventService: GlobalEventService,
private customEmojiService: CustomEmojiService,
private driveService: DriveService,
) {
super(meta, paramDef, async (ps, me) => {
const emoji = await this.emojisRepository.findOneBy({ id: ps.emojiId });

if (emoji == null) {
throw new ApiError(meta.errors.noSuchEmoji);
}
Expand All @@ -75,28 +76,27 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
// Create file
driveFile = await this.driveService.uploadFromUrl({ url: emoji.originalUrl, user: null, force: true });
} catch (e) {
// TODO: need to return Drive Error
throw new ApiError();
}

const copied = await this.emojisRepository.insert({
id: this.idService.gen(),
updatedAt: new Date(),
// Duplication Check
const isDuplicate = await this.customEmojiService.checkDuplicate(emoji.name);
if (isDuplicate) throw new ApiError(meta.errors.duplicateName);

const addedEmoji = await this.customEmojiService.add({
driveFile,
name: emoji.name,
category: emoji.category,
aliases: emoji.aliases,
host: null,
aliases: [],
originalUrl: driveFile.url,
publicUrl: driveFile.webpublicUrl ?? driveFile.url,
type: driveFile.webpublicType ?? driveFile.type,
license: emoji.license,
}).then(x => this.emojisRepository.findOneByOrFail(x.identifiers[0]));

this.globalEventService.publishBroadcastStream('emojiAdded', {
emoji: await this.emojiEntityService.packDetailed(copied.id),
});
isSensitive: emoji.isSensitive,
localOnly: emoji.localOnly,
roleIdsThatCanBeUsedThisEmojiAsReaction: emoji.roleIdsThatCanBeUsedThisEmojiAsReaction,
}, me);

return {
id: copied.id,
};
return this.emojiEntityService.packDetailed(addedEmoji);
});
}
}
4 changes: 2 additions & 2 deletions packages/frontend/src/pages/custom-emojis-manager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ const edit = (emoji) => {
}, 'closed');
};
const im = (emoji) => {
const importEmoji = (emoji) => {
os.apiWithDialog('admin/emoji/copy', {
emojiId: emoji.id,
});
Expand All @@ -168,7 +168,7 @@ const remoteMenu = (emoji, ev: MouseEvent) => {
}, {
text: i18n.ts.import,
icon: 'ti ti-plus',
action: () => { im(emoji); },
action: () => { importEmoji(emoji); },
}], ev.currentTarget ?? ev.target);
};
Expand Down

0 comments on commit 8968bfd

Please sign in to comment.