2022-02-27 03:07:39 +01:00
|
|
|
import define from '../../../define.js';
|
|
|
|
import { Emojis } from '@/models/index.js';
|
|
|
|
import { toPuny } from '@/misc/convert-host.js';
|
|
|
|
import { makePaginationQuery } from '../../../common/make-pagination-query.js';
|
2020-01-29 20:37:25 +01:00
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
tags: ['admin'],
|
|
|
|
|
2022-01-18 14:27:10 +01:00
|
|
|
requireCredential: true,
|
2020-01-29 20:37:25 +01:00
|
|
|
requireModerator: true,
|
|
|
|
|
2021-03-06 14:34:11 +01:00
|
|
|
res: {
|
2022-01-18 14:27:10 +01:00
|
|
|
type: 'array',
|
|
|
|
optional: false, nullable: false,
|
2021-03-06 14:34:11 +01:00
|
|
|
items: {
|
2022-01-18 14:27:10 +01:00
|
|
|
type: 'object',
|
|
|
|
optional: false, nullable: false,
|
2021-03-06 14:34:11 +01:00
|
|
|
properties: {
|
|
|
|
id: {
|
2022-01-18 14:27:10 +01:00
|
|
|
type: 'string',
|
|
|
|
optional: false, nullable: false,
|
2021-03-06 14:34:11 +01:00
|
|
|
format: 'id',
|
|
|
|
},
|
|
|
|
aliases: {
|
2022-01-18 14:27:10 +01:00
|
|
|
type: 'array',
|
|
|
|
optional: false, nullable: false,
|
2021-03-06 14:34:11 +01:00
|
|
|
items: {
|
2022-01-18 14:27:10 +01:00
|
|
|
type: 'string',
|
|
|
|
optional: false, nullable: false,
|
2021-12-09 15:58:30 +01:00
|
|
|
},
|
2021-03-06 14:34:11 +01:00
|
|
|
},
|
|
|
|
name: {
|
2022-01-18 14:27:10 +01:00
|
|
|
type: 'string',
|
|
|
|
optional: false, nullable: false,
|
2021-03-06 14:34:11 +01:00
|
|
|
},
|
|
|
|
category: {
|
2022-01-18 14:27:10 +01:00
|
|
|
type: 'string',
|
|
|
|
optional: false, nullable: true,
|
2021-03-06 14:34:11 +01:00
|
|
|
},
|
|
|
|
host: {
|
2022-01-18 14:27:10 +01:00
|
|
|
type: 'string',
|
|
|
|
optional: false, nullable: true,
|
2022-04-03 06:57:26 +02:00
|
|
|
description: 'The local host is represented with `null`.',
|
2021-03-06 14:34:11 +01:00
|
|
|
},
|
|
|
|
url: {
|
2022-01-18 14:27:10 +01:00
|
|
|
type: 'string',
|
|
|
|
optional: false, nullable: false,
|
2021-12-09 15:58:30 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-01-18 14:27:10 +01:00
|
|
|
} as const;
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2022-02-20 05:15:40 +01:00
|
|
|
export const paramDef = {
|
2022-02-19 06:05:32 +01:00
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
query: { type: 'string', nullable: true, default: null },
|
2022-04-03 06:57:26 +02:00
|
|
|
host: {
|
|
|
|
type: 'string',
|
|
|
|
nullable: true,
|
|
|
|
default: null,
|
|
|
|
description: 'Use `null` to represent the local host.',
|
|
|
|
},
|
2022-02-19 06:05:32 +01:00
|
|
|
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
|
|
|
|
sinceId: { type: 'string', format: 'misskey:id' },
|
|
|
|
untilId: { type: 'string', format: 'misskey:id' },
|
|
|
|
},
|
|
|
|
required: [],
|
|
|
|
} as const;
|
|
|
|
|
2022-01-02 18:12:50 +01:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2022-02-19 06:05:32 +01:00
|
|
|
export default define(meta, paramDef, async (ps) => {
|
2020-01-29 20:37:25 +01:00
|
|
|
const q = makePaginationQuery(Emojis.createQueryBuilder('emoji'), ps.sinceId, ps.untilId);
|
|
|
|
|
|
|
|
if (ps.host == null) {
|
|
|
|
q.andWhere(`emoji.host IS NOT NULL`);
|
|
|
|
} else {
|
|
|
|
q.andWhere(`emoji.host = :host`, { host: toPuny(ps.host) });
|
|
|
|
}
|
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
if (ps.query) {
|
|
|
|
q.andWhere('emoji.name like :query', { query: '%' + ps.query + '%' });
|
|
|
|
}
|
|
|
|
|
2020-01-29 20:37:25 +01:00
|
|
|
const emojis = await q
|
2020-10-17 13:12:00 +02:00
|
|
|
.orderBy('emoji.id', 'DESC')
|
2022-02-19 06:05:32 +01:00
|
|
|
.take(ps.limit)
|
2020-01-29 20:37:25 +01:00
|
|
|
.getMany();
|
|
|
|
|
2020-03-31 02:15:04 +02:00
|
|
|
return Emojis.packMany(emojis);
|
2020-01-29 20:37:25 +01:00
|
|
|
});
|