From a4bc5ce3d030be6021dbab8824f80246bd296b83 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 9 Mar 2024 23:25:28 -0700 Subject: [PATCH] Update web-api popular accounts route to its own method to remove the breaking oauth scope bug --- app/Http/Controllers/Api/ApiV1Controller.php | 6 ++- app/Http/Controllers/DiscoverController.php | 43 ++++++++++++++++++++ routes/web-api.php | 2 +- 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index 8253e1373..5ab69dfc9 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -4066,7 +4066,7 @@ class ApiV1Controller extends Controller $pid = $request->user()->profile_id; - $ids = Cache::remember('api:v1.1:discover:accounts:popular', 3600, function () { + $ids = Cache::remember('api:v1.1:discover:accounts:popular', 14400, function () { return DB::table('profiles') ->where('is_private', false) ->whereNull('status') @@ -4075,6 +4075,7 @@ class ApiV1Controller extends Controller ->get(); }); $filters = UserFilterService::filters($pid); + $asf = AdminShadowFilterService::getHideFromPublicFeedsList(); $ids = $ids->map(function ($profile) { return AccountService::get($profile->id, true); }) @@ -4087,6 +4088,9 @@ class ApiV1Controller extends Controller ->filter(function ($profile) use ($pid) { return ! FollowerService::follows($pid, $profile['id'], true); }) + ->filter(function ($profile) use ($asf) { + return ! in_array($profile['id'], $asf); + }) ->filter(function ($profile) use ($filters) { return ! in_array($profile['id'], $filters); }) diff --git a/app/Http/Controllers/DiscoverController.php b/app/Http/Controllers/DiscoverController.php index 862a16ad0..c9e93eecf 100644 --- a/app/Http/Controllers/DiscoverController.php +++ b/app/Http/Controllers/DiscoverController.php @@ -5,8 +5,11 @@ namespace App\Http\Controllers; use App\Hashtag; use App\Instance; use App\Like; +use App\Services\AccountService; +use App\Services\AdminShadowFilterService; use App\Services\BookmarkService; use App\Services\ConfigCacheService; +use App\Services\FollowerService; use App\Services\HashtagService; use App\Services\LikeService; use App\Services\ReblogService; @@ -377,4 +380,44 @@ class DiscoverController extends Controller return $res; } + + public function discoverAccountsPopular(Request $request) + { + abort_if(! $request->user(), 403); + + $pid = $request->user()->profile_id; + + $ids = Cache::remember('api:v1.1:discover:accounts:popular', 14400, function () { + return DB::table('profiles') + ->where('is_private', false) + ->whereNull('status') + ->orderByDesc('profiles.followers_count') + ->limit(30) + ->get(); + }); + $filters = UserFilterService::filters($pid); + $asf = AdminShadowFilterService::getHideFromPublicFeedsList(); + $ids = $ids->map(function ($profile) { + return AccountService::get($profile->id, true); + }) + ->filter(function ($profile) { + return $profile && isset($profile['id'], $profile['locked']) && ! $profile['locked']; + }) + ->filter(function ($profile) use ($pid) { + return $profile['id'] != $pid; + }) + ->filter(function ($profile) use ($pid) { + return ! FollowerService::follows($pid, $profile['id'], true); + }) + ->filter(function ($profile) use ($asf) { + return ! in_array($profile['id'], $asf); + }) + ->filter(function ($profile) use ($filters) { + return ! in_array($profile['id'], $filters); + }) + ->take(16) + ->values(); + + return response()->json($ids, 200, [], JSON_UNESCAPED_SLASHES); + } } diff --git a/routes/web-api.php b/routes/web-api.php index e19c36b6c..4b0595c66 100644 --- a/routes/web-api.php +++ b/routes/web-api.php @@ -115,7 +115,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact Route::post('discover/admin/features', 'DiscoverController@updateFeatures'); }); - Route::get('discover/accounts/popular', 'Api\ApiV1Controller@discoverAccountsPopular'); + Route::get('discover/accounts/popular', 'DiscoverController@discoverAccountsPopular'); Route::post('web/change-language.json', 'SpaController@updateLanguage'); });