This commit is contained in:
Kode 2018-10-28 10:59:59 +00:00
parent d1956c4e88
commit 4351f55225
11 changed files with 59 additions and 27 deletions

View file

@ -7,6 +7,6 @@ interface EnhancedApps
{ {
public function test(); public function test();
public function livestats(); public function livestats();
public function apiUrl($endpoint); public function url($endpoint);
} }

View file

@ -335,8 +335,8 @@ class ItemController extends Controller
$item = Item::find($id); $item = Item::find($id);
$config = $item->getconfig(); $config = $item->getconfig();
if(isset($config->type)) { if(isset($item->class)) {
$application = new $config->type; $application = new $item->class;
$application->config = $config; $application->config = $config;
echo $application->livestats(); echo $application->livestats();
} }

View file

@ -159,7 +159,7 @@ class Item extends Model
$config = json_decode($this->description); $config = json_decode($this->description);
$explode = explode('\\', $config->type); $explode = explode('\\', $this->class);
$config->name = end($explode); $config->name = end($explode);

View file

@ -6,33 +6,47 @@ use GuzzleHttp\Client;
abstract class SupportedApps abstract class SupportedApps
{ {
public function appTest($url, $requiresLoginFirst=false) protected $jar = false;
protected $method = 'GET';
public function appTest($url, $attrs = [])
{ {
$res = $this->execute($url, $requiresLoginFirst); $res = $this->execute($url, $attrs);
switch($res->getStatusCode()) { switch($res->getStatusCode()) {
case 200: case 200:
echo 'Successfully connected to the API'; $status = 'Successfully communicated with the API';
break; break;
case 401: case 401:
echo 'Failed: Invalid credentials'; $status = 'Failed: Invalid credentials';
break; break;
case 404: case 404:
echo 'Failed: Please make sure your URL is correct and that there is a trailing slash'; $status = 'Failed: Please make sure your URL is correct and that there is a trailing slash';
break; break;
default: default:
echo 'Something went wrong... Code: '.$res->getStatusCode(); $status = 'Something went wrong... Code: '.$res->getStatusCode();
break; break;
} }
return (object)[
'code' => $res->getStatusCode(),
'status' => $status,
'response' => $res->getBody(),
];
} }
public function execute($url, $requiresLoginFirst=false) public function execute($url, $attrs = [])
{ {
if($requiresLoginFirst) { $vars = [
'http_errors' => false,
'timeout' => 15,
'connect_timeout' => 15,
];
$client = new Client($vars);
try {
return $client->request($this->method, $url, $attrs);
} catch (\GuzzleHttp\Exception\ServerException $e) {
echo (string) $e->getResponse()->getBody();
} }
$client = new Client(['http_errors' => false, 'timeout' => 15, 'connect_timeout' => 15]);
return $client->request('GET', $url);
} }
public function login() public function login()
@ -61,14 +75,14 @@ abstract class SupportedApps
{ {
$list_url = 'https://apps.heimdall.site/list'; $list_url = 'https://apps.heimdall.site/list';
$client = new Client(['http_errors' => false, 'timeout' => 15, 'connect_timeout' => 15]); $client = new Client(['http_errors' => false, 'timeout' => 15, 'connect_timeout' => 15]);
return $client->request('GET', $list_url); return $client->request($this->method, $list_url);
} }
public static function getFiles($app) public static function getFiles($app)
{ {
$zipurl = $app->files; $zipurl = $app->files;
$client = new Client(['http_errors' => false, 'timeout' => 60, 'connect_timeout' => 15]); $client = new Client(['http_errors' => false, 'timeout' => 60, 'connect_timeout' => 15]);
$res = $client->request('GET', $zipurl); $res = $client->request($this->method, $zipurl);
if(!file_exists(app_path('SupportedApps'))) { if(!file_exists(app_path('SupportedApps'))) {
mkdir(app_path('SupportedApps'), 0777, true); mkdir(app_path('SupportedApps'), 0777, true);

15
public/css/app.css vendored
View file

@ -1252,7 +1252,7 @@ hr {
} }
.livestats-container .livestats { .livestats-container .livestats {
margin: 5px 0px -5px; margin: 5px 0px 0px;
padding: 0; padding: 0;
display: -webkit-box; display: -webkit-box;
display: -ms-flexbox; display: -ms-flexbox;
@ -1277,11 +1277,24 @@ hr {
font-weight: 500; font-weight: 500;
opacity: 0.5; opacity: 0.5;
line-height: 1; line-height: 1;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
} }
.livestats-container .livestats strong { .livestats-container .livestats strong {
display: block; display: block;
line-height: 1; line-height: 1;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}
.livestats-container .livestats strong span {
margin-left: 4px;
} }
input:-webkit-autofill, input:-webkit-autofill,

2
public/js/app.js vendored
View file

@ -135,7 +135,7 @@ $.when( $.ready ).then(function() {
var data = {}; var data = {};
data['url'] = apiurl; data['url'] = apiurl;
$('input.config-item').each(function(index){ $('.config-item').each(function(index){
var config = $(this).data('config'); var config = $(this).data('config');
data[config] = $(this).val(); data[config] = $(this).val();
}); });

View file

@ -1,4 +1,4 @@
{ {
"/css/app.css": "/css/app.css?id=d501edaf8c9cc02c173d", "/css/app.css": "/css/app.css?id=22a39cc94a111a82ce68",
"/js/app.js": "/js/app.js?id=32cbf6f4924b46ae7e05" "/js/app.js": "/js/app.js?id=8dc4a6ea723d0df7469d"
} }

View file

@ -126,7 +126,7 @@ $.when( $.ready ).then(function() {
var data = {}; var data = {};
data['url'] = apiurl; data['url'] = apiurl;
$('input.config-item').each(function(index){ $('.config-item').each(function(index){
var config = $(this).data('config'); var config = $(this).data('config');
data[config] = $(this).val(); data[config] = $(this).val();
}); });

View file

@ -852,7 +852,7 @@ hr {
.livestats-container { .livestats-container {
.livestats { .livestats {
margin: 5px 0px -5px; margin: 5px 0px 0px;
padding: 0; padding: 0;
display: flex; display: flex;
list-style: none; list-style: none;
@ -871,10 +871,16 @@ hr {
font-weight: 500; font-weight: 500;
opacity: 0.5; opacity: 0.5;
line-height: 1; line-height: 1;
display: flex;
} }
strong { strong {
display: block; display: block;
line-height: 1; line-height: 1;
display: flex;
align-items: center;
span {
margin-left: 4px;
}
} }
} }

View file

@ -22,14 +22,13 @@
</header> </header>
<div id="create" class="create"> <div id="create" class="create">
{!! csrf_field() !!} {!! csrf_field() !!}
{!! Form::hidden('class', '') !!}
<div class="input"> <div class="input">
<label>{{ __('app.apps.application_name') }} *</label> <label>{{ __('app.apps.application_name') }} *</label>
{!! Form::text('title', null, array('placeholder' => __('app.apps.title'), 'id' => 'appname', 'class' => 'form-control')) !!} {!! Form::text('title', null, array('placeholder' => __('app.apps.title'), 'id' => 'appname', 'class' => 'form-control')) !!}
</div> </div>
<div class="input"> <div class="input">
<label>{{ __('app.apps.apptype') }} *</label> <label>{{ __('app.apps.apptype') }} *</label>
{!! Form::select('class', App\Application::applist(), null, array('class' => 'form-control')) !!} {!! Form::select('class', App\Application::applist(), null, array('class' => 'form-control config-item', 'data-config' => 'type')) !!}
</div> </div>
<div class="input"> <div class="input">

View file

@ -11,7 +11,7 @@
<div class="details"> <div class="details">
<div class="title{{ title_color($item->colour) ?? 'white' }}">{{ $item->title ?? '' }}</div> <div class="title{{ title_color($item->colour) ?? 'white' }}">{{ $item->title ?? '' }}</div>
@if($item->enhanced()) @if($item->enhanced())
<div data-id="{{ $item->id }}" data-dataonly="{{ $item->getconfig()->dataonly ?? '0' }}" class="livestats-container"></div> <div data-id="{{ $item->id }}" data-dataonly="{{ $item->getconfig()->dataonly ?? '0' }}" class="no-livestats-container"></div>
@endif @endif
</div> </div>
<a class="link{{ title_color($item->colour) }}"{!! $item->link_target !!} href="{{ $item->link }}"><i class="fas {{ $item->link_icon }}"></i></a> <a class="link{{ title_color($item->colour) }}"{!! $item->link_target !!} href="{{ $item->link }}"><i class="fas {{ $item->link_icon }}"></i></a>