Normalize Link header URLs

This commit is contained in:
Alex Gleason 2025-02-22 21:45:04 -06:00
parent 7f059b4dac
commit f1cb8c778a
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7

View file

@ -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<string, string | string[]>;
/** Return results with pagination headers. Assumes chronological sorting of events. */
export function paginated(
c: Context,
c: Context<DittoEnv>,
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<DittoEnv>,
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) {