diff --git a/CHANGELOG.md b/CHANGELOG.md index 74604b94..c2119eb3 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) diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index 8837e4f5..307bafa6 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, }; @@ -977,7 +979,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 +996,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') ] ]; @@ -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); } /** diff --git a/app/Transformer/Api/StatusStatelessTransformer.php b/app/Transformer/Api/StatusStatelessTransformer.php index 2190303e..b3ba463d 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 a4359ae7..4ff62187 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) { diff --git a/app/Util/Site/Config.php b/app/Util/Site/Config.php index d9836ca7..117696c5 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'), ]