2020-03-31 02:15:04 +02:00
|
|
|
import { EntityRepository, Repository } from 'typeorm';
|
2022-02-27 03:07:39 +01:00
|
|
|
import { Emoji } from '@/models/entities/emoji.js';
|
|
|
|
import { Packed } from '@/misc/schema.js';
|
2020-03-31 02:15:04 +02:00
|
|
|
|
|
|
|
@EntityRepository(Emoji)
|
|
|
|
export class EmojiRepository extends Repository<Emoji> {
|
|
|
|
public async pack(
|
|
|
|
src: Emoji['id'] | Emoji,
|
2021-09-22 15:35:55 +02:00
|
|
|
): Promise<Packed<'Emoji'>> {
|
2021-02-13 07:33:38 +01:00
|
|
|
const emoji = typeof src === 'object' ? src : await this.findOneOrFail(src);
|
2020-03-31 02:15:04 +02:00
|
|
|
|
|
|
|
return {
|
|
|
|
id: emoji.id,
|
|
|
|
aliases: emoji.aliases,
|
|
|
|
name: emoji.name,
|
|
|
|
category: emoji.category,
|
|
|
|
host: emoji.host,
|
2022-01-21 10:47:02 +01:00
|
|
|
// || emoji.originalUrl してるのは後方互換性のため
|
|
|
|
url: emoji.publicUrl || emoji.originalUrl,
|
2020-03-31 02:15:04 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public packMany(
|
|
|
|
emojis: any[],
|
|
|
|
) {
|
|
|
|
return Promise.all(emojis.map(x => this.pack(x)));
|
|
|
|
}
|
|
|
|
}
|