From 9187723263c5b0d87b78bfbdcfa8b8234ee958ce Mon Sep 17 00:00:00 2001 From: Hank Grabowski Date: Fri, 17 Feb 2023 13:24:11 -0500 Subject: [PATCH] Add link headers to Mastodon trending endpoints --- src/Module/Api/Mastodon/Trends/Links.php | 6 +++++- src/Module/Api/Mastodon/Trends/Statuses.php | 6 +++++- src/Module/Api/Mastodon/Trends/Tags.php | 8 ++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Module/Api/Mastodon/Trends/Links.php b/src/Module/Api/Mastodon/Trends/Links.php index e2a1600875..bfb3531478 100644 --- a/src/Module/Api/Mastodon/Trends/Links.php +++ b/src/Module/Api/Mastodon/Trends/Links.php @@ -41,7 +41,7 @@ class Links extends BaseApi { $request = $this->getRequest([ 'limit' => 10, // Maximum number of results to return. Defaults to 10. - 'offset' => 0, // Offset page, Defaults to 0. + 'offset' => 0, // Offset in set, Defaults to 0. ], $request); $condition = ["EXISTS(SELECT `id` FROM `post-media` WHERE `post-media`.`uri-id` = `post-thread-view`.`uri-id` AND `type` = ? AND NOT `name` IS NULL AND NOT `description` IS NULL) AND NOT `private` AND `commented` > ? AND `created` > ?", @@ -56,6 +56,10 @@ class Links extends BaseApi } DBA::close($statuses); + if (!empty($trending)) { + self::setLinkHeaderByOffsetLimit($request['offset'], $request['limit']); + } + System::jsonExit($trending); } } diff --git a/src/Module/Api/Mastodon/Trends/Statuses.php b/src/Module/Api/Mastodon/Trends/Statuses.php index 6ae9c83dd5..884319aa48 100644 --- a/src/Module/Api/Mastodon/Trends/Statuses.php +++ b/src/Module/Api/Mastodon/Trends/Statuses.php @@ -44,7 +44,7 @@ class Statuses extends BaseApi $request = $this->getRequest([ 'limit' => 10, // Maximum number of results to return. Defaults to 10. - 'offset' => 0, // Offset page, Defaults to 0. + 'offset' => 0, // Offset in set, Defaults to 0. ], $request); $condition = ["NOT `private` AND `commented` > ? AND `created` > ?", DateTimeFormat::utc('now -1 day'), DateTimeFormat::utc('now -1 week')]; @@ -63,6 +63,10 @@ class Statuses extends BaseApi } DBA::close($statuses); + if (!empty($trending)) { + self::setLinkHeaderByOffsetLimit($request['offset'], $request['limit']); + } + System::jsonExit($trending); } } diff --git a/src/Module/Api/Mastodon/Trends/Tags.php b/src/Module/Api/Mastodon/Trends/Tags.php index 21e078b237..2190a2e3c9 100644 --- a/src/Module/Api/Mastodon/Trends/Tags.php +++ b/src/Module/Api/Mastodon/Trends/Tags.php @@ -38,7 +38,7 @@ class Tags extends BaseApi { $request = $this->getRequest([ 'limit' => 20, // Maximum number of results to return. Defaults to 20. - 'offset' => 0, // Offset page. Defaults to 0. + 'offset' => 0, // Offset in set. Defaults to 0. 'friendica_local' => false, // Whether to return local tag trends instead of global, defaults to false ], $request); @@ -56,6 +56,10 @@ class Tags extends BaseApi $trending[] = $hashtag->toArray(); } - System::jsonExit(array_slice($trending, 0, $request['limit'])); + if (!empty($trending)) { + self::setLinkHeaderByOffsetLimit($request['offset'], $request['limit']); + } + + System::jsonExit($trending); } } -- 2.39.5