Set the "Link" header

This commit is contained in:
Michael 2021-06-16 15:02:33 +00:00
parent d4f883a376
commit 78d4aff878
18 changed files with 98 additions and 18 deletions

View file

@ -92,8 +92,6 @@ class FollowRequests extends BaseApi
'limit' => 40, // Maximum number of results to return. Defaults to 40. Paginate using the HTTP Link header.
]);
$baseUrl = DI::baseUrl();
$introductions = DI::intro()->selectByBoundaries(
['`uid` = ? AND NOT `ignore`', $uid],
['order' => ['id' => 'DESC']],
@ -106,6 +104,7 @@ class FollowRequests extends BaseApi
foreach ($introductions as $key => $introduction) {
try {
self::setBoundaries($introduction->id);
$return[] = DI::mstdnFollowRequest()->createFromIntroduction($introduction);
} catch (HTTPException\InternalServerErrorException $exception) {
DI::intro()->delete($introduction);
@ -113,22 +112,7 @@ class FollowRequests extends BaseApi
}
}
$base_query = [];
if (isset($_GET['limit'])) {
$base_query['limit'] = $request['limit'];
}
$links = [];
if ($introductions->getTotalCount() > $request['limit']) {
$links[] = '<' . $baseUrl->get() . '/api/v1/follow_requests?' . http_build_query($base_query + ['max_id' => $introductions[count($introductions) - 1]->id]) . '>; rel="next"';
}
if (count($introductions)) {
$links[] = '<' . $baseUrl->get() . '/api/v1/follow_requests?' . http_build_query($base_query + ['min_id' => $introductions[0]->id]) . '>; rel="prev"';
}
header('Link: ' . implode(', ', $links));
self::setLinkHeader();
System::jsonExit($return);
}
}