Update DiscoverController, add albums and video to discover trending api

This commit is contained in:
Daniel Supernault 2021-01-11 00:31:21 -07:00
parent 96afc3e781
commit b2fe219eec
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -170,26 +170,26 @@ class DiscoverController extends Controller
public function trendingApi(Request $request)
{
$this->validate($request, [
'range' => 'nullable|string|in:daily,monthly,alltime'
'range' => 'nullable|string|in:daily,monthly'
]);
$range = $request->filled('range') ?
$request->input('range') == 'alltime' ? '-1' :
($request->input('range') == 'daily' ? 1 : 31) : 1;
$key = ':api:discover:trending:v2:range:' . $range;
$key = ':api:discover:trending:v2.1:range:' . $range;
$ttl = now()->addHours(2);
$res = Cache::remember($key, $ttl, function() use($range) {
if($range == '-1') {
$res = Status::whereScope('public')
->whereType('photo')
->whereIn('type', ['photo', 'photo:album', 'video'])
->whereIsNsfw(false)
->orderBy('likes_count','desc')
->take(12)
->get();
} else {
$res = Status::whereScope('public')
->whereType('photo')
->whereIn('type', ['photo', 'photo:album', 'video'])
->whereIsNsfw(false)
->orderBy('likes_count','desc')
->take(12)