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';
|
2021-03-23 09:43:07 +01:00
|
|
|
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 = {
|
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
|
|
|
}
|
2021-03-06 14:34:11 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
res: {
|
|
|
|
type: 'array' as const,
|
|
|
|
optional: false as const, nullable: false as const,
|
|
|
|
items: {
|
|
|
|
type: 'object' as const,
|
|
|
|
optional: false as const, nullable: false as const,
|
|
|
|
properties: {
|
|
|
|
id: {
|
|
|
|
type: 'string' as const,
|
|
|
|
optional: false as const, nullable: false as const,
|
|
|
|
format: 'id',
|
|
|
|
description: 'The unique identifier for this Emoji.'
|
|
|
|
},
|
|
|
|
aliases: {
|
|
|
|
type: 'array' as const,
|
|
|
|
optional: false as const, nullable: false as const,
|
|
|
|
description: 'List to make it easier to be displayed as a candidate when entering emoji.',
|
|
|
|
items: {
|
|
|
|
type: 'string' as const,
|
|
|
|
optional: false as const, nullable: false as const
|
|
|
|
}
|
|
|
|
},
|
|
|
|
name: {
|
|
|
|
type: 'string' as const,
|
|
|
|
optional: false as const, nullable: false as const,
|
|
|
|
description: 'Official name of custom emoji.'
|
|
|
|
},
|
|
|
|
category: {
|
|
|
|
type: 'string' as const,
|
|
|
|
optional: false as const, nullable: true as const,
|
|
|
|
description: 'Names categorized in the emoji list.'
|
|
|
|
},
|
|
|
|
host: {
|
|
|
|
type: 'string' as const,
|
|
|
|
optional: false as const, nullable: true as const,
|
|
|
|
description: 'If it is another server, the FQDN will be returned here.'
|
|
|
|
},
|
|
|
|
url: {
|
|
|
|
type: 'string' as const,
|
|
|
|
optional: false as const, nullable: false as const,
|
|
|
|
description: 'Image URL of emoji.'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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 =>
|
2021-03-24 03:05:37 +01:00
|
|
|
emoji.name.includes(ps.query!) ||
|
|
|
|
emoji.aliases.some(a => a.includes(ps.query!)) ||
|
|
|
|
emoji.category?.includes(ps.query!));
|
2020-10-17 13:12:00 +02:00
|
|
|
|
|
|
|
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
|
|
|
});
|