mirror of https://github.com/pixelfed/pixelfed.git
Update AdminApiController, add instance stats endpoint
This commit is contained in:
parent
ba58aaba36
commit
89c3710d3c
|
@ -23,6 +23,7 @@ use App\Services\AdminStatsService;
|
|||
use App\Services\ConfigCacheService;
|
||||
use App\Services\InstanceService;
|
||||
use App\Services\ModLogService;
|
||||
use App\Services\SnowflakeService;
|
||||
use App\Services\StatusService;
|
||||
use App\Services\NetworkTimelineService;
|
||||
use App\Services\NotificationService;
|
||||
|
@ -599,4 +600,62 @@ class AdminApiController extends Controller
|
|||
|
||||
return new AdminInstance($instance);
|
||||
}
|
||||
|
||||
public function getAllStats(Request $request)
|
||||
{
|
||||
abort_if(!$request->user(), 404);
|
||||
abort_unless($request->user()->is_admin === 1, 404);
|
||||
|
||||
if($request->has('refresh')) {
|
||||
Cache::forget('admin-api:instance-all-stats_v1');
|
||||
}
|
||||
|
||||
return Cache::remember('admin-api:instance-all-stats-v1', 1209600, function() {
|
||||
$days = range(0, 6);
|
||||
$res = [
|
||||
'cached_at' => now()->format('c'),
|
||||
];
|
||||
$minStatusId = SnowflakeService::byDate(now()->subDays(8));
|
||||
|
||||
foreach($days as $day) {
|
||||
$label = now()->subDays($day)->format('D');
|
||||
$labelShort = substr($label, 0, 1);
|
||||
$res['users']['days'][] = [
|
||||
'date' => now()->subDays($day)->format('M j Y'),
|
||||
'label_full' => $label,
|
||||
'label' => $labelShort,
|
||||
'count' => User::whereDate('created_at', now()->subDays($day))->count()
|
||||
];
|
||||
|
||||
$res['posts']['days'][] = [
|
||||
'date' => now()->subDays($day)->format('M j Y'),
|
||||
'label_full' => $label,
|
||||
'label' => $labelShort,
|
||||
'count' => Status::where('id', '>', $minStatusId)->whereNull('uri')->whereDate('created_at', now()->subDays($day))->count()
|
||||
];
|
||||
|
||||
$res['instances']['days'][] = [
|
||||
'date' => now()->subDays($day)->format('M j Y'),
|
||||
'label_full' => $label,
|
||||
'label' => $labelShort,
|
||||
'count' => Instance::whereDate('created_at', now()->subDays($day))->count()
|
||||
];
|
||||
}
|
||||
|
||||
$res['users']['total'] = DB::table('users')->count();
|
||||
$res['users']['min'] = collect($res['users']['days'])->min('count');
|
||||
$res['users']['max'] = $res['users']['total'];
|
||||
$res['users']['change'] = $res['users']['total'] - $res['users']['min'];
|
||||
$res['posts']['total'] = DB::table('statuses')->whereNull('uri')->count();
|
||||
$res['posts']['min'] = collect($res['posts']['days'])->min('count');
|
||||
$res['posts']['max'] = collect($res['posts']['days'])->max('count');
|
||||
$res['posts']['change'] = $res['posts']['total'] - $res['posts']['min'];
|
||||
$res['instances']['total'] = DB::table('instances')->count();
|
||||
$res['instances']['min'] = collect($res['instances']['days'])->min('count');
|
||||
$res['instances']['max'] = collect($res['instances']['days'])->max('count');
|
||||
$res['instances']['change'] = $res['instances']['total'] - $res['instances']['min'];
|
||||
|
||||
return $res;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -200,21 +200,21 @@ Route::group(['prefix' => 'api'], function() use($middleware) {
|
|||
});
|
||||
|
||||
Route::group(['prefix' => 'live'], function() use($middleware) {
|
||||
Route::post('create_stream', 'LiveStreamController@createStream')->middleware($middleware);
|
||||
Route::post('stream/edit', 'LiveStreamController@editStream')->middleware($middleware);
|
||||
Route::get('active/list', 'LiveStreamController@getActiveStreams')->middleware($middleware);
|
||||
Route::get('accounts/stream', 'LiveStreamController@getUserStream')->middleware($middleware);
|
||||
Route::get('accounts/stream/guest', 'LiveStreamController@getUserStreamAsGuest');
|
||||
Route::delete('accounts/stream', 'LiveStreamController@deleteStream')->middleware($middleware);
|
||||
Route::get('chat/latest', 'LiveStreamController@getLatestChat')->middleware($middleware);
|
||||
Route::post('chat/message', 'LiveStreamController@addChatComment')->middleware($middleware);
|
||||
Route::post('chat/delete', 'LiveStreamController@deleteChatComment')->middleware($middleware);
|
||||
Route::post('chat/ban-user', 'LiveStreamController@banChatUser')->middleware($middleware);
|
||||
Route::post('chat/pin', 'LiveStreamController@pinChatComment')->middleware($middleware);
|
||||
Route::post('chat/unpin', 'LiveStreamController@unpinChatComment')->middleware($middleware);
|
||||
Route::get('config', 'LiveStreamController@getConfig');
|
||||
Route::post('broadcast/publish', 'LiveStreamController@clientBroadcastPublish');
|
||||
Route::post('broadcast/finish', 'LiveStreamController@clientBroadcastFinish');
|
||||
// Route::post('create_stream', 'LiveStreamController@createStream')->middleware($middleware);
|
||||
// Route::post('stream/edit', 'LiveStreamController@editStream')->middleware($middleware);
|
||||
// Route::get('active/list', 'LiveStreamController@getActiveStreams')->middleware($middleware);
|
||||
// Route::get('accounts/stream', 'LiveStreamController@getUserStream')->middleware($middleware);
|
||||
// Route::get('accounts/stream/guest', 'LiveStreamController@getUserStreamAsGuest');
|
||||
// Route::delete('accounts/stream', 'LiveStreamController@deleteStream')->middleware($middleware);
|
||||
// Route::get('chat/latest', 'LiveStreamController@getLatestChat')->middleware($middleware);
|
||||
// Route::post('chat/message', 'LiveStreamController@addChatComment')->middleware($middleware);
|
||||
// Route::post('chat/delete', 'LiveStreamController@deleteChatComment')->middleware($middleware);
|
||||
// Route::post('chat/ban-user', 'LiveStreamController@banChatUser')->middleware($middleware);
|
||||
// Route::post('chat/pin', 'LiveStreamController@pinChatComment')->middleware($middleware);
|
||||
// Route::post('chat/unpin', 'LiveStreamController@unpinChatComment')->middleware($middleware);
|
||||
// Route::get('config', 'LiveStreamController@getConfig');
|
||||
// Route::post('broadcast/publish', 'LiveStreamController@clientBroadcastPublish')->middleware($middleware);
|
||||
// Route::post('broadcast/finish', 'LiveStreamController@clientBroadcastFinish')->middleware($middleware);
|
||||
});
|
||||
|
||||
Route::group(['prefix' => 'admin'], function() use($middleware) {
|
||||
|
@ -235,6 +235,7 @@ Route::group(['prefix' => 'api'], function() use($middleware) {
|
|||
Route::get('instances/get', 'Api\AdminApiController@getInstance')->middleware($middleware);
|
||||
Route::post('instances/moderate', 'Api\AdminApiController@moderateInstance')->middleware($middleware);
|
||||
Route::post('instances/refresh-stats', 'Api\AdminApiController@refreshInstanceStats')->middleware($middleware);
|
||||
Route::get('instance/stats', 'Api\AdminApiController@getAllStats')->middleware($middleware);
|
||||
});
|
||||
|
||||
Route::group(['prefix' => 'landing/v1'], function() use($middleware) {
|
||||
|
|
Loading…
Reference in New Issue