mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-28 23:33:08 +02:00
3cb669a852
* disabledCache: trueのときにqueryResultCacheへアクセスしないように * append changelog
63 lines
1.7 KiB
TypeScript
63 lines
1.7 KiB
TypeScript
import { Inject, Injectable } from '@nestjs/common';
|
|
import { DataSource, In } from 'typeorm';
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
|
import type { EmojisRepository } from '@/models/index.js';
|
|
import { DI } from '@/di-symbols.js';
|
|
import { EmojiEntityService } from '@/core/entities/EmojiEntityService.js';
|
|
import { GlobalEventService } from '@/core/GlobalEventService.js';
|
|
|
|
export const meta = {
|
|
tags: ['admin'],
|
|
|
|
requireCredential: true,
|
|
requireRolePolicy: 'canManageCustomEmojis',
|
|
} as const;
|
|
|
|
export const paramDef = {
|
|
type: 'object',
|
|
properties: {
|
|
ids: { type: 'array', items: {
|
|
type: 'string', format: 'misskey:id',
|
|
} },
|
|
aliases: { type: 'array', items: {
|
|
type: 'string',
|
|
} },
|
|
},
|
|
required: ['ids', 'aliases'],
|
|
} 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 emojiEntityService: EmojiEntityService,
|
|
private globalEventService: GlobalEventService,
|
|
) {
|
|
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))],
|
|
});
|
|
}
|
|
|
|
await this.db.queryResultCache?.remove(['meta_emojis']);
|
|
|
|
this.globalEventService.publishBroadcastStream('emojiUpdated', {
|
|
emojis: await this.emojiEntityService.packDetailedMany(ps.ids),
|
|
});
|
|
});
|
|
}
|
|
}
|