mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-23 05:43:07 +02:00
allow offset
in admin/emoji/list
- #490
also, use `skip` + `take` instead of `limit` (the TypeORM docs say so https://github.com/typeorm/typeorm/blob/master/docs/select-query-builder.md#adding-limit-expression )
This commit is contained in:
parent
c88de91b1a
commit
40f08617c4
1 changed files with 4 additions and 3 deletions
|
@ -66,6 +66,7 @@ export const paramDef = {
|
||||||
properties: {
|
properties: {
|
||||||
query: { type: 'string', nullable: true, default: null },
|
query: { type: 'string', nullable: true, default: null },
|
||||||
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
|
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
|
||||||
|
offset: { type: 'integer', minimum: 1, nullable: true, default: null },
|
||||||
sinceId: { type: 'string', format: 'misskey:id' },
|
sinceId: { type: 'string', format: 'misskey:id' },
|
||||||
untilId: { type: 'string', format: 'misskey:id' },
|
untilId: { type: 'string', format: 'misskey:id' },
|
||||||
},
|
},
|
||||||
|
@ -91,7 +92,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
//q.andWhere('emoji.name ILIKE :q', { q: `%${ sqlLikeEscape(ps.query) }%` });
|
//q.andWhere('emoji.name ILIKE :q', { q: `%${ sqlLikeEscape(ps.query) }%` });
|
||||||
//const emojis = await q.limit(ps.limit).getMany();
|
//const emojis = await q.limit(ps.limit).getMany();
|
||||||
|
|
||||||
emojis = await q.orderBy('length(emoji.name)', 'ASC').getMany();
|
emojis = await q.orderBy('length(emoji.name)', 'ASC').addOrderBy('id', 'DESC').getMany();
|
||||||
const queryarry = ps.query.match(/\:([a-z0-9_]*)\:/g);
|
const queryarry = ps.query.match(/\:([a-z0-9_]*)\:/g);
|
||||||
|
|
||||||
if (queryarry) {
|
if (queryarry) {
|
||||||
|
@ -104,9 +105,9 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
emoji.aliases.some(a => a.includes(ps.query!)) ||
|
emoji.aliases.some(a => a.includes(ps.query!)) ||
|
||||||
emoji.category?.includes(ps.query!));
|
emoji.category?.includes(ps.query!));
|
||||||
}
|
}
|
||||||
emojis.splice(ps.limit + 1);
|
emojis = emojis.slice((ps.offset ?? 0), ((ps.offset ?? 0) + ps.limit));
|
||||||
} else {
|
} else {
|
||||||
emojis = await q.limit(ps.limit).getMany();
|
emojis = await q.take(ps.limit).skip(ps.offset ?? 0).getMany();
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.emojiEntityService.packDetailedMany(emojis);
|
return this.emojiEntityService.packDetailedMany(emojis);
|
||||||
|
|
Loading…
Reference in a new issue