mirror of
https://github.com/versia-pub/server.git
synced 2025-12-07 00:48:18 +01:00
Add Link header to notifications endpoint
This commit is contained in:
parent
82162fccf4
commit
17bd81cf46
|
|
@ -49,7 +49,7 @@ export default async (req: Request): Promise<Response> => {
|
||||||
return errorResponse("Can't use both types and exclude_types", 400);
|
return errorResponse("Can't use both types and exclude_types", 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
const notifications = await client.notification.findMany({
|
const objects = await client.notification.findMany({
|
||||||
where: {
|
where: {
|
||||||
notifiedId: user.id,
|
notifiedId: user.id,
|
||||||
id: {
|
id: {
|
||||||
|
|
@ -77,7 +77,24 @@ export default async (req: Request): Promise<Response> => {
|
||||||
take: limit,
|
take: limit,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Constuct HTTP Link header (next and prev)
|
||||||
|
const linkHeader = [];
|
||||||
|
if (objects.length > 0) {
|
||||||
|
const urlWithoutQuery = req.url.split("?")[0];
|
||||||
|
linkHeader.push(
|
||||||
|
`<${urlWithoutQuery}?max_id=${objects[0].id}&limit=${limit}>; rel="next"`
|
||||||
|
);
|
||||||
|
linkHeader.push(
|
||||||
|
`<${urlWithoutQuery}?since_id=${objects.at(-1)
|
||||||
|
?.id}&limit=${limit}>; rel="prev"`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return jsonResponse(
|
return jsonResponse(
|
||||||
await Promise.all(notifications.map(n => notificationToAPI(n)))
|
await Promise.all(objects.map(n => notificationToAPI(n))),
|
||||||
|
200,
|
||||||
|
{
|
||||||
|
Link: linkHeader.join(", "),
|
||||||
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue