2022-09-18 03:27:08 +09:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
|
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
2023-04-06 11:14:43 +09:00
|
|
|
import { CustomEmojiService } from '@/core/CustomEmojiService.js';
|
2023-05-18 18:45:49 +09:00
|
|
|
import type { DriveFilesRepository } from '@/models/index.js';
|
|
|
|
|
import { DI } from '@/di-symbols.js';
|
2023-02-17 15:36:36 +09:00
|
|
|
import { ApiError } from '../../../error.js';
|
2022-01-03 02:12:50 +09:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2022-09-18 03:27:08 +09:00
|
|
|
@Injectable()
|
2023-05-26 07:32:15 +00:00
|
|
|
export default class extends Endpoint<'admin/emoji/update'> {
|
|
|
|
|
name = 'admin/emoji/update' as const;
|
2022-09-18 03:27:08 +09:00
|
|
|
constructor(
|
2023-05-18 18:45:49 +09:00
|
|
|
@Inject(DI.driveFilesRepository)
|
|
|
|
|
private driveFilesRepository: DriveFilesRepository,
|
|
|
|
|
|
2023-04-06 11:14:43 +09:00
|
|
|
private customEmojiService: CustomEmojiService,
|
2022-09-18 03:27:08 +09:00
|
|
|
) {
|
2023-05-26 07:32:15 +00:00
|
|
|
super(async (ps, me) => {
|
2023-05-18 18:45:49 +09:00
|
|
|
let driveFile;
|
|
|
|
|
|
|
|
|
|
if (ps.fileId) {
|
|
|
|
|
driveFile = await this.driveFilesRepository.findOneBy({ id: ps.fileId });
|
2023-05-26 07:32:15 +00:00
|
|
|
if (driveFile == null) throw new ApiError(this.meta.errors.noSuchFile);
|
2023-05-18 18:45:49 +09:00
|
|
|
}
|
|
|
|
|
|
2023-04-06 11:14:43 +09:00
|
|
|
await this.customEmojiService.update(ps.id, {
|
2023-05-18 18:45:49 +09:00
|
|
|
driveFile,
|
2022-09-18 03:27:08 +09:00
|
|
|
name: ps.name,
|
2023-04-06 11:14:43 +09:00
|
|
|
category: ps.category ?? null,
|
2022-09-18 03:27:08 +09:00
|
|
|
aliases: ps.aliases,
|
2023-04-06 11:14:43 +09:00
|
|
|
license: ps.license ?? null,
|
2023-05-18 18:45:49 +09:00
|
|
|
isSensitive: ps.isSensitive,
|
|
|
|
|
localOnly: ps.localOnly,
|
|
|
|
|
roleIdsThatCanBeUsedThisEmojiAsReaction: ps.roleIdsThatCanBeUsedThisEmojiAsReaction,
|
2022-09-18 03:27:08 +09:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|