2022-09-17 21:27:08 +03:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
|
|
import { DataSource, In } from 'typeorm';
|
|
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
2022-09-20 23:33:11 +03:00
|
|
|
import type { EmojisRepository } from '@/models/index.js';
|
2022-09-17 21:27:08 +03:00
|
|
|
import { DI } from '@/di-symbols.js';
|
2023-01-22 16:53:24 +02:00
|
|
|
import { EmojiEntityService } from '@/core/entities/EmojiEntityService.js';
|
|
|
|
import { GlobalEventService } from '@/core/GlobalEventService.js';
|
2022-01-12 17:47:05 +02:00
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
tags: ['admin'],
|
|
|
|
|
2022-01-18 15:27:10 +02:00
|
|
|
requireCredential: true,
|
2023-01-15 13:52:53 +02:00
|
|
|
requireRolePolicy: 'canManageCustomEmojis',
|
2022-02-19 07:05:32 +02:00
|
|
|
} as const;
|
2022-01-12 17:47:05 +02:00
|
|
|
|
2022-02-20 06:15:40 +02:00
|
|
|
export const paramDef = {
|
2022-02-19 07:05:32 +02:00
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
ids: { type: 'array', items: {
|
|
|
|
type: 'string', format: 'misskey:id',
|
|
|
|
} },
|
|
|
|
aliases: { type: 'array', items: {
|
|
|
|
type: 'string',
|
|
|
|
} },
|
2022-01-12 17:47:05 +02:00
|
|
|
},
|
2022-02-19 07:05:32 +02:00
|
|
|
required: ['ids', 'aliases'],
|
2022-01-18 15:27:10 +02:00
|
|
|
} as const;
|
2022-01-12 17:47:05 +02:00
|
|
|
|
2022-09-17 21:27:08 +03:00
|
|
|
// TODO: ロジックをサービスに切り出す
|
|
|
|
|
2022-01-12 17:47:05 +02:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2022-09-17 21:27:08 +03:00
|
|
|
@Injectable()
|
|
|
|
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|
|
|
constructor(
|
|
|
|
@Inject(DI.db)
|
|
|
|
private db: DataSource,
|
|
|
|
|
|
|
|
@Inject(DI.emojisRepository)
|
|
|
|
private emojisRepository: EmojisRepository,
|
2023-01-22 16:53:24 +02:00
|
|
|
|
|
|
|
private emojiEntityService: EmojiEntityService,
|
|
|
|
private globalEventService: GlobalEventService,
|
2022-09-17 21:27:08 +03:00
|
|
|
) {
|
|
|
|
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: [...new Set(emoji.aliases.concat(ps.aliases))],
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-03-14 02:37:14 +02:00
|
|
|
await this.db.queryResultCache?.remove(['meta_emojis']);
|
2023-01-22 16:53:24 +02:00
|
|
|
|
|
|
|
this.globalEventService.publishBroadcastStream('emojiUpdated', {
|
2023-02-17 08:36:36 +02:00
|
|
|
emojis: await this.emojiEntityService.packDetailedMany(ps.ids),
|
2023-01-22 16:53:24 +02:00
|
|
|
});
|
2022-01-12 17:47:05 +02:00
|
|
|
});
|
|
|
|
}
|
2022-09-17 21:27:08 +03:00
|
|
|
}
|