Browse Source

fix Tautulli not showing on the Homepage (#1556) by testing out new request options

CauseFX 5 years ago
parent
commit
e01514f5fe
2 changed files with 25 additions and 8 deletions
  1. 14 0
      api/functions/organizr-functions.php
  2. 11 8
      api/homepage/tautulli.php

+ 14 - 0
api/functions/organizr-functions.php

@@ -605,4 +605,18 @@ trait OrganizrFunctions
 	{
 		return strtr($link, $variables);
 	}
+	
+	public function requestOptions($url, $override = false, $timeout = null)
+	{
+		$options = [];
+		if (is_numeric($timeout)) {
+			$timeout = $timeout / 1000;
+			array_push($options, array('timeout' => $timeout));
+		}
+		if ($this->localURL($url, $override)) {
+			array_push($options, array('verify' => false));
+			
+		}
+		return $options;
+	}
 }

+ 11 - 8
api/homepage/tautulli.php

@@ -164,7 +164,7 @@ trait TautulliHomepageItem
 			)
 		);
 	}
-
+	
 	public function testConnectionTautulli()
 	{
 		if (empty($this->config['tautulliURL'])) {
@@ -179,7 +179,8 @@ trait TautulliHomepageItem
 		$apiURL = $url . '/api/v2?apikey=' . $this->config['tautulliApikey'];
 		try {
 			$homestatsUrl = $apiURL . '&cmd=get_home_stats&grouping=1';
-			$homestats = Requests::get($homestatsUrl, [], []);
+			$options = $this->requestOptions($this->config['tautulliURL'], false, $this->config['homepageTautulliRefresh']);
+			$homestats = Requests::get($homestatsUrl, [], $options);
 			if ($homestats->success) {
 				$this->setAPIResponse('success', 'API Connection succeeded', 200);
 				return true;
@@ -193,7 +194,7 @@ trait TautulliHomepageItem
 			return false;
 		}
 	}
-
+	
 	public function tautulliHomepagePermissions($key = null)
 	{
 		$permissions = [
@@ -218,7 +219,7 @@ trait TautulliHomepageItem
 			return [];
 		}
 	}
-
+	
 	public function homepageOrdertautulli()
 	{
 		if ($this->homepageItemPermissions($this->tautulliHomepagePermissions('main'))) {
@@ -234,7 +235,7 @@ trait TautulliHomepageItem
 				';
 		}
 	}
-
+	
 	public function getTautulliHomepageData()
 	{
 		if (!$this->homepageItemPermissions($this->tautulliHomepagePermissions('main'), true)) {
@@ -249,7 +250,8 @@ trait TautulliHomepageItem
 		$nowPlayingWidth = $this->getCacheImageSize('npw');
 		try {
 			$homestatsUrl = $apiURL . '&cmd=get_home_stats&grouping=1';
-			$homestats = Requests::get($homestatsUrl, [], []);
+			$options = $this->requestOptions($this->config['tautulliURL'], false, $this->config['homepageTautulliRefresh']);
+			$homestats = Requests::get($homestatsUrl, [], $options);
 			if ($homestats->success) {
 				$homestats = json_decode($homestats->body, true);
 				$api['homestats'] = $homestats['response'];
@@ -270,7 +272,8 @@ trait TautulliHomepageItem
 				$this->cacheImage($url . '/images/platforms/' . $platform . '.svg', 'tautulli-' . $platform, 'svg');
 			}
 			$libstatsUrl = $apiURL . '&cmd=get_libraries';
-			$libstats = Requests::get($libstatsUrl, [], []);
+			$options = $this->requestOptions($this->config['tautulliURL'], false, $this->config['homepageTautulliRefresh']);
+			$libstats = Requests::get($libstatsUrl, [], $options);
 			if ($libstats->success) {
 				$libstats = json_decode($libstats->body, true);
 				$api['libstats'] = $libstats['response'];
@@ -327,4 +330,4 @@ trait TautulliHomepageItem
 		$this->setAPIResponse('success', null, 200, $api);
 		return $api;
 	}
-}
+}