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