From f1cb8c778a7245bdc82c9850723a1e13908666a3 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 22 Feb 2025 21:45:04 -0600 Subject: [PATCH] Normalize Link header URLs --- packages/mastoapi/pagination/paginate.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/mastoapi/pagination/paginate.ts b/packages/mastoapi/pagination/paginate.ts index 2da2e478..26be72bd 100644 --- a/packages/mastoapi/pagination/paginate.ts +++ b/packages/mastoapi/pagination/paginate.ts @@ -1,5 +1,6 @@ import { buildLinkHeader, buildListLinkHeader } from './link-header.ts'; +import type { DittoEnv } from '@ditto/mastoapi/router'; import type { Context } from '@hono/hono'; import type { NostrEvent } from '@nostrify/nostrify'; @@ -7,12 +8,15 @@ type HeaderRecord = Record; /** Return results with pagination headers. Assumes chronological sorting of events. */ export function paginated( - c: Context, + c: Context, events: NostrEvent[], body: object | unknown[], headers: HeaderRecord = {}, ): Response { - const link = buildLinkHeader(c.req.url, events); + const { conf } = c.var; + + const url = conf.local(c.req.url); + const link = buildLinkHeader(url, events); if (link) { headers.link = link; @@ -25,12 +29,15 @@ export function paginated( /** paginate a list of tags. */ export function paginatedList( - c: Context, + c: Context, params: { offset: number; limit: number }, body: object | unknown[], headers: HeaderRecord = {}, ): Response { - const link = buildListLinkHeader(c.req.url, params); + const { conf } = c.var; + + const url = conf.local(c.req.url); + const link = buildListLinkHeader(url, params); const hasMore = Array.isArray(body) ? body.length > 0 : true; if (link) {