2022-09-17 20:27:08 +02:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
|
|
import { DataSource, In } from 'typeorm';
|
|
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
2022-09-20 22:33:11 +02:00
|
|
|
import type { EmojisRepository } from '@/models/index.js';
|
2022-09-17 20:27:08 +02:00
|
|
|
import { DI } from '@/di-symbols.js';
|
2022-01-12 16:47:05 +01:00
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
tags: ['admin'],
|
|
|
|
|
2022-01-18 14:27:10 +01:00
|
|
|
requireCredential: true,
|
2023-01-15 12:52:53 +01:00
|
|
|
requireRolePolicy: 'canManageCustomEmojis',
|
2022-02-19 06:05:32 +01:00
|
|
|
} as const;
|
2022-01-12 16:47:05 +01:00
|
|
|
|
2022-02-20 05:15:40 +01:00
|
|
|
export const paramDef = {
|
2022-02-19 06:05:32 +01:00
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
ids: { type: 'array', items: {
|
|
|
|
type: 'string', format: 'misskey:id',
|
|
|
|
} },
|
|
|
|
aliases: { type: 'array', items: {
|
|
|
|
type: 'string',
|
|
|
|
} },
|
2022-01-12 16:47:05 +01:00
|
|
|
},
|
2022-02-19 06:05:32 +01:00
|
|
|
required: ['ids', 'aliases'],
|
2022-01-18 14:27:10 +01:00
|
|
|
} as const;
|
2022-01-12 16:47:05 +01:00
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
// TODO: ロジックをサービスに切り出す
|
|
|
|
|
2022-01-12 16:47:05 +01:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2022-09-17 20:27:08 +02:00
|
|
|
@Injectable()
|
|
|
|
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|
|
|
constructor(
|
|
|
|
@Inject(DI.db)
|
|
|
|
private db: DataSource,
|
|
|
|
|
|
|
|
@Inject(DI.emojisRepository)
|
|
|
|
private emojisRepository: EmojisRepository,
|
|
|
|
) {
|
|
|
|
super(meta, paramDef, async (ps, me) => {
|
|
|
|
const emojis = await this.emojisRepository.findBy({
|
|
|
|
id: In(ps.ids),
|
|
|
|
});
|
|
|
|
|
|
|
|
for (const emoji of emojis) {
|
|
|
|
await this.emojisRepository.update(emoji.id, {
|
|
|
|
updatedAt: new Date(),
|
|
|
|
aliases: emoji.aliases.filter(x => !ps.aliases.includes(x)),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
await this.db.queryResultCache!.remove(['meta_emojis']);
|
2022-01-12 16:47:05 +01:00
|
|
|
});
|
|
|
|
}
|
2022-09-17 20:27:08 +02:00
|
|
|
}
|