This commit is contained in:
denisdulici 2018-05-25 06:11:53 +03:00
parent bcb56de06a
commit 2b9721195d
4 changed files with 36 additions and 14 deletions

View File

@ -6,6 +6,7 @@ use App\Utilities\Info;
use Artisan; use Artisan;
use File; use File;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
use Module; use Module;
use ZipArchive; use ZipArchive;
@ -22,7 +23,7 @@ trait Modules
$response = $this->getRemote('token/check', 'POST', $data); $response = $this->getRemote('token/check', 'POST', $data);
if ($response->getStatusCode() == 200) { if ($response && ($response->getStatusCode() == 200)) {
$result = json_decode($response->getBody()); $result = json_decode($response->getBody());
return ($result->success) ? true : false; return ($result->success) ? true : false;
@ -35,7 +36,7 @@ trait Modules
{ {
$response = $this->getRemote('apps/items'); $response = $this->getRemote('apps/items');
if ($response->getStatusCode() == 200) { if ($response && ($response->getStatusCode() == 200)) {
return json_decode($response->getBody())->data; return json_decode($response->getBody())->data;
} }
@ -46,7 +47,7 @@ trait Modules
{ {
$response = $this->getRemote('apps/' . $alias); $response = $this->getRemote('apps/' . $alias);
if ($response->getStatusCode() == 200) { if ($response && ($response->getStatusCode() == 200)) {
return json_decode($response->getBody())->data; return json_decode($response->getBody())->data;
} }
@ -57,7 +58,7 @@ trait Modules
{ {
$response = $this->getRemote('apps/categories'); $response = $this->getRemote('apps/categories');
if ($response->getStatusCode() == 200) { if ($response && ($response->getStatusCode() == 200)) {
return json_decode($response->getBody())->data; return json_decode($response->getBody())->data;
} }
@ -68,7 +69,7 @@ trait Modules
{ {
$response = $this->getRemote('apps/categories/' . $alias); $response = $this->getRemote('apps/categories/' . $alias);
if ($response->getStatusCode() == 200) { if ($response && ($response->getStatusCode() == 200)) {
return json_decode($response->getBody())->data; return json_decode($response->getBody())->data;
} }
@ -79,7 +80,7 @@ trait Modules
{ {
$response = $this->getRemote('apps/paid', 'GET', $data); $response = $this->getRemote('apps/paid', 'GET', $data);
if ($response->getStatusCode() == 200) { if ($response && ($response->getStatusCode() == 200)) {
return json_decode($response->getBody())->data; return json_decode($response->getBody())->data;
} }
@ -90,7 +91,7 @@ trait Modules
{ {
$response = $this->getRemote('apps/new', 'GET', $data); $response = $this->getRemote('apps/new', 'GET', $data);
if ($response->getStatusCode() == 200) { if ($response && ($response->getStatusCode() == 200)) {
return json_decode($response->getBody())->data; return json_decode($response->getBody())->data;
} }
@ -101,7 +102,7 @@ trait Modules
{ {
$response = $this->getRemote('apps/free', 'GET', $data); $response = $this->getRemote('apps/free', 'GET', $data);
if ($response->getStatusCode() == 200) { if ($response && ($response->getStatusCode() == 200)) {
return json_decode($response->getBody())->data; return json_decode($response->getBody())->data;
} }
@ -112,7 +113,7 @@ trait Modules
{ {
$response = $this->getRemote('apps/search', 'GET', $data); $response = $this->getRemote('apps/search', 'GET', $data);
if ($response->getStatusCode() == 200) { if ($response && ($response->getStatusCode() == 200)) {
return json_decode($response->getBody())->data; return json_decode($response->getBody())->data;
} }
@ -125,7 +126,7 @@ trait Modules
$response = $this->getRemote('core/version', 'GET', $data); $response = $this->getRemote('core/version', 'GET', $data);
if ($response->getStatusCode() == 200) { if ($response && ($response->getStatusCode() == 200)) {
return $response->json(); return $response->json();
} }
@ -136,7 +137,7 @@ trait Modules
{ {
$response = $this->getRemote($path); $response = $this->getRemote($path);
if ($response->getStatusCode() == 200) { if ($response && ($response->getStatusCode() == 200)) {
$file = $response->getBody()->getContents(); $file = $response->getBody()->getContents();
$path = 'temp-' . md5(mt_rand()); $path = 'temp-' . md5(mt_rand());
@ -327,7 +328,11 @@ trait Modules
$data = array_merge($data, $headers); $data = array_merge($data, $headers);
$result = $client->request($method, $path, $data); try {
$result = $client->request($method, $path, $data);
} catch (RequestException $e) {
$result = false;
}
return $result; return $result;
} }

View File

@ -3,6 +3,7 @@
namespace App\Traits; namespace App\Traits;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
trait SiteApi trait SiteApi
{ {
@ -23,7 +24,11 @@ trait SiteApi
$data = array_merge($data, $headers); $data = array_merge($data, $headers);
$result = $client->get($url, $data); try {
$result = $client->get($url, $data);
} catch (RequestException $e) {
$result = $e;
}
return $result; return $result;
} }

View File

@ -10,6 +10,7 @@ use Date;
use File; use File;
use Module; use Module;
use ZipArchive; use ZipArchive;
use GuzzleHttp\Exception\RequestException;
class Updater class Updater
{ {
@ -107,6 +108,11 @@ class Updater
$response = static::getRemote($url, ['timeout' => 30, 'track_redirects' => true]); $response = static::getRemote($url, ['timeout' => 30, 'track_redirects' => true]);
// Exception
if ($response instanceof RequestException) {
return false;
}
if ($response->getStatusCode() == 200) { if ($response->getStatusCode() == 200) {
$file = $response->getBody()->getContents(); $file = $response->getBody()->getContents();
} }

View File

@ -6,6 +6,7 @@ use App\Traits\SiteApi;
use Cache; use Cache;
use Date; use Date;
use Parsedown; use Parsedown;
use GuzzleHttp\Exception\RequestException;
class Versions class Versions
{ {
@ -90,7 +91,12 @@ class Versions
{ {
$latest = '0.0.0'; $latest = '0.0.0';
$response = static::getRemote($url, ['timeout' => 30, 'referer' => true]); $response = static::getRemote($url, ['timeout' => 1, 'referer' => true]);
// Exception
if ($response instanceof RequestException) {
return $latest;
}
// Bad response // Bad response
if ($response->getStatusCode() != 200) { if ($response->getStatusCode() != 200) {