4
0
Эх сурвалжийг харах

Reflect homepage refresh for Monitorr (#1554)

CauseFX 5 жил өмнө
parent
commit
5f53452bfc
1 өөрчлөгдсөн 18 нэмэгдсэн , 17 устгасан
  1. 18 17
      api/homepage/monitorr.php

+ 18 - 17
api/homepage/monitorr.php

@@ -118,7 +118,8 @@ trait MonitorrHomepageItem
 		$url = $this->qualifyURL($this->config['monitorrURL']);
 		$dataUrl = $url . '/assets/php/loop.php';
 		try {
-			$response = Requests::get($dataUrl, ['Token' => $this->config['organizrAPI']], []);
+			$options = $this->requestOptions($this->config['monitorrURL'], false, $this->config['homepageMonitorrRefresh']);
+			$response = Requests::get($dataUrl, ['Token' => $this->config['organizrAPI']], $options);
 			if ($response->success) {
 				$html = html_entity_decode($response->body);
 				// This section grabs the names of all services by regex
@@ -127,25 +128,24 @@ trait MonitorrHomepageItem
 				$servicePattern = '/<div id="servicetitle(?:offline|nolink)?".*><div>(.*)<\/div><\/div><div class="(?:btnonline|btnoffline|btnunknown)".*>(Online|Offline|Unresponsive)<\/div>(:?<\/a>)?<\/div><\/div>/';
 				preg_match_all($servicePattern, $html, $servicesMatch);
 				$services = array_filter($servicesMatch[1]);
-                $status = array_filter($servicesMatch[2]);
+				$status = array_filter($servicesMatch[2]);
 				$statuses = [];
 				foreach ($services as $key => $service) {
 					$match = $status[$key];
 					$statuses[$service] = $match;
-                    if ($match == 'Online') {
-                        $statuses[$service] = [
-                            'status' => true
-                        ];
-                    } else if ($match == 'Offline') {
-                        $statuses[$service] = [
-                            'status' => false
-                        ];
-                    } else if ($match == 'Unresponsive') {
-                        $statuses[$service] = [
-                            'status' => 'unresponsive'
-                        ];
-                    }
-
+					if ($match == 'Online') {
+						$statuses[$service] = [
+							'status' => true
+						];
+					} else if ($match == 'Offline') {
+						$statuses[$service] = [
+							'status' => false
+						];
+					} else if ($match == 'Unresponsive') {
+						$statuses[$service] = [
+							'status' => 'unresponsive'
+						];
+					}
 					$statuses[$service]['sort'] = $key;
 					$imageMatch = [];
 					$imgPattern = '/assets\/img\/\.\.(.*)" class="serviceimg" alt=.*><\/div><\/div><div id="servicetitle"><div>' . $service . '|assets\/img\/\.\.(.*)" class="serviceimg imgoffline" alt=.*><\/div><\/div><div id="servicetitleoffline".*><div>' . $service . '|assets\/img\/\.\.(.*)" class="serviceimg" alt=.*><\/div><\/div><div id="servicetitlenolink".*><div>' . $service . '/';
@@ -162,7 +162,8 @@ trait MonitorrHomepageItem
 					$ext = $ext[key(array_slice($ext, -1, 1, true))];
 					$imageUrl = $url . '/assets' . $image;
 					$cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
-					$img = Requests::get($imageUrl, ['Token' => $this->config['organizrAPI']], []);
+					$options = $this->requestOptions($this->config['monitorrURL'], false, $this->config['homepageMonitorrRefresh']);
+					$img = Requests::get($imageUrl, ['Token' => $this->config['organizrAPI']], $options);
 					if ($img->success) {
 						$base64 = 'data:image/' . $ext . ';base64,' . base64_encode($img->body);
 						$statuses[$service]['image'] = $base64;