add pagination to i/shared-access/list and i/apps endpoints
This commit is contained in:
parent
90ff04eebc
commit
b48859e562
2 changed files with 20 additions and 4 deletions
|
|
@ -10,6 +10,7 @@ import { DI } from '@/di-symbols.js';
|
|||
import { IdService } from '@/core/IdService.js';
|
||||
import { UserEntityService } from '@/core/entities/UserEntityService.js';
|
||||
import { CacheService } from '@/core/CacheService.js';
|
||||
import { QueryService } from '@/core/QueryService.js';
|
||||
|
||||
export const meta = {
|
||||
requireCredential: true,
|
||||
|
|
@ -77,6 +78,9 @@ export const paramDef = {
|
|||
properties: {
|
||||
sort: { type: 'string', enum: ['+createdAt', '-createdAt', '+lastUsedAt', '-lastUsedAt'] },
|
||||
onlySharedAccess: { type: 'boolean' },
|
||||
limit: { type: 'integer', minimum: 1, maximum: 100, default: 30 },
|
||||
sinceId: { type: 'string', format: 'misskey:id' },
|
||||
untilId: { type: 'string', format: 'misskey:id' },
|
||||
},
|
||||
required: [],
|
||||
} as const;
|
||||
|
|
@ -89,11 +93,13 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
|
||||
private readonly userEntityService: UserEntityService,
|
||||
private readonly cacheService: CacheService,
|
||||
private readonly queryService: QueryService,
|
||||
private idService: IdService,
|
||||
) {
|
||||
super(meta, paramDef, async (ps, me) => {
|
||||
const query = this.accessTokensRepository.createQueryBuilder('token')
|
||||
const query = this.queryService.makePaginationQuery(this.accessTokensRepository.createQueryBuilder('token'), ps.sinceId, ps.untilId)
|
||||
.where('token.userId = :userId', { userId: me.id })
|
||||
.limit(ps.limit)
|
||||
.leftJoinAndSelect('token.app', 'app');
|
||||
|
||||
switch (ps.sort) {
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import { Endpoint } from '@/server/api/endpoint-base.js';
|
|||
import { DI } from '@/di-symbols.js';
|
||||
import type { AccessTokensRepository } from '@/models/_.js';
|
||||
import { UserEntityService } from '@/core/entities/UserEntityService.js';
|
||||
import { QueryService } from '@/core/QueryService.js';
|
||||
|
||||
export const meta = {
|
||||
requireCredential: true,
|
||||
|
|
@ -62,7 +63,15 @@ export const meta = {
|
|||
},
|
||||
} as const;
|
||||
|
||||
export const paramDef = {} as const;
|
||||
export const paramDef = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
limit: { type: 'integer', minimum: 1, maximum: 100, default: 30 },
|
||||
sinceId: { type: 'string', format: 'misskey:id' },
|
||||
untilId: { type: 'string', format: 'misskey:id' },
|
||||
},
|
||||
required: [],
|
||||
} as const;
|
||||
|
||||
@Injectable()
|
||||
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
|
||||
|
|
@ -71,11 +80,12 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
private readonly accessTokensRepository: AccessTokensRepository,
|
||||
|
||||
private readonly userEntityService: UserEntityService,
|
||||
private readonly queryService: QueryService,
|
||||
) {
|
||||
super(meta, paramDef, async (ps, me) => {
|
||||
const tokens = await this.accessTokensRepository
|
||||
.createQueryBuilder('token')
|
||||
const tokens = await this.queryService.makePaginationQuery(this.accessTokensRepository.createQueryBuilder('token'), ps.sinceId, ps.untilId)
|
||||
.where(':meIdAsList <@ token.granteeIds', { meIdAsList: [me.id] })
|
||||
.limit(ps.limit)
|
||||
.getMany();
|
||||
|
||||
const userIds = tokens.map(token => token.userId);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue