diff --git a/Autobrr/Autobrr.php b/Autobrr/Autobrr.php index f204fe5e43..ff28a922af 100644 --- a/Autobrr/Autobrr.php +++ b/Autobrr/Autobrr.php @@ -6,33 +6,57 @@ class Autobrr extends \App\SupportedApps implements \App\EnhancedApps { public $config; - //protected $login_first = true; // Uncomment if api requests need to be authed first - //protected $method = 'POST'; // Uncomment if requests to the API should be set by POST - - public function __construct() - { - //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } - public function test() { - $test = parent::appTest($this->url('status')); + $headers = [ + 'headers' => [ + 'X-API-Token' => $this->config->apikey, + ], + ]; + + $test = parent::appTest($this->url('healthz/liveness'), $headers); echo $test->status; } public function livestats() { $status = 'inactive'; - $res = parent::execute($this->url('status')); - $details = json_decode($res->getBody()); + $headers = [ + 'headers' => [ + 'X-API-Token' => $this->config->apikey, + ], + ]; + + $filtersRes = parent::execute($this->url('filters'), $headers); + $filters = json_decode($filtersRes->getBody(), true); + $filterCount = is_array($filters) ? count($filters) : 0; + + $ircRes = parent::execute($this->url('irc'), $headers); + $irc = json_decode($ircRes->getBody(), true); + $ircCount = 0; + + if (is_array($irc)) { + foreach ($irc as $conn) { + if (!empty($conn['connected'])) { + $ircCount++; + } + } + } + + $data = [ + 'Filters' => $filterCount, + 'IRC' => $ircCount, + ]; + + if ($filterCount > 0 || $ircCount > 0) { + $status = 'active'; + } - $data = []; return parent::getLiveStats($status, $data); } public function url($endpoint) { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; + return parent::normaliseurl($this->config->url) . 'api/' . $endpoint; } } diff --git a/Autobrr/config.blade.php b/Autobrr/config.blade.php index e892e6c0d9..4a8082c945 100644 --- a/Autobrr/config.blade.php +++ b/Autobrr/config.blade.php @@ -2,18 +2,13 @@