mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Normalize Link header URLs
This commit is contained in:
parent
7f059b4dac
commit
f1cb8c778a
1 changed files with 11 additions and 4 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
import { buildLinkHeader, buildListLinkHeader } from './link-header.ts';
|
import { buildLinkHeader, buildListLinkHeader } from './link-header.ts';
|
||||||
|
|
||||||
|
import type { DittoEnv } from '@ditto/mastoapi/router';
|
||||||
import type { Context } from '@hono/hono';
|
import type { Context } from '@hono/hono';
|
||||||
import type { NostrEvent } from '@nostrify/nostrify';
|
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. */
|
/** Return results with pagination headers. Assumes chronological sorting of events. */
|
||||||
export function paginated(
|
export function paginated(
|
||||||
c: Context,
|
c: Context<DittoEnv>,
|
||||||
events: NostrEvent[],
|
events: NostrEvent[],
|
||||||
body: object | unknown[],
|
body: object | unknown[],
|
||||||
headers: HeaderRecord = {},
|
headers: HeaderRecord = {},
|
||||||
): Response {
|
): 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) {
|
if (link) {
|
||||||
headers.link = link;
|
headers.link = link;
|
||||||
|
|
@ -25,12 +29,15 @@ export function paginated(
|
||||||
|
|
||||||
/** paginate a list of tags. */
|
/** paginate a list of tags. */
|
||||||
export function paginatedList(
|
export function paginatedList(
|
||||||
c: Context,
|
c: Context<DittoEnv>,
|
||||||
params: { offset: number; limit: number },
|
params: { offset: number; limit: number },
|
||||||
body: object | unknown[],
|
body: object | unknown[],
|
||||||
headers: HeaderRecord = {},
|
headers: HeaderRecord = {},
|
||||||
): Response {
|
): 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;
|
const hasMore = Array.isArray(body) ? body.length > 0 : true;
|
||||||
|
|
||||||
if (link) {
|
if (link) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue