mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-13 15:23:09 +02:00
60 lines
1.5 KiB
TypeScript
60 lines
1.5 KiB
TypeScript
import { Inject, Injectable } from '@nestjs/common';
|
|
import { DataSource } from 'typeorm';
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
|
import { EmojisRepository } from '@/models/index.js';
|
|
import { DI } from '@/di-symbols.js';
|
|
import { ModerationLogService } from '@/core/ModerationLogService.js';
|
|
import { ApiError } from '../../../error.js';
|
|
|
|
export const meta = {
|
|
tags: ['admin'],
|
|
|
|
requireCredential: true,
|
|
requireModerator: true,
|
|
|
|
errors: {
|
|
noSuchEmoji: {
|
|
message: 'No such emoji.',
|
|
code: 'NO_SUCH_EMOJI',
|
|
id: 'be83669b-773a-44b7-b1f8-e5e5170ac3c2',
|
|
},
|
|
},
|
|
} as const;
|
|
|
|
export const paramDef = {
|
|
type: 'object',
|
|
properties: {
|
|
id: { type: 'string', format: 'misskey:id' },
|
|
},
|
|
required: ['id'],
|
|
} as const;
|
|
|
|
// TODO: ロジックをサービスに切り出す
|
|
|
|
// eslint-disable-next-line import/no-default-export
|
|
@Injectable()
|
|
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|
constructor(
|
|
@Inject(DI.db)
|
|
private db: DataSource,
|
|
|
|
@Inject(DI.emojisRepository)
|
|
private emojisRepository: EmojisRepository,
|
|
|
|
private moderationLogService: ModerationLogService,
|
|
) {
|
|
super(meta, paramDef, async (ps, me) => {
|
|
const emoji = await this.emojisRepository.findOneBy({ id: ps.id });
|
|
|
|
if (emoji == null) throw new ApiError(meta.errors.noSuchEmoji);
|
|
|
|
await this.emojisRepository.delete(emoji.id);
|
|
|
|
await this.db.queryResultCache!.remove(['meta_emojis']);
|
|
|
|
this.moderationLogService.insertModerationLog(me, 'deleteEmoji', {
|
|
emoji: emoji,
|
|
});
|
|
});
|
|
}
|
|
}
|