2023-02-16 15:09:41 +01:00
|
|
|
import { IsNull } from 'typeorm';
|
2023-01-09 07:50:25 +01:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
|
|
import type { EmojisRepository } from '@/models/index.js';
|
|
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
|
|
|
import { EmojiEntityService } from '@/core/entities/EmojiEntityService.js';
|
|
|
|
import type { Config } from '@/config.js';
|
|
|
|
import { DI } from '@/di-symbols.js';
|
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
tags: ['meta'],
|
|
|
|
|
|
|
|
requireCredential: false,
|
2023-01-16 10:39:58 +01:00
|
|
|
allowGet: true,
|
2023-01-22 18:14:05 +01:00
|
|
|
cacheSec: 3600,
|
2023-01-09 07:50:25 +01:00
|
|
|
|
|
|
|
res: {
|
|
|
|
type: 'object',
|
|
|
|
optional: false, nullable: false,
|
|
|
|
properties: {
|
|
|
|
emojis: {
|
|
|
|
type: 'array',
|
|
|
|
optional: false, nullable: false,
|
|
|
|
items: {
|
|
|
|
type: 'object',
|
|
|
|
optional: false, nullable: false,
|
2023-03-17 12:24:47 +01:00
|
|
|
ref: 'EmojiSimple',
|
2023-01-09 07:50:25 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
} as const;
|
|
|
|
|
|
|
|
export const paramDef = {
|
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
},
|
|
|
|
required: [],
|
|
|
|
} as const;
|
|
|
|
|
|
|
|
// eslint-disable-next-line import/no-default-export
|
|
|
|
@Injectable()
|
|
|
|
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|
|
|
constructor(
|
|
|
|
@Inject(DI.config)
|
|
|
|
private config: Config,
|
|
|
|
|
|
|
|
@Inject(DI.emojisRepository)
|
|
|
|
private emojisRepository: EmojisRepository,
|
|
|
|
|
|
|
|
private emojiEntityService: EmojiEntityService,
|
|
|
|
) {
|
|
|
|
super(meta, paramDef, async (ps, me) => {
|
|
|
|
const emojis = await this.emojisRepository.find({
|
|
|
|
where: {
|
|
|
|
host: IsNull(),
|
|
|
|
},
|
|
|
|
order: {
|
|
|
|
category: 'ASC',
|
|
|
|
name: 'ASC',
|
|
|
|
},
|
|
|
|
cache: {
|
|
|
|
id: 'meta_emojis',
|
2023-01-22 18:14:05 +01:00
|
|
|
milliseconds: 3600000, // 1 hour
|
2023-01-09 07:50:25 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
2023-02-17 07:36:36 +01:00
|
|
|
emojis: await this.emojiEntityService.packSimpleMany(emojis),
|
2023-01-09 07:50:25 +01:00
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|