diff --git a/app/Http/Controllers/Api/AdminController.php b/app/Http/Controllers/Api/AdminController.php index 6ec226675..b70b1b9d0 100644 --- a/app/Http/Controllers/Api/AdminController.php +++ b/app/Http/Controllers/Api/AdminController.php @@ -933,19 +933,35 @@ public function instanceStats(Request $request) $res = [ [ 'name' => 'Total', - 'value' => Instance::whereNotNull('software')->whereFederationState(5)->count(), + 'value' => Instance::active()->count(), ], [ 'name' => 'New', - 'value' => Instance::whereNotNull('software')->whereFederationState(5)->where('created_at', '>', now()->subHours(24))->count(), + 'value' => Instance::active()->where('created_at', '>', now()->subHours(24))->count(), + ], + [ + 'name' => 'Blocked', + 'value' => Instance::whereFederationState(2)->count(), ], [ 'name' => 'Users', - 'value' => Instance::whereNotNull('software')->where('federation_state', 5)->sum('user_count'), + 'value' => Instance::active()->sum('user_count'), + ], + [ + 'name' => 'Videos', + 'value' => Instance::active()->sum('video_count'), + ], + [ + 'name' => 'Followers', + 'value' => Instance::active()->sum('follower_count'), + ], + [ + 'name' => 'Following', + 'value' => Instance::active()->sum('following_count'), ], [ 'name' => 'Comments', - 'value' => Instance::whereNotNull('software')->where('federation_state', 5)->sum('comment_count'), + 'value' => Instance::active()->sum('comment_count'), ], ]; @@ -954,14 +970,16 @@ public function instanceStats(Request $request) public function instanceAdvancedStats() { - $totalInstances = Instance::count(); - $activeInstances = Instance::where('is_blocked', false)->count(); - $allowedVideoPosts = Instance::where('allow_video_posts', true)->count(); - $allowedInFyf = Instance::where('allow_videos_in_fyf', true)->count(); + $totalInstances = Instance::active()->count(); + $activeInstances = Instance::active()->count(); + $allowedVideoPosts = Instance::active()->where('allow_video_posts', true)->count(); + $allowedInFyf = Instance::active()->where('allow_videos_in_fyf', true)->count(); $softwareStats = Instance::select('software') ->selectRaw('COUNT(*) as count') ->selectRaw('SUM(CASE WHEN allow_video_posts = 1 THEN 1 ELSE 0 END) as allow_video_posts_count') + ->where('is_blocked', false) + ->active() ->groupBy('software') ->orderByDesc('count') ->get(); diff --git a/app/Http/Controllers/Api/WebPublicController.php b/app/Http/Controllers/Api/WebPublicController.php index 674fa0bde..718bbccf1 100644 --- a/app/Http/Controllers/Api/WebPublicController.php +++ b/app/Http/Controllers/Api/WebPublicController.php @@ -199,7 +199,7 @@ public function getAccountInfoByUsername(Request $request, $id) $res['is_owner'] = $request->user()?->profile_id == $profile->id; $res['likes_count'] = AccountService::getAccountLikesCount($profile->id); - return response()->json(['data' => $res]); + return response()->json(['data' => $res], 200, [], JSON_UNESCAPED_SLASHES); } public function accountFollowers(Request $request, $id) diff --git a/app/Models/Instance.php b/app/Models/Instance.php index 5878fbea4..e837c738c 100644 --- a/app/Models/Instance.php +++ b/app/Models/Instance.php @@ -2,6 +2,7 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; /** @@ -109,4 +110,13 @@ class Instance extends Model * 4 - Temporary Silenced * 5 - Full federation */ + + /** + * @param Builder $query + * @return Builder + */ + protected function scopeActive(Builder $query): Builder + { + return $query->where('federation_state', 5); + } }