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

View File

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

View File

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

View File

@ -6,6 +6,7 @@ use App\Traits\SiteApi;
use Cache;
use Date;
use Parsedown;
use GuzzleHttp\Exception\RequestException;
class Versions
{
@ -90,7 +91,12 @@ class Versions
{
$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
if ($response->getStatusCode() != 200) {