Skip to content

Commit

Permalink
Merge commit 'refs/pull/11941/head' of https://github.com/misskey-dev…
Browse files Browse the repository at this point in the history
…/misskey into develop
  • Loading branch information
noridev committed Sep 30, 2023
2 parents 207bd64 + f5cc70d commit 70b6714
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
12 changes: 12 additions & 0 deletions packages/backend/src/core/CustomEmojiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,18 @@ export class CustomEmojiService implements OnApplicationShutdown {
this.cache.set(`${emoji.name} ${emoji.host}`, emoji);
}
}
/**
* ローカル内の絵文字に重複がないかチェックします
* @param name 絵文字名
*/
public async isDuplicateCheck(name: string): Promise<boolean> {
return (await this.emojisRepository.findOneBy({ name, host: IsNull() })) !== null;
}

@bindThis
public async getEmojiById(id: string): Promise<MiEmoji | null> {
return this.emojisRepository.findOneBy({ id });
}

@bindThis
public dispose(): void {
Expand Down
8 changes: 7 additions & 1 deletion packages/backend/src/server/api/endpoints/admin/emoji/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ export const meta = {
code: 'NO_SUCH_FILE',
id: 'fc46b5a4-6b92-4c33-ac66-b806659bb5cf',
},
duplicateName: {
message: 'Duplicate name.',
code: 'DUPLICATE_NAME',
id: 'f7a3462c-4e6e-4069-8421-b9bd4f4c3975',
},
},
} as const;

Expand Down Expand Up @@ -64,7 +69,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
super(meta, paramDef, async (ps, me) => {
const driveFile = await this.driveFilesRepository.findOneBy({ id: ps.fileId });
if (driveFile == null) throw new ApiError(meta.errors.noSuchFile);

const duplicateCheck = await this.customEmojiService.isDuplicateCheck(ps.name);
if (duplicateCheck != null) throw new ApiError(meta.errors.duplicateName);
const emoji = await this.customEmojiService.add({
driveFile,
name: ps.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
driveFile = await this.driveFilesRepository.findOneBy({ id: ps.fileId });
if (driveFile == null) throw new ApiError(meta.errors.noSuchFile);
}
const oldemoji = await this.customEmojiService.getEmojiById(ps.id);
if (oldemoji !== null) {
if (ps.name !== oldemoji.name) {
const duplicateCheck = await this.customEmojiService.isDuplicateCheck(ps.name);
if (duplicateCheck) throw new ApiError(meta.errors.sameNameEmojiExists);
}
} else {
throw new ApiError(meta.errors.noSuchEmoji);
}

await this.customEmojiService.update(ps.id, {
driveFile,
Expand Down

0 comments on commit 70b6714

Please sign in to comment.