diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e7f63efb..8921d9583 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - Add Media Tags ([711fc020](https://github.com/pixelfed/pixelfed/commit/711fc020)) - Add MediaTagService ([524c6d45](https://github.com/pixelfed/pixelfed/commit/524c6d45)) - Add MediaBlocklist feature ([ba1f7e7e](https://github.com/pixelfed/pixelfed/commit/ba1f7e7e)) +- New Discover Layout, add trending hashtags, places and posts ([c251d41b](https://github.com/pixelfed/pixelfed/commit/c251d41b)) ### Updated - Updated PostComponent, fix remote urls ([42716ccc](https://github.com/pixelfed/pixelfed/commit/42716ccc)) diff --git a/app/Http/Controllers/DiscoverController.php b/app/Http/Controllers/DiscoverController.php index 4f443ed2d..9bc48c7a4 100644 --- a/app/Http/Controllers/DiscoverController.php +++ b/app/Http/Controllers/DiscoverController.php @@ -16,6 +16,7 @@ use Auth, DB, Cache; use Illuminate\Http\Request; use App\Transformer\Api\AccountTransformer; use App\Transformer\Api\AccountWithStatusesTransformer; +use App\Transformer\Api\StatusTransformer; use App\Transformer\Api\StatusStatelessTransformer; use League\Fractal; use League\Fractal\Serializer\ArraySerializer; @@ -165,4 +166,74 @@ class DiscoverController extends Controller return $res; } + + public function trendingApi(Request $request) + { + $this->validate($request, [ + 'range' => 'nullable|string|in:daily,monthly,alltime' + ]); + + $range = $request->filled('range') ? + $request->input('range') == 'alltime' ? '-1' : + ($request->input('range') == 'daily' ? 1 : 31) : 1; + + $key = ':api:discover:trending:v1:range:' . $range; + $ttl = now()->addHours(2); + $res = Cache::remember($key, $ttl, function() use($range) { + if($range == '-1') { + $res = Status::orderBy('likes_count','desc') + ->take(12) + ->get(); + } else { + $res = Status::orderBy('likes_count','desc') + ->take(12) + ->where('created_at', '>', now()->subDays($range)) + ->get(); + } + $resource = new Fractal\Resource\Collection($res, new StatusStatelessTransformer()); + return $this->fractal->createData($resource)->toArray(); + }); + return response()->json($res, 200, [], JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES); + } + + public function trendingHashtags(Request $request) + { + $res = StatusHashtag::select('hashtag_id', \DB::raw('count(*) as total')) + ->groupBy('hashtag_id') + ->orderBy('total','desc') + ->where('created_at', '>', now()->subDays(4)) + ->take(9) + ->get() + ->map(function($h) { + $hashtag = $h->hashtag; + return [ + 'id' => $hashtag->id, + 'total' => $h->total, + 'name' => '#'.$hashtag->name, + 'url' => $hashtag->url('?src=dsh1') + ]; + }); + return $res; + } + + public function trendingPlaces(Request $request) + { + $res = Status::select('place_id',DB::raw('count(place_id) as total')) + ->whereNotNull('place_id') + ->where('created_at','>',now()->subDays(14)) + ->groupBy('place_id') + ->orderBy('total') + ->limit(4) + ->get() + ->map(function($s){ + $p = $s->place; + return [ + 'name' => $p->name, + 'country' => $p->country, + 'url' => $p->url() + ]; + }); + + return $res; + } } diff --git a/app/Http/Controllers/InternalApiController.php b/app/Http/Controllers/InternalApiController.php index 31ecd2563..4947e8c2e 100644 --- a/app/Http/Controllers/InternalApiController.php +++ b/app/Http/Controllers/InternalApiController.php @@ -95,7 +95,7 @@ class InternalApiController extends Controller ->with('media') ->inRandomOrder() ->latest() - ->take(37) + ->take(39) ->get(); $res = [ diff --git a/public/js/discover.js b/public/js/discover.js index 95229664f..5f36b2d78 100644 Binary files a/public/js/discover.js and b/public/js/discover.js differ diff --git a/public/mix-manifest.json b/public/mix-manifest.json index ec2f415c6..65e28f70f 100644 Binary files a/public/mix-manifest.json and b/public/mix-manifest.json differ diff --git a/resources/assets/js/components/DiscoverComponent.vue b/resources/assets/js/components/DiscoverComponent.vue index 8f2f6350e..34bbe3224 100644 --- a/resources/assets/js/components/DiscoverComponent.vue +++ b/resources/assets/js/components/DiscoverComponent.vue @@ -4,39 +4,111 @@
DISCOVER
+DISCOVER
+DISCOVER