Skip to content

Commit

Permalink
Add a stats endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
austinwbest committed Nov 9, 2024
1 parent eca8e6e commit e794ab2
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion root/app/www/public/api/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
$originalEndpoint = $endpoint;
$method = strtolower($_SERVER['REQUEST_METHOD']);
$json = file_get_contents('php://input');
$internalEndpoint = str_equals_any($endpoint, ['/api/addstarr']) ? true : false;
$internalEndpoint = str_equals_any($endpoint, ['/api/addstarr', '/api/proxystats']) ? true : false;
$apikey = $_GET['apikey'] ?: $_SERVER['HTTP_X_API_KEY'];

if (!$apikey) {
Expand All @@ -49,6 +49,16 @@
}

switch ($endpoint) {
case '/api/proxystats':
$stats = [
'instances' => getTotalAppStats($starrsTable),
'endpoints' => getTotalEndpointStats($starrsTable, $appsTable),
'usage' => getTotalUsageStats($starrsTable, $appsTable, $usageTable)
];

$code = 200;
$response = $stats;
break;
case '/api/addstarr':
if (!$json) {
$code = 400;
Expand Down

0 comments on commit e794ab2

Please sign in to comment.