diff --git a/packages/backend/src/server/api/mastodon/endpoints/account.ts b/packages/backend/src/server/api/mastodon/endpoints/account.ts index 859978164..f574f8af4 100644 --- a/packages/backend/src/server/api/mastodon/endpoints/account.ts +++ b/packages/backend/src/server/api/mastodon/endpoints/account.ts @@ -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); diff --git a/packages/backend/src/server/api/mastodon/endpoints/list.ts b/packages/backend/src/server/api/mastodon/endpoints/list.ts index 1f90f6e42..92ed31044 100644 --- a/packages/backend/src/server/api/mastodon/endpoints/list.ts +++ b/packages/backend/src/server/api/mastodon/endpoints/list.ts @@ -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; } diff --git a/packages/backend/src/server/api/mastodon/endpoints/status.ts b/packages/backend/src/server/api/mastodon/endpoints/status.ts index 98bb967c2..63ba88fa8 100644 --- a/packages/backend/src/server/api/mastodon/endpoints/status.ts +++ b/packages/backend/src/server/api/mastodon/endpoints/status.ts @@ -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; diff --git a/packages/backend/src/server/api/mastodon/endpoints/timeline.ts b/packages/backend/src/server/api/mastodon/endpoints/timeline.ts index 0beb77fd9..35f096ec5 100644 --- a/packages/backend/src/server/api/mastodon/endpoints/timeline.ts +++ b/packages/backend/src/server/api/mastodon/endpoints/timeline.ts @@ -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); diff --git a/packages/backend/src/server/api/mastodon/helpers/pagination.ts b/packages/backend/src/server/api/mastodon/helpers/pagination.ts index ad6e70f99..b76e7cc4b 100644 --- a/packages/backend/src/server/api/mastodon/helpers/pagination.ts +++ b/packages/backend/src/server/api/mastodon/helpers/pagination.ts @@ -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);