mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-10 00:34:50 +00:00
Add /api/v1/followed_tags api endpoint
This commit is contained in:
parent
fc1a385cfd
commit
175a848665
3 changed files with 81 additions and 1 deletions
|
@ -19,6 +19,7 @@ use App\{
|
||||||
Follower,
|
Follower,
|
||||||
FollowRequest,
|
FollowRequest,
|
||||||
Hashtag,
|
Hashtag,
|
||||||
|
HashtagFollow,
|
||||||
Instance,
|
Instance,
|
||||||
Like,
|
Like,
|
||||||
Media,
|
Media,
|
||||||
|
@ -99,6 +100,7 @@ use App\Jobs\FollowPipeline\FollowRejectPipeline;
|
||||||
use Illuminate\Support\Facades\RateLimiter;
|
use Illuminate\Support\Facades\RateLimiter;
|
||||||
use Purify;
|
use Purify;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use App\Http\Resources\MastoApi\FollowedTagResource;
|
||||||
|
|
||||||
class ApiV1Controller extends Controller
|
class ApiV1Controller extends Controller
|
||||||
{
|
{
|
||||||
|
@ -3802,4 +3804,47 @@ class ApiV1Controller extends Controller
|
||||||
|
|
||||||
return $this->json([]);
|
return $this->json([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET /api/v1/followed_tags
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getFollowedTags(Request $request)
|
||||||
|
{
|
||||||
|
abort_if(!$request->user(), 403);
|
||||||
|
|
||||||
|
if(config('pixelfed.bouncer.cloud_ips.ban_api')) {
|
||||||
|
abort_if(BouncerService::checkIp($request->ip()), 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
$account = AccountService::get($request->user()->profile_id);
|
||||||
|
|
||||||
|
$this->validate($request, [
|
||||||
|
'cursor' => 'sometimes',
|
||||||
|
'limit' => 'sometimes|integer|min:1|max:200'
|
||||||
|
]);
|
||||||
|
$limit = $request->input('limit', 100);
|
||||||
|
|
||||||
|
$res = HashtagFollow::whereProfileId($account['id'])
|
||||||
|
->cursorPaginate($limit)->withQueryString();
|
||||||
|
|
||||||
|
$pagination = false;
|
||||||
|
$prevPage = $res->nextPageUrl();
|
||||||
|
$nextPage = $res->previousPageUrl();
|
||||||
|
if($nextPage && $prevPage) {
|
||||||
|
$pagination = '<' . $nextPage . '>; rel="next", <' . $prevPage . '>; rel="prev"';
|
||||||
|
} else if($nextPage && !$prevPage) {
|
||||||
|
$pagination = '<' . $nextPage . '>; rel="next"';
|
||||||
|
} else if(!$nextPage && $prevPage) {
|
||||||
|
$pagination = '<' . $prevPage . '>; rel="prev"';
|
||||||
|
}
|
||||||
|
|
||||||
|
if($pagination) {
|
||||||
|
return response()->json(FollowedTagResource::collection($res)->collection)
|
||||||
|
->header('Link', $pagination);
|
||||||
|
}
|
||||||
|
return response()->json(FollowedTagResource::collection($res)->collection);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
33
app/Http/Resources/MastoApi/FollowedTagResource.php
Normal file
33
app/Http/Resources/MastoApi/FollowedTagResource.php
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Resources\MastoApi;
|
||||||
|
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Cache;
|
||||||
|
use App\Services\HashtagService;
|
||||||
|
|
||||||
|
class FollowedTagResource extends JsonResource
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Transform the resource into an array.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||||
|
*/
|
||||||
|
public function toArray($request)
|
||||||
|
{
|
||||||
|
$tag = HashtagService::get($this->hashtag_id);
|
||||||
|
|
||||||
|
if(!$tag || !isset($tag['name'])) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'name' => $tag['name'],
|
||||||
|
'url' => config('app.url') . '/i/web/hashtag/' . $tag['slug'],
|
||||||
|
'history' => [],
|
||||||
|
'following' => true,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
|
@ -89,6 +89,8 @@ Route::group(['prefix' => 'api'], function() use($middleware) {
|
||||||
Route::get('announcements', 'Api\ApiV1Controller@getAnnouncements')->middleware($middleware);
|
Route::get('announcements', 'Api\ApiV1Controller@getAnnouncements')->middleware($middleware);
|
||||||
Route::get('markers', 'Api\ApiV1Controller@getMarkers')->middleware($middleware);
|
Route::get('markers', 'Api\ApiV1Controller@getMarkers')->middleware($middleware);
|
||||||
Route::post('markers', 'Api\ApiV1Controller@setMarkers')->middleware($middleware);
|
Route::post('markers', 'Api\ApiV1Controller@setMarkers')->middleware($middleware);
|
||||||
|
|
||||||
|
Route::get('followed_tags', 'Api\ApiV1Controller@getFollowedTags')->middleware($middleware);
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::group(['prefix' => 'v2'], function() use($middleware) {
|
Route::group(['prefix' => 'v2'], function() use($middleware) {
|
||||||
|
|
Loading…
Reference in a new issue