From 6e9f25d680125a4180e3bb93e86ddf67a499bd58 Mon Sep 17 00:00:00 2001 From: Kode Date: Sun, 21 Oct 2018 12:39:12 +0100 Subject: [PATCH] Fixes --- app/Application.php | 9 +++++- app/EnhancedApps.php | 2 +- app/Http/Controllers/ItemController.php | 24 ++++++++------- app/Item.php | 40 ++++++++++++++----------- app/SupportedApps.php | 29 +++++++++++++++--- resources/views/item.blade.php | 4 +-- resources/views/items/scripts.blade.php | 2 +- 7 files changed, 72 insertions(+), 38 deletions(-) diff --git a/app/Application.php b/app/Application.php index e60e8bfe..757e8a15 100644 --- a/app/Application.php +++ b/app/Application.php @@ -9,7 +9,12 @@ class Application extends Model // public function icon() { - return asset($this->icon); + return $this->icon; + } + + public function iconView() + { + return asset('storage/'.$this->icon); } public function defaultColour() @@ -24,4 +29,6 @@ class Application extends Model $class = '\App\SupportedApps\\'.$this->name.'\\'.$this->name; return $class; } + + } diff --git a/app/EnhancedApps.php b/app/EnhancedApps.php index 4cc7b89a..5eee0a3d 100644 --- a/app/EnhancedApps.php +++ b/app/EnhancedApps.php @@ -5,6 +5,6 @@ use GuzzleHttp\Client; interface EnhancedApps { - + public function livestats(); } \ No newline at end of file diff --git a/app/Http/Controllers/ItemController.php b/app/Http/Controllers/ItemController.php index 14e99368..84da8a74 100644 --- a/app/Http/Controllers/ItemController.php +++ b/app/Http/Controllers/ItemController.php @@ -291,6 +291,7 @@ class ItemController extends Controller // basic details $output['icon'] = $app_details->icon(); + $output['iconview'] = $app_details->iconView(); $output['colour'] = $app_details->defaultColour(); // live details @@ -319,15 +320,11 @@ class ItemController extends Controller { $item = Item::find($id); - $config = json_decode($item->description); + $config = $item->config(); if(isset($config->type)) { - $config->url = $item->url; - if(isset($config->override_url) && !empty($config->override_url)) { - $config->url = $config->override_url; - } - $app_details = new $config->type; - $app_details->config = $config; - echo $app_details->executeConfig(); + $application = new $config->type; + $application->config = $config; + echo $application->livestats(); } } @@ -345,9 +342,14 @@ class ItemController extends Controller } else { // check if there has been an update for this app $localapp = $localapps->where('name', $app->name)->first(); - if($localapp->sha !== $app->sha) { - SupportedApps::getFiles($app); - SupportedApps::saveApp($app, $localapp); + if($localapp) { + if($localapp->sha !== $app->sha) { + SupportedApps::getFiles($app); + SupportedApps::saveApp($app, $localapp); + } + } else { // local folder, add to database + $application = new Application; + SupportedApps::saveApp($app, $application); } } } diff --git a/app/Item.php b/app/Item.php index 5bc172c8..286804bf 100644 --- a/app/Item.php +++ b/app/Item.php @@ -45,24 +45,6 @@ class Item extends Model return $query->where('pinned', 1); } - public function getConfigAttribute() - { - $output = null; - $view = null; - if(isset($this->description) && !empty($this->description)){ - $output = json_decode($this->description); - $output = is_object($output) ? $output : new \stdClass(); - if(isset($output->type) && !empty($output->type)) { - $class = $output->type; - $sap = new $class(); - $view = $sap->configDetails(); - $output->view = $view; - } - if(!isset($output->dataonly)) $output->dataonly = '0'; - - } - return (object)$output; - } public static function checkConfig($config) { if(empty($config)) { @@ -156,6 +138,28 @@ class Item extends Model return $query->where('type', $typeid); } + public function enhanced() + { + $details = $this->config(); + $class = $details->type; + $app = new $class; + return (bool)($app instanceof \App\EnhancedApps); + } + + public function config() + { + $config = json_decode($this->description); + + $config->url = $this->url; + if(isset($config->override_url) && !empty($config->override_url)) { + $config->url = $config->override_url; + } + + return $config; + } + + + /** * Get the user that owns the item. */ diff --git a/app/SupportedApps.php b/app/SupportedApps.php index 335c10c8..338868bd 100644 --- a/app/SupportedApps.php +++ b/app/SupportedApps.php @@ -5,7 +5,6 @@ use GuzzleHttp\Client; abstract class SupportedApps { - public $config; public function test($url, $requiresLoginFirst=false) { @@ -14,7 +13,12 @@ abstract class SupportedApps public function execute($url, $requiresLoginFirst=false) { - + if($requiresLoginFirst) { + + } + + $client = new Client(['http_errors' => false, 'timeout' => 15, 'connect_timeout' => 15]); + return $client->request('GET', $url); } public function login() @@ -27,6 +31,18 @@ abstract class SupportedApps } + + public function getLiveStats($status, $data) + { + $className = get_class($this); + $explode = explode('\\', $className); + $name = end($explode); + + $html = view('SupportedApps::'.$name.'.livestats', $data)->with('data', $data)->render(); + return json_encode(['status' => $status, 'html' => $html]); + //return + } + public static function getList() { $list_url = 'https://apps.heimdall.site/list'; @@ -60,11 +76,16 @@ abstract class SupportedApps $app->name = $details->name; $app->sha = $details->sha; - $app->icon = 'storage/supportedapps/'.$details->icon; + $app->icon = 'supportedapps/'.$details->icon; $app->website = $details->website; $app->license = $details->license; $app->description = $details->description; - $app->enhanced = $details->enhanced; + + $appclass = $app->class(); + $application = new $appclass; + $enhanced = (bool)($application instanceof \App\EnhancedApps); + + $app->enhanced = $enhanced; $app->tile_background = $details->tile_background; $app->save(); } diff --git a/resources/views/item.blade.php b/resources/views/item.blade.php index d7a1a1ff..bb8b15cf 100644 --- a/resources/views/item.blade.php +++ b/resources/views/item.blade.php @@ -7,8 +7,8 @@ @endif
{{ $app->title }}
- @if(isset($app->config->enabled) && ((bool)$app->config->enabled === true)) -
+ @if($app->enhanced()) +
@endif
link_target !!} href="{{ $app->link }}"> diff --git a/resources/views/items/scripts.blade.php b/resources/views/items/scripts.blade.php index 751f98a8..7a895711 100644 --- a/resources/views/items/scripts.blade.php +++ b/resources/views/items/scripts.blade.php @@ -13,7 +13,7 @@ source: availableTags, select: function( event, ui ) { $.post('/appload', { app: ui.item.value }, function(data) { - $('#appimage').html(""); + $('#appimage').html(""); $('input[name=colour]').val(data.colour); hueb.setColor( data.colour ); $('input[name=pinned]').prop('checked', true);