Skip to content

Commit 3847338

Browse files
committed
Update AdminController
1 parent a091f3e commit 3847338

3 files changed

Lines changed: 37 additions & 9 deletions

File tree

app/Http/Controllers/Api/AdminController.php

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -933,19 +933,35 @@ public function instanceStats(Request $request)
933933
$res = [
934934
[
935935
'name' => 'Total',
936-
'value' => Instance::whereNotNull('software')->whereFederationState(5)->count(),
936+
'value' => Instance::active()->count(),
937937
],
938938
[
939939
'name' => 'New',
940-
'value' => Instance::whereNotNull('software')->whereFederationState(5)->where('created_at', '>', now()->subHours(24))->count(),
940+
'value' => Instance::active()->where('created_at', '>', now()->subHours(24))->count(),
941+
],
942+
[
943+
'name' => 'Blocked',
944+
'value' => Instance::whereFederationState(2)->count(),
941945
],
942946
[
943947
'name' => 'Users',
944-
'value' => Instance::whereNotNull('software')->where('federation_state', 5)->sum('user_count'),
948+
'value' => Instance::active()->sum('user_count'),
949+
],
950+
[
951+
'name' => 'Videos',
952+
'value' => Instance::active()->sum('video_count'),
953+
],
954+
[
955+
'name' => 'Followers',
956+
'value' => Instance::active()->sum('follower_count'),
957+
],
958+
[
959+
'name' => 'Following',
960+
'value' => Instance::active()->sum('following_count'),
945961
],
946962
[
947963
'name' => 'Comments',
948-
'value' => Instance::whereNotNull('software')->where('federation_state', 5)->sum('comment_count'),
964+
'value' => Instance::active()->sum('comment_count'),
949965
],
950966
];
951967

@@ -954,14 +970,16 @@ public function instanceStats(Request $request)
954970

955971
public function instanceAdvancedStats()
956972
{
957-
$totalInstances = Instance::count();
958-
$activeInstances = Instance::where('is_blocked', false)->count();
959-
$allowedVideoPosts = Instance::where('allow_video_posts', true)->count();
960-
$allowedInFyf = Instance::where('allow_videos_in_fyf', true)->count();
973+
$totalInstances = Instance::active()->count();
974+
$activeInstances = Instance::active()->count();
975+
$allowedVideoPosts = Instance::active()->where('allow_video_posts', true)->count();
976+
$allowedInFyf = Instance::active()->where('allow_videos_in_fyf', true)->count();
961977

962978
$softwareStats = Instance::select('software')
963979
->selectRaw('COUNT(*) as count')
964980
->selectRaw('SUM(CASE WHEN allow_video_posts = 1 THEN 1 ELSE 0 END) as allow_video_posts_count')
981+
->where('is_blocked', false)
982+
->active()
965983
->groupBy('software')
966984
->orderByDesc('count')
967985
->get();

app/Http/Controllers/Api/WebPublicController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public function getAccountInfoByUsername(Request $request, $id)
199199
$res['is_owner'] = $request->user()?->profile_id == $profile->id;
200200
$res['likes_count'] = AccountService::getAccountLikesCount($profile->id);
201201

202-
return response()->json(['data' => $res]);
202+
return response()->json(['data' => $res], 200, [], JSON_UNESCAPED_SLASHES);
203203
}
204204

205205
public function accountFollowers(Request $request, $id)

app/Models/Instance.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Models;
44

5+
use Illuminate\Database\Eloquent\Builder;
56
use Illuminate\Database\Eloquent\Model;
67

78
/**
@@ -109,4 +110,13 @@ class Instance extends Model
109110
* 4 - Temporary Silenced
110111
* 5 - Full federation
111112
*/
113+
114+
/**
115+
* @param Builder<Instance> $query
116+
* @return Builder<Instance>
117+
*/
118+
protected function scopeActive(Builder $query): Builder
119+
{
120+
return $query->where('federation_state', 5);
121+
}
112122
}

0 commit comments

Comments
 (0)