[mastodon-client] Fix link pagination default limits

This commit is contained in:
Laura Hausmann 2023-10-02 22:24:04 +02:00
parent 3fb3f405ea
commit b8b6206b4e
No known key found for this signature in database
GPG Key ID: D044E84C5BE01605
5 changed files with 13 additions and 13 deletions

View File

@ -149,7 +149,7 @@ export function setupEndpointsAccount(router: Router): void {
const followers = await UserConverter.encodeMany(res.data, cache);
ctx.body = followers.map((account) => convertAccount(account));
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res);
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res, 40);
} catch (e: any) {
console.error(e);
console.error(e.response.data);
@ -174,7 +174,7 @@ export function setupEndpointsAccount(router: Router): void {
const following = await UserConverter.encodeMany(res.data, cache);
ctx.body = following.map((account) => convertAccount(account));
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res);
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res, 40);
} catch (e: any) {
console.error(e);
console.error(e.response.data);
@ -377,7 +377,7 @@ export function setupEndpointsAccount(router: Router): void {
const bookmarks = await NoteConverter.encodeMany(res.data, user, cache);
ctx.body = bookmarks.map(s => convertStatus(s));
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res);
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res, 20);
} catch (e: any) {
console.error(e);
console.error(e.response.data);
@ -401,7 +401,7 @@ export function setupEndpointsAccount(router: Router): void {
const favorites = await NoteConverter.encodeMany(res.data, user, cache);
ctx.body = favorites.map(s => convertStatus(s));
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res);
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res, 20);
} catch (e: any) {
console.error(e);
console.error(e.response.data);
@ -423,7 +423,7 @@ export function setupEndpointsAccount(router: Router): void {
const args = normalizeUrlQuery(convertPaginationArgsIds(limitToInt(ctx.query as any)));
const res = await UserHelpers.getUserMutes(user, args.max_id, args.since_id, args.min_id, args.limit, cache);
ctx.body = res.data.map(m => convertAccount(m));
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res);
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res, 40);
} catch (e: any) {
console.error(e);
console.error(e.response.data);
@ -446,7 +446,7 @@ export function setupEndpointsAccount(router: Router): void {
const res = await UserHelpers.getUserBlocks(user, args.max_id, args.since_id, args.min_id, args.limit);
const blocks = await UserConverter.encodeMany(res.data, cache);
ctx.body = blocks.map(b => convertAccount(b));
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res);
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res, 40);
} catch (e: any) {
console.error(e);
console.error(e.response.data);
@ -469,7 +469,7 @@ export function setupEndpointsAccount(router: Router): void {
const res = await UserHelpers.getUserFollowRequests(user, args.max_id, args.since_id, args.min_id, args.limit);
const requests = await UserConverter.encodeMany(res.data, cache);
ctx.body = requests.map(b => convertAccount(b));
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res);
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res, 40);
} catch (e: any) {
console.error(e);
console.error(e.response.data);

View File

@ -159,7 +159,7 @@ export function setupEndpointsList(router: Router): void {
const res = await ListHelpers.getListUsers(user, id, args.max_id, args.since_id, args.min_id, args.limit);
const accounts = await UserConverter.encodeMany(res.data);
ctx.body = accounts.map(account => convertAccount(account));
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res);
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res, 40);
} catch (e: any) {
ctx.status = 404;
}

View File

@ -246,7 +246,7 @@ export function setupEndpointsStatus(router: Router): void {
const res = await NoteHelpers.getNoteRebloggedBy(note, args.max_id, args.since_id, args.min_id, args.limit);
const users = await UserConverter.encodeMany(res.data, cache);
ctx.body = users.map(m => convertAccount(m));
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res);
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res, 40);
} catch (e: any) {
console.error(e);
ctx.status = 401;
@ -274,7 +274,7 @@ export function setupEndpointsStatus(router: Router): void {
const res = await NoteHelpers.getNoteFavoritedBy(note, args.max_id, args.since_id, args.min_id, args.limit);
const users = await UserConverter.encodeMany(res.data, cache);
ctx.body = users.map(m => convertAccount(m));
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res);
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res, 40);
} catch (e: any) {
console.error(e);
ctx.status = 401;

View File

@ -193,7 +193,7 @@ export function setupEndpointsTimeline(router: Router): void {
const res = await TimelineHelpers.getConversations(user, args.max_id, args.since_id, args.min_id, args.limit);
ctx.body = res.data.map(c => convertConversation(c));
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res);
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res, 20);
} catch (e: any) {
console.error(e);
console.error(e.response.data);

View File

@ -68,9 +68,9 @@ export class PaginationHelpers {
return reverse ? found.reverse() : found;
}
public static appendLinkPaginationHeader(args: any, ctx: any, res: any): void {
public static appendLinkPaginationHeader(args: any, ctx: any, res: any, defaultLimit: number): void {
const link: string[] = [];
const limit = args.limit ?? 40;
const limit = args.limit ?? defaultLimit;
if (res.maxId) {
const l = `<${config.url}/api${ctx.path}?limit=${limit}&max_id=${convertId(res.maxId, IdType.MastodonId)}>; rel="next"`;
link.push(l);