37 lines
1.2 KiB
TypeScript
37 lines
1.2 KiB
TypeScript
import { Inject, Injectable } from '@nestjs/common';
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
|
import { CustomEmojiService } from '@/core/CustomEmojiService.js';
|
|
import type { DriveFilesRepository } from '@/models/index.js';
|
|
import { DI } from '@/di-symbols.js';
|
|
import { ApiError } from '../../../error.js';
|
|
// eslint-disable-next-line import/no-default-export
|
|
@Injectable()
|
|
export default class extends Endpoint<'admin/emoji/update'> {
|
|
name = 'admin/emoji/update' as const;
|
|
constructor(
|
|
@Inject(DI.driveFilesRepository)
|
|
private driveFilesRepository: DriveFilesRepository,
|
|
|
|
private customEmojiService: CustomEmojiService,
|
|
) {
|
|
super(async (ps, me) => {
|
|
let driveFile;
|
|
|
|
if (ps.fileId) {
|
|
driveFile = await this.driveFilesRepository.findOneBy({ id: ps.fileId });
|
|
if (driveFile == null) throw new ApiError(this.meta.errors.noSuchFile);
|
|
}
|
|
|
|
await this.customEmojiService.update(ps.id, {
|
|
driveFile,
|
|
name: ps.name,
|
|
category: ps.category ?? null,
|
|
aliases: ps.aliases,
|
|
license: ps.license ?? null,
|
|
isSensitive: ps.isSensitive,
|
|
localOnly: ps.localOnly,
|
|
roleIdsThatCanBeUsedThisEmojiAsReaction: ps.roleIdsThatCanBeUsedThisEmojiAsReaction,
|
|
});
|
|
});
|
|
}
|
|
}
|