Skip to content
This repository has been archived by the owner on Jun 29, 2024. It is now read-only.

Commit

Permalink
admin/emoji/updateの必須項目を減らす 等 (#13449)
Browse files Browse the repository at this point in the history
* admin/emoji/update enhancement

* add CustomEmojiService.getEmojiByName

* update endpoint

* fix

* Update update.ts

* Update autogen files

* type assertion

* Update CHANGELOG.md
  • Loading branch information
FineArchs authored Feb 25, 2024
1 parent 2c6f25b commit dd48366
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
- Fix: nodeinfoにenableMcaptchaとenableTurnstileが無いのを修正
- エンドポイント`flash/update``flashId`以外のパラメータは必須ではなくなりました
- Fix: 禁止キーワードを含むノートがDelayed Queueに追加されて再処理される問題を修正
- エンドポイント`admin/emoji/update`の各種修正
- 必須パラメータを`id`または`name`のいずれかのみに
- `id`の代わりに`name`で絵文字を指定可能に(`id``name`両指定時は従来通り`name`を変更する挙動)
- `category`および`licence`が指定なしの時勝手にnullに上書きされる挙動を修正

## 2024.2.0

Expand Down
5 changes: 5 additions & 0 deletions packages/backend/src/core/CustomEmojiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,11 @@ export class CustomEmojiService implements OnApplicationShutdown {
return this.emojisRepository.findOneBy({ id });
}

@bindThis
public getEmojiByName(name: string): Promise<MiEmoji | null> {
return this.emojisRepository.findOneBy({ name, host: IsNull() });
}

@bindThis
public dispose(): void {
this.cache.dispose();
Expand Down
27 changes: 18 additions & 9 deletions packages/backend/src/server/api/endpoints/admin/emoji/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ export const paramDef = {
type: 'string',
} },
},
required: ['id', 'name', 'aliases'],
anyOf: [
{ required: ['id'] },
{ required: ['name'] },
],
} as const;

@Injectable()
Expand All @@ -70,27 +73,33 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
) {
super(meta, paramDef, async (ps, me) => {
let driveFile;

if (ps.fileId) {
driveFile = await this.driveFilesRepository.findOneBy({ id: ps.fileId });
if (driveFile == null) throw new ApiError(meta.errors.noSuchFile);
}
const emoji = await this.customEmojiService.getEmojiById(ps.id);
if (emoji != null) {
if (ps.name !== emoji.name) {

let emojiId;
if (ps.id) {
emojiId = ps.id;
const emoji = await this.customEmojiService.getEmojiById(ps.id);
if (!emoji) throw new ApiError(meta.errors.noSuchEmoji);
if (ps.name && (ps.name !== emoji.name)) {
const isDuplicate = await this.customEmojiService.checkDuplicate(ps.name);
if (isDuplicate) throw new ApiError(meta.errors.sameNameEmojiExists);
}
} else {
throw new ApiError(meta.errors.noSuchEmoji);
if (!ps.name) throw new Error('Invalid Params unexpectedly passed. This is a BUG. Please report it to the development team.');
const emoji = await this.customEmojiService.getEmojiByName(ps.name);
if (!emoji) throw new ApiError(meta.errors.noSuchEmoji);
emojiId = emoji.id;
}

await this.customEmojiService.update(ps.id, {
await this.customEmojiService.update(emojiId, {
driveFile,
name: ps.name,
category: ps.category ?? null,
category: ps.category,
aliases: ps.aliases,
license: ps.license ?? null,
license: ps.license,
isSensitive: ps.isSensitive,
localOnly: ps.localOnly,
roleIdsThatCanBeUsedThisEmojiAsReaction: ps.roleIdsThatCanBeUsedThisEmojiAsReaction,
Expand Down
6 changes: 3 additions & 3 deletions packages/misskey-js/src/autogen/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7089,13 +7089,13 @@ export type operations = {
content: {
'application/json': {
/** Format: misskey:id */
id: string;
name: string;
id?: string;
name?: string;
/** Format: misskey:id */
fileId?: string;
/** @description Use `null` to reset the category. */
category?: string | null;
aliases: string[];
aliases?: string[];
license?: string | null;
isSensitive?: boolean;
localOnly?: boolean;
Expand Down

0 comments on commit dd48366

Please sign in to comment.