mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 22:41:27 +00:00
Update Discover apis
This commit is contained in:
parent
a1083511f0
commit
243fcac7d5
2 changed files with 22 additions and 16 deletions
|
@ -123,7 +123,7 @@ class DiscoverController extends Controller
|
||||||
|
|
||||||
public function trendingApi(Request $request)
|
public function trendingApi(Request $request)
|
||||||
{
|
{
|
||||||
abort_if(config('instance.discover.public') == false && !Auth::check(), 403);
|
abort_if(config('instance.discover.public') == false && !$request->user(), 403);
|
||||||
|
|
||||||
$this->validate($request, [
|
$this->validate($request, [
|
||||||
'range' => 'nullable|string|in:daily,monthly,yearly',
|
'range' => 'nullable|string|in:daily,monthly,yearly',
|
||||||
|
@ -179,7 +179,10 @@ class DiscoverController extends Controller
|
||||||
|
|
||||||
public function trendingHashtags(Request $request)
|
public function trendingHashtags(Request $request)
|
||||||
{
|
{
|
||||||
$res = StatusHashtag::select('hashtag_id', \DB::raw('count(*) as total'))
|
abort_if(!$request->user(), 403);
|
||||||
|
|
||||||
|
$res = Cache::remember('api:discover:v1.1:trending:hashtags', 3600, function() {
|
||||||
|
return StatusHashtag::select('hashtag_id', \DB::raw('count(*) as total'))
|
||||||
->groupBy('hashtag_id')
|
->groupBy('hashtag_id')
|
||||||
->orderBy('total','desc')
|
->orderBy('total','desc')
|
||||||
->where('created_at', '>', now()->subDays(90))
|
->where('created_at', '>', now()->subDays(90))
|
||||||
|
@ -191,9 +194,10 @@ class DiscoverController extends Controller
|
||||||
'id' => $hashtag->id,
|
'id' => $hashtag->id,
|
||||||
'total' => $h->total,
|
'total' => $h->total,
|
||||||
'name' => '#'.$hashtag->name,
|
'name' => '#'.$hashtag->name,
|
||||||
'url' => $hashtag->url('?src=dsh1')
|
'url' => $hashtag->url()
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
});
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -112,6 +112,8 @@ Route::group(['prefix' => 'api'], function() use($middleware) {
|
||||||
|
|
||||||
Route::group(['prefix' => 'discover'], function () use($middleware) {
|
Route::group(['prefix' => 'discover'], function () use($middleware) {
|
||||||
Route::get('accounts/popular', 'Api\ApiV1Controller@discoverAccountsPopular')->middleware($middleware);
|
Route::get('accounts/popular', 'Api\ApiV1Controller@discoverAccountsPopular')->middleware($middleware);
|
||||||
|
Route::get('posts/trending', 'DiscoverController@trendingApi')->middleware($middleware);
|
||||||
|
Route::get('posts/hashtags', 'DiscoverController@trendingHashtags')->middleware($middleware);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue