2018-11-03 19:18:32 +01:00
|
|
|
import $ from 'cafy';
|
|
|
|
import define from '../../../define';
|
2019-04-07 14:50:36 +02:00
|
|
|
import { Emojis } from '../../../../../models';
|
2020-01-29 20:37:25 +01:00
|
|
|
import { makePaginationQuery } from '../../../common/make-pagination-query';
|
|
|
|
import { ID } from '../../../../../misc/cafy-id';
|
2020-10-17 13:12:00 +02:00
|
|
|
import { Emoji } from '../../../../../models/entities/emoji';
|
2018-11-03 19:18:32 +01:00
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
desc: {
|
|
|
|
'ja-JP': 'カスタム絵文字を取得します。'
|
|
|
|
},
|
|
|
|
|
2019-02-23 03:20:58 +01:00
|
|
|
tags: ['admin'],
|
|
|
|
|
2020-02-15 13:33:32 +01:00
|
|
|
requireCredential: true as const,
|
2018-11-14 20:15:42 +01:00
|
|
|
requireModerator: true,
|
2018-11-03 19:18:32 +01:00
|
|
|
|
|
|
|
params: {
|
2020-10-17 13:12:00 +02:00
|
|
|
query: {
|
|
|
|
validator: $.optional.nullable.str,
|
|
|
|
default: null as any
|
|
|
|
},
|
|
|
|
|
2020-01-29 20:37:25 +01:00
|
|
|
limit: {
|
|
|
|
validator: $.optional.num.range(1, 100),
|
|
|
|
default: 10
|
|
|
|
},
|
|
|
|
|
|
|
|
sinceId: {
|
|
|
|
validator: $.optional.type(ID),
|
|
|
|
},
|
|
|
|
|
|
|
|
untilId: {
|
|
|
|
validator: $.optional.type(ID),
|
2018-11-03 19:18:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-02-22 03:46:58 +01:00
|
|
|
export default define(meta, async (ps) => {
|
2020-10-17 13:12:00 +02:00
|
|
|
const q = makePaginationQuery(Emojis.createQueryBuilder('emoji'), ps.sinceId, ps.untilId)
|
|
|
|
.andWhere(`emoji.host IS NULL`);
|
|
|
|
|
|
|
|
let emojis: Emoji[];
|
|
|
|
|
|
|
|
if (ps.query) {
|
|
|
|
//q.andWhere('emoji.name ILIKE :q', { q: `%${ps.query}%` });
|
|
|
|
//const emojis = await q.take(ps.limit!).getMany();
|
|
|
|
|
|
|
|
emojis = await q.getMany();
|
|
|
|
|
|
|
|
emojis = emojis.filter(emoji =>
|
|
|
|
emoji.name.includes(ps.query) ||
|
|
|
|
emoji.aliases.some(a => a.includes(ps.query)) ||
|
|
|
|
emoji.category?.includes(ps.query));
|
|
|
|
|
|
|
|
emojis.splice(ps.limit! + 1);
|
|
|
|
} else {
|
|
|
|
emojis = await q.take(ps.limit!).getMany();
|
|
|
|
}
|
2018-11-03 19:18:32 +01:00
|
|
|
|
2020-03-31 02:15:04 +02:00
|
|
|
return Emojis.packMany(emojis);
|
2019-02-22 03:46:58 +01:00
|
|
|
});
|