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 @@
- {!! Form::text('config[override_url]', null, array('placeholder' => __('app.apps.override'), 'id' => 'override_url', 'class' => 'form-control')) !!} + {!! Form::text('config[override_url]', isset($item) ? $item->getconfig()->override_url : null, ['placeholder' => __('app.apps.override'), 'id' => 'override_url', 'class' => 'form-control']) !!}
- - {!! Form::text('config[username]', null, array('placeholder' => __('app.apps.username'), 'data-config' => 'username', 'class' => 'form-control config-item')) !!} -
-
- - {!! Form::input('password', 'config[password]', '', ['placeholder' => __('app.apps.password'), 'data-config' => 'password', 'class' => 'form-control config-item']) !!} + + {!! Form::text('config[apikey]', isset($item) ? $item->getconfig()->apikey : null, ['placeholder' => __('app.apps.apikey'), 'data-config' => 'apikey', 'class' => 'form-control config-item']) !!}
- diff --git a/Autobrr/livestats.blade.php b/Autobrr/livestats.blade.php index 4fa2c8bc4d..7697c0a8c3 100644 --- a/Autobrr/livestats.blade.php +++ b/Autobrr/livestats.blade.php @@ -1,10 +1,15 @@ \ No newline at end of file + @if (isset($data['Filters'])) +
  • + Filters + {{ $data['Filters'] }} +
  • + @endif + @if (isset($data['IRC'])) +
  • + IRC + {{ $data['IRC'] }} +
  • + @endif + +