admin/emoji/updateの必須項目を減らす 等 (#13449)

* admin/emoji/update enhancement

* add CustomEmojiService.getEmojiByName

* update endpoint

* fix

* Update update.ts

* Update autogen files

* type assertion

* Update CHANGELOG.md
This commit is contained in:
FineArchs 2024-02-25 18:06:26 +09:00 committed by GitHub
parent 2c6f25b710
commit dd48366ed8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 30 additions and 12 deletions

View File

@ -28,6 +28,10 @@
- Fix: nodeinfoにenableMcaptchaとenableTurnstileが無いのを修正 - Fix: nodeinfoにenableMcaptchaとenableTurnstileが無いのを修正
- エンドポイント`flash/update`の`flashId`以外のパラメータは必須ではなくなりました - エンドポイント`flash/update`の`flashId`以外のパラメータは必須ではなくなりました
- Fix: 禁止キーワードを含むートがDelayed Queueに追加されて再処理される問題を修正 - Fix: 禁止キーワードを含むートがDelayed Queueに追加されて再処理される問題を修正
- エンドポイント`admin/emoji/update`の各種修正
- 必須パラメータを`id`または`name`のいずれかのみに
- `id`の代わりに`name`で絵文字を指定可能に(`id`・`name`両指定時は従来通り`name`を変更する挙動)
- `category`および`licence`が指定なしの時勝手にnullに上書きされる挙動を修正
## 2024.2.0 ## 2024.2.0

View File

@ -393,6 +393,11 @@ export class CustomEmojiService implements OnApplicationShutdown {
return this.emojisRepository.findOneBy({ id }); return this.emojisRepository.findOneBy({ id });
} }
@bindThis
public getEmojiByName(name: string): Promise<MiEmoji | null> {
return this.emojisRepository.findOneBy({ name, host: IsNull() });
}
@bindThis @bindThis
public dispose(): void { public dispose(): void {
this.cache.dispose(); this.cache.dispose();

View File

@ -57,7 +57,10 @@ export const paramDef = {
type: 'string', type: 'string',
} }, } },
}, },
required: ['id', 'name', 'aliases'], anyOf: [
{ required: ['id'] },
{ required: ['name'] },
],
} as const; } as const;
@Injectable() @Injectable()
@ -70,27 +73,33 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
) { ) {
super(meta, paramDef, async (ps, me) => { super(meta, paramDef, async (ps, me) => {
let driveFile; let driveFile;
if (ps.fileId) { if (ps.fileId) {
driveFile = await this.driveFilesRepository.findOneBy({ id: ps.fileId }); driveFile = await this.driveFilesRepository.findOneBy({ id: ps.fileId });
if (driveFile == null) throw new ApiError(meta.errors.noSuchFile); if (driveFile == null) throw new ApiError(meta.errors.noSuchFile);
} }
let emojiId;
if (ps.id) {
emojiId = ps.id;
const emoji = await this.customEmojiService.getEmojiById(ps.id); const emoji = await this.customEmojiService.getEmojiById(ps.id);
if (emoji != null) { if (!emoji) throw new ApiError(meta.errors.noSuchEmoji);
if (ps.name !== emoji.name) { if (ps.name && (ps.name !== emoji.name)) {
const isDuplicate = await this.customEmojiService.checkDuplicate(ps.name); const isDuplicate = await this.customEmojiService.checkDuplicate(ps.name);
if (isDuplicate) throw new ApiError(meta.errors.sameNameEmojiExists); if (isDuplicate) throw new ApiError(meta.errors.sameNameEmojiExists);
} }
} else { } 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, driveFile,
name: ps.name, name: ps.name,
category: ps.category ?? null, category: ps.category,
aliases: ps.aliases, aliases: ps.aliases,
license: ps.license ?? null, license: ps.license,
isSensitive: ps.isSensitive, isSensitive: ps.isSensitive,
localOnly: ps.localOnly, localOnly: ps.localOnly,
roleIdsThatCanBeUsedThisEmojiAsReaction: ps.roleIdsThatCanBeUsedThisEmojiAsReaction, roleIdsThatCanBeUsedThisEmojiAsReaction: ps.roleIdsThatCanBeUsedThisEmojiAsReaction,

View File

@ -7089,13 +7089,13 @@ export type operations = {
content: { content: {
'application/json': { 'application/json': {
/** Format: misskey:id */ /** Format: misskey:id */
id: string; id?: string;
name: string; name?: string;
/** Format: misskey:id */ /** Format: misskey:id */
fileId?: string; fileId?: string;
/** @description Use `null` to reset the category. */ /** @description Use `null` to reset the category. */
category?: string | null; category?: string | null;
aliases: string[]; aliases?: string[];
license?: string | null; license?: string | null;
isSensitive?: boolean; isSensitive?: boolean;
localOnly?: boolean; localOnly?: boolean;