From 9d59ee09fdc3b8a54f2b43fa18a88e1f4bafe95b Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Thu, 28 Sep 2023 16:51:25 +0200 Subject: [PATCH] [mastodon-client] Improve link pagination helper function --- .../backend/src/server/api/mastodon/endpoints/account.ts | 8 ++++---- .../backend/src/server/api/mastodon/helpers/pagination.ts | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/backend/src/server/api/mastodon/endpoints/account.ts b/packages/backend/src/server/api/mastodon/endpoints/account.ts index 92a8cfd77..f47ed88ae 100644 --- a/packages/backend/src/server/api/mastodon/endpoints/account.ts +++ b/packages/backend/src/server/api/mastodon/endpoints/account.ts @@ -198,7 +198,7 @@ export function apiAccountMastodon(router: Router): void { const followers = await UserConverter.encodeMany(res.data, cache); ctx.body = followers.map((account) => convertAccount(account)); - PaginationHelpers.appendLinkPaginationHeader(args, ctx, res, `v1/accounts/${ctx.params.id}/followers`); + PaginationHelpers.appendLinkPaginationHeader(args, ctx, res); } catch (e: any) { console.error(e); console.error(e.response.data); @@ -223,7 +223,7 @@ export function apiAccountMastodon(router: Router): void { const following = await UserConverter.encodeMany(res.data, cache); ctx.body = following.map((account) => convertAccount(account)); - PaginationHelpers.appendLinkPaginationHeader(args, ctx, res, `v1/accounts/${ctx.params.id}/following`); + PaginationHelpers.appendLinkPaginationHeader(args, ctx, res); } catch (e: any) { console.error(e); console.error(e.response.data); @@ -414,7 +414,7 @@ export function apiAccountMastodon(router: Router): void { const bookmarks = await NoteConverter.encodeMany(res.data, user, cache); ctx.body = bookmarks.map(s => convertStatus(s)); - PaginationHelpers.appendLinkPaginationHeader(args, ctx, res, `v1/bookmarks`); + PaginationHelpers.appendLinkPaginationHeader(args, ctx, res); } catch (e: any) { console.error(e); console.error(e.response.data); @@ -438,7 +438,7 @@ export function apiAccountMastodon(router: Router): void { const favorites = await NoteConverter.encodeMany(res.data, user, cache); ctx.body = favorites.map(s => convertStatus(s)); - PaginationHelpers.appendLinkPaginationHeader(args, ctx, res, `v1/favourites`); + PaginationHelpers.appendLinkPaginationHeader(args, ctx, res); } 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 b99562997..a5a7d142e 100644 --- a/packages/backend/src/server/api/mastodon/helpers/pagination.ts +++ b/packages/backend/src/server/api/mastodon/helpers/pagination.ts @@ -65,15 +65,15 @@ export class PaginationHelpers { return reverse ? found.reverse() : found; } - public static appendLinkPaginationHeader(args: any, ctx: any, res: any, route: string): void { + public static appendLinkPaginationHeader(args: any, ctx: any, res: any): void { const link: string[] = []; const limit = args.limit ?? 40; if (res.maxId) { - const l = `<${config.url}/api/${route}?limit=${limit}&max_id=${convertId(res.maxId, IdType.MastodonId)}>; rel="next"`; + const l = `<${config.url}/api${ctx.path}?limit=${limit}&max_id=${convertId(res.maxId, IdType.MastodonId)}>; rel="next"`; link.push(l); } if (res.minId) { - const l = `<${config.url}/api/${route}?limit=${limit}&min_id=${convertId(res.minId, IdType.MastodonId)}>; rel="prev"`; + const l = `<${config.url}/api${ctx.path}?limit=${limit}&min_id=${convertId(res.minId, IdType.MastodonId)}>; rel="prev"`; link.push(l); } if (link.length > 0){