This commit is contained in:
FineArchs 2024-10-11 14:15:44 +09:00
parent 77ae12bf18
commit f965b35a2c
2 changed files with 10 additions and 6 deletions

View File

@ -114,20 +114,20 @@ export class CustomEmojiService implements OnApplicationShutdown {
localOnly?: boolean; localOnly?: boolean;
roleIdsThatCanBeUsedThisEmojiAsReaction?: MiRole['id'][]; roleIdsThatCanBeUsedThisEmojiAsReaction?: MiRole['id'][];
}, moderator?: MiUser): Promise< }, moderator?: MiUser): Promise<
undefined void
| "NO_SUCH_EMOJI" | "NO_SUCH_EMOJI"
| "SAME_NAME_EMOJI_EXISTS" | "SAME_NAME_EMOJI_EXISTS"
> { > {
const emoji = data.id const emoji = data.id
? await this.getEmojiById(data.id) ? await this.getEmojiById(data.id)
: await this.getEmojiByName(data.name); : await this.getEmojiByName(data.name!);
if (emoji === null) return "NO_SUCH_EMOJI"; if (emoji === null) return "NO_SUCH_EMOJI";
const id = emoji.id; const id = emoji.id;
// IDと絵文字名が両方指定されている場合は絵文字名の変更を行うため重複チェックが必要 // IDと絵文字名が両方指定されている場合は絵文字名の変更を行うため重複チェックが必要
const doNameUpdate = data.id && data.name && (data.name !== emoji.name); const doNameUpdate = data.id && data.name && (data.name !== emoji.name);
if (doNameUpdate) { if (doNameUpdate) {
const isDuplicate = await this.checkDuplicate(data.name); const isDuplicate = await this.checkDuplicate(data.name!);
if (isDuplicate) return "SAME_NAME_EMOJI_EXISTS"; if (isDuplicate) return "SAME_NAME_EMOJI_EXISTS";
} }

View File

@ -6,7 +6,7 @@
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 { CustomEmojiService } from '@/core/CustomEmojiService.js'; import { CustomEmojiService } from '@/core/CustomEmojiService.js';
import type { DriveFilesRepository } from '@/models/_.js'; import type { DriveFilesRepository, MiEmoji } from '@/models/_.js';
import { DI } from '@/di-symbols.js'; import { DI } from '@/di-symbols.js';
import { ApiError } from '../../../error.js'; import { ApiError } from '../../../error.js';
@ -78,9 +78,13 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
if (driveFile == null) throw new ApiError(meta.errors.noSuchFile); if (driveFile == null) throw new ApiError(meta.errors.noSuchFile);
} }
// JSON schemeのanyOfの型変換がうまくいっていないらしい
const required = { id: ps.id, name: ps.name } as
| { id: MiEmoji['id']; name?: string }
| { id?: MiEmoji['id']; name: string };
const error = await this.customEmojiService.update({ const error = await this.customEmojiService.update({
id: ps.id, ...required,
name: ps.name,
driveFile, driveFile,
category: ps.category, category: ps.category,
aliases: ps.aliases, aliases: ps.aliases,