From 955696b8a0f1867c748da72f9b4b7afd1f9c64ed Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 18 May 2021 17:53:59 -0600 Subject: [PATCH 1/4] Update site config, fix boolean casting --- app/Http/Controllers/Api/ApiV1Controller.php | 4 ++-- app/Util/Site/Config.php | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index 8837e4f56..973f14d3e 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -977,7 +977,7 @@ class ApiV1Controller extends Controller 'short_description' => 'Pixelfed - Photo sharing for everyone', 'languages' => ['en'], 'max_toot_chars' => (int) config('pixelfed.max_caption_length'), - 'registrations' => config_cache('pixelfed.open_registration'), + 'registrations' => (bool) config_cache('pixelfed.open_registration'), 'stats' => [ 'user_count' => 0, 'status_count' => 0, @@ -994,7 +994,7 @@ class ApiV1Controller extends Controller 'max_caption_length' => (int) config('pixelfed.max_caption_length'), 'max_bio_length' => (int) config('pixelfed.max_bio_length'), 'max_album_length' => (int) config_cache('pixelfed.max_album_length'), - 'mobile_apis' => config_cache('pixelfed.oauth_enabled') + 'mobile_apis' => (bool) config_cache('pixelfed.oauth_enabled') ] ]; diff --git a/app/Util/Site/Config.php b/app/Util/Site/Config.php index d9836ca70..117696c59 100644 --- a/app/Util/Site/Config.php +++ b/app/Util/Site/Config.php @@ -8,7 +8,7 @@ use Illuminate\Support\Str; class Config { public static function get() { - return Cache::remember('api:site:configuration:_v0.2', now()->addMinutes(5), function() { + return Cache::remember('api:site:configuration:_v0.3', now()->addMinutes(5), function() { return [ 'open_registration' => (bool) config_cache('pixelfed.open_registration'), 'uploader' => [ @@ -19,15 +19,15 @@ class Config { 'max_collection_length' => config('pixelfed.max_collection_length', 18), - 'optimize_image' => config('pixelfed.optimize_image'), - 'optimize_video' => config('pixelfed.optimize_video'), + 'optimize_image' => (bool) config('pixelfed.optimize_image'), + 'optimize_video' => (bool) config('pixelfed.optimize_video'), 'media_types' => config_cache('pixelfed.media_types'), - 'enforce_account_limit' => config_cache('pixelfed.enforce_account_limit') + 'enforce_account_limit' => (bool) config_cache('pixelfed.enforce_account_limit') ], 'activitypub' => [ - 'enabled' => config_cache('federation.activitypub.enabled'), + 'enabled' => (bool) config_cache('federation.activitypub.enabled'), 'remote_follow' => config('federation.activitypub.remoteFollow') ], @@ -54,9 +54,9 @@ class Config { ], 'features' => [ - 'mobile_apis' => config_cache('pixelfed.oauth_enabled'), + 'mobile_apis' => (bool) config_cache('pixelfed.oauth_enabled'), 'circles' => false, - 'stories' => config_cache('instance.stories.enabled'), + 'stories' => (bool) config_cache('instance.stories.enabled'), 'video' => Str::contains(config_cache('pixelfed.media_types'), 'video/mp4'), 'import' => [ 'instagram' => config_cache('pixelfed.import.instagram.enabled'), @@ -65,7 +65,7 @@ class Config { ], 'label' => [ 'covid' => [ - 'enabled' => config('instance.label.covid.enabled'), + 'enabled' => (bool) config('instance.label.covid.enabled'), 'org' => config('instance.label.covid.org'), 'url' => config('instance.label.covid.url'), ] From dac326e94937807114c197f9a0b32eb5cb70d5b8 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 18 May 2021 19:39:33 -0600 Subject: [PATCH 2/4] Update StatusTransformer, fix missing tags attribute --- app/Transformer/Api/StatusStatelessTransformer.php | 8 ++++++++ app/Transformer/Api/StatusTransformer.php | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/app/Transformer/Api/StatusStatelessTransformer.php b/app/Transformer/Api/StatusStatelessTransformer.php index 2190303ed..b3ba463da 100644 --- a/app/Transformer/Api/StatusStatelessTransformer.php +++ b/app/Transformer/Api/StatusStatelessTransformer.php @@ -15,6 +15,7 @@ class StatusStatelessTransformer extends Fractal\TransformerAbstract { protected $defaultIncludes = [ 'account', + 'tags', 'media_attachments', ]; @@ -72,6 +73,13 @@ class StatusStatelessTransformer extends Fractal\TransformerAbstract return $this->item($account, new AccountTransformer()); } + public function includeTags(Status $status) + { + $tags = $status->hashtags; + + return $this->collection($tags, new HashtagTransformer()); + } + public function includeMediaAttachments(Status $status) { return Cache::remember('status:transformer:media:attachments:'.$status->id, now()->addMinutes(3), function() use($status) { diff --git a/app/Transformer/Api/StatusTransformer.php b/app/Transformer/Api/StatusTransformer.php index a4359ae76..4ff621872 100644 --- a/app/Transformer/Api/StatusTransformer.php +++ b/app/Transformer/Api/StatusTransformer.php @@ -17,6 +17,7 @@ class StatusTransformer extends Fractal\TransformerAbstract { protected $defaultIncludes = [ 'account', + 'tags', 'media_attachments', ]; @@ -74,6 +75,13 @@ class StatusTransformer extends Fractal\TransformerAbstract return $this->item($account, new AccountTransformer()); } + public function includeTags(Status $status) + { + $tags = $status->hashtags; + + return $this->collection($tags, new HashtagTransformer()); + } + public function includeMediaAttachments(Status $status) { return Cache::remember('status:transformer:media:attachments:'.$status->id, now()->addMinutes(14), function() use($status) { From 241ae0368fb772de50c7cbaa9e7ec17a5f36fc10 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 18 May 2021 19:46:26 -0600 Subject: [PATCH 3/4] Add hashtag timeline to v1 api --- app/Http/Controllers/Api/ApiV1Controller.php | 45 ++++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index 973f14d3e..307bafa64 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -13,11 +13,13 @@ use App\{ Bookmark, Follower, FollowRequest, + Hashtag, Like, Media, Notification, Profile, Status, + StatusHashtag, User, UserFilter, }; @@ -1988,9 +1990,46 @@ class ApiV1Controller extends Controller { abort_if(!$request->user(), 403); - // todo - $res = []; - return response()->json($res); + $this->validate($request,[ + 'page' => 'nullable|integer|max:40', + 'min_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX, + 'max_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX, + 'limit' => 'nullable|integer|max:40' + ]); + + $tag = Hashtag::whereName($hashtag) + ->orWhere('slug', $hashtag) + ->first(); + + if(!$tag) { + return response()->json([]); + } + + $min = $request->input('min_id'); + $max = $request->input('max_id'); + $limit = $request->input('limit', 20); + + if(!$min && !$max) { + $id = 1; + $dir = '>'; + } else { + $dir = $min ? '>' : '<'; + $id = $min ?? $max; + } + + $res = StatusHashtag::whereHashtagId($tag->id) + ->whereStatusVisibility('public') + ->whereHas('media') + ->where('status_id', $dir, $id) + ->latest() + ->limit($limit) + ->pluck('status_id') + ->map(function ($i) { + return StatusService::get($i); + }) + ->all(); + + return response()->json($res, 200, [], JSON_PRETTY_PRINT); } /** From e8f15b6fa145408542f438faef026253d5460ad2 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 18 May 2021 19:47:47 -0600 Subject: [PATCH 4/4] Update changelog --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74604b94a..c2119eb3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,10 +7,11 @@ - Network Timeline ([af7face4](https://github.com/pixelfed/pixelfed/commit/af7face4)) - Admin config settings ([f2066b74](https://github.com/pixelfed/pixelfed/commit/f2066b74)) - Profile pronouns ([fabb57a9](https://github.com/pixelfed/pixelfed/commit/fabb57a9)) +- Hashtag timeline api support ([241ae036](https://github.com/pixelfed/pixelfed/commit/241ae036)) ### Updated - Updated AdminController, fix variable name in updateSpam method. ([6edaf940](https://github.com/pixelfed/pixelfed/commit/6edaf940)) -- Updated RemotAvatarFetch, only dispatch jobs if cloud storage is enabled. ([4f40f6f5](https://github.com/pixelfed/pixelfed/commit/4f40f6f5)) +- Updated RemoteAvatarFetch, only dispatch jobs if cloud storage is enabled. ([4f40f6f5](https://github.com/pixelfed/pixelfed/commit/4f40f6f5)) - Updated StatusService, add ttl of 7 days. ([6e44ae0b](https://github.com/pixelfed/pixelfed/commit/6e44ae0b)) - Updated StatusHashtagService, use StatusService for statuses. ([0355b567](https://github.com/pixelfed/pixelfed/commit/0355b567)) - Updated StatusHashtagService, remove deprecated methods. ([aa4c718d](https://github.com/pixelfed/pixelfed/commit/aa4c718d)) @@ -89,6 +90,7 @@ - Updated LikeService, show like count to status owner. ([4408e2ef](https://github.com/pixelfed/pixelfed/commit/4408e2ef)) - Updated admin settings, add rules. ([a4efbb75](https://github.com/pixelfed/pixelfed/commit/a4efbb75)) - Updated LikeService, fix authentication bug. ([c9abd70e](https://github.com/pixelfed/pixelfed/commit/c9abd70e)) +- Updated StatusTransformer, fix missing tags attribute. ([dac326e9](https://github.com/pixelfed/pixelfed/commit/dac326e9)) - ([](https://github.com/pixelfed/pixelfed/commit/)) ## [v0.10.10 (2021-01-28)](https://github.com/pixelfed/pixelfed/compare/v0.10.9...v0.10.10)