@@ -6,33 +6,58 @@ class Autobrr extends \App\SupportedApps implements \App\EnhancedApps
66{
77 public $ config ;
88
9- //protected $login_first = true; // Uncomment if api requests need to be authed first
10- //protected $method = 'POST'; // Uncomment if requests to the API should be set by POST
11-
12- public function __construct ()
13- {
14- //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set
15- }
16-
179 public function test ()
1810 {
19- $ test = parent ::appTest ($ this ->url ('status ' ));
11+ $ headers = [
12+ 'headers ' => [
13+ 'X-API-Token ' => $ this ->config ->apikey ,
14+ ],
15+ ];
16+
17+ $ test = parent ::appTest ($ this ->url ('healthz/liveness ' ), $ headers );
2018 echo $ test ->status ;
2119 }
2220
2321 public function livestats ()
2422 {
2523 $ status = 'inactive ' ;
26- $ res = parent ::execute ($ this ->url ('status ' ));
27- $ details = json_decode ($ res ->getBody ());
28-
29- $ data = [];
24+ $ headers = [
25+ 'headers ' => [
26+ 'X-API-Token ' => $ this ->config ->apikey ,
27+ ],
28+ ];
29+
30+ $ filtersRes = parent ::execute ($ this ->url ('filters ' ), $ headers );
31+ $ filters = json_decode ($ filtersRes ->getBody (), true );
32+ $ filterCount = is_array ($ filters ) ? count ($ filters ) : 0 ;
33+
34+ $ ircRes = parent ::execute ($ this ->url ('irc ' ), $ headers );
35+ $ irc = json_decode ($ ircRes ->getBody (), true );
36+ $ ircCount = 0 ;
37+
38+ if (is_array ($ irc )) {
39+ foreach ($ irc as $ conn ) {
40+ if (!empty ($ conn ['connected ' ])) {
41+ $ ircCount ++;
42+ }
43+ }
44+ }
45+
46+ $ data = [
47+ 'Filters ' => $ filterCount ,
48+ 'IRC ' => $ ircCount ,
49+ ];
50+
51+ if ($ filterCount > 0 || $ ircCount > 0 ) {
52+ $ status = 'active ' ;
53+ }
54+
3055 return parent ::getLiveStats ($ status , $ data );
3156 }
3257
3358 public function url ($ endpoint )
3459 {
35- $ api_url = parent ::normaliseurl ($ this ->config ->url ) . $ endpoint ;
36- return $ api_url ;
60+ return parent ::normaliseurl ($ this ->config ->url ) . 'api/ ' . $ endpoint ;
3761 }
3862}
63+
0 commit comments