More work on apps

This commit is contained in:
KodeStar 2022-03-15 18:19:01 +00:00
parent bdeae6a722
commit 8499d100ff
7 changed files with 121 additions and 64 deletions

View file

@ -66,10 +66,38 @@ class Application extends Model
return $list; return $list;
} }
public static function getApp($appid)
{
$localapp = Application::where('appid', $appid)->first();
$app = self::single($appid);
$application = ($localapp) ? $localapp : new Application;
if(!file_exists(app_path('SupportedApps/'.className($app->name)))) {
SupportedApps::getFiles($app);
SupportedApps::saveApp($app, $application);
} else {
// check if there has been an update for this app
if($localapp) {
if($localapp->sha !== $app->sha) {
SupportedApps::getFiles($app);
$app = SupportedApps::saveApp($app, $application);
}
} else {
SupportedApps::getFiles($app);
$app = SupportedApps::saveApp($app, $application);
}
}
return $app;
}
public static function single($appid) public static function single($appid)
{ {
$apps = self::apps(); $apps = self::apps();
$app = $apps->where('appid', $appid)->first(); $app = $apps->where('appid', $appid)->first();
if ($app === null) return null;
$classname = preg_replace('/[^\p{L}\p{N}]/u', '', $app->name); $classname = preg_replace('/[^\p{L}\p{N}]/u', '', $app->name);
$app->class = '\App\SupportedApps\\'.$classname.'\\'.$classname; $app->class = '\App\SupportedApps\\'.$classname.'\\'.$classname;
return $app; return $app;

View file

@ -145,15 +145,9 @@ class ItemController extends Controller
} }
/** public function storelogic($request, $id = null)
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{ {
// $application = Application::single($request->input('appid'));
$validatedData = $request->validate([ $validatedData = $request->validate([
'title' => 'required|max:255', 'title' => 'required|max:255',
'url' => 'required', 'url' => 'required',
@ -164,6 +158,14 @@ class ItemController extends Controller
$request->merge([ $request->merge([
'icon' => $path 'icon' => $path
]); ]);
} elseif(strpos($request->input('icon'), 'http') === 0) {
$icon = $application->icon;
$contents = file_get_contents($request->input('icon'));
$path = 'icons/'.$icon;
Storage::disk('public')->put($path, $contents);
$request->merge([
'icon' => $path
]);
} }
$config = Item::checkConfig($request->input('config')); $config = Item::checkConfig($request->input('config'));
@ -180,14 +182,28 @@ class ItemController extends Controller
} }
//die(print_r($request->input('config'))); if($id === null) {
$item = Item::create($request->all());
$item = Item::create($request->all()); } else {
$item = Item::find($id);
$item->update($request->all());
}
//Search::storeSearchProvider($request->input('class'), $item);
$item->parents()->sync($request->tags); $item->parents()->sync($request->tags);
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$this->storelogic($request);
$route = route('dash', []); $route = route('dash', []);
return redirect($route) return redirect($route)
->with('success', __('app.alert.success.item_created')); ->with('success', __('app.alert.success.item_created'));
@ -232,39 +248,7 @@ class ItemController extends Controller
*/ */
public function update(Request $request, $id) public function update(Request $request, $id)
{ {
$validatedData = $request->validate([ $this->storelogic($request, $id);
'title' => 'required|max:255',
'url' => 'required',
]);
//die(print_r($request->all()));
if($request->hasFile('file')) {
$path = $request->file('file')->store('icons');
$request->merge([
'icon' => $path
]);
}
$config = Item::checkConfig($request->input('config'));
$current_user = User::currentUser();
$request->merge([
'description' => $config,
'user_id' => $current_user->id
]);
if($request->input('class') === 'null') {
$request->merge([
'class' => null,
]);
}
$item = Item::find($id);
$item->update($request->all());
//Search::storeSearchProvider($request->input('class'), $item);
$item->parents()->sync($request->tags);
$route = route('dash', []); $route = route('dash', []);
return redirect($route) return redirect($route)
->with('success',__('app.alert.success.item_updated')); ->with('success',__('app.alert.success.item_updated'));
@ -320,6 +304,8 @@ class ItemController extends Controller
{ {
$output = []; $output = [];
$appid = $request->input('app'); $appid = $request->input('app');
if($appid === "null") return null;
/*$appname = $request->input('app'); /*$appname = $request->input('app');
//die($appname); //die($appname);
@ -340,9 +326,20 @@ class ItemController extends Controller
} else { } else {
$output['config'] = null; $output['config'] = null;
}*/ }*/
$output['config'] = null;
$output['custom'] = null;
$app = Application::single($appid); $app = Application::single($appid);
$output = (array)$app; $output = (array)$app;
$output['config'] = null;
if((boolean)$app->enhanced === true) {
if(!isset($app->config)) { // class based config
$appdetails = Application::getApp($appid);
$output['custom'] = className($appdetails->name).'.config';
}
}
$output['colour'] = ($app->tile_background == 'light') ? '#fafbfc' : '#161b1f'; $output['colour'] = ($app->tile_background == 'light') ? '#fafbfc' : '#161b1f';
$output['iconview'] = 'https://raw.githubusercontent.com/linuxserver/Heimdall-Apps/master/' . preg_replace('/[^\p{L}\p{N}]/u', '', $app->name) . '/' . $app->icon; $output['iconview'] = 'https://raw.githubusercontent.com/linuxserver/Heimdall-Apps/master/' . preg_replace('/[^\p{L}\p{N}]/u', '', $app->name) . '/' . $app->icon;

View file

@ -30,7 +30,7 @@ class Item extends Model
// //
protected $fillable = [ protected $fillable = [
'title', 'url', 'colour', 'icon', 'description', 'pinned', 'order', 'type', 'class', 'user_id' 'title', 'url', 'colour', 'icon', 'description', 'pinned', 'order', 'type', 'class', 'user_id', 'appid'
]; ];
/** /**
@ -53,6 +53,7 @@ class Item extends Model
public static function checkConfig($config) public static function checkConfig($config)
{ {
// die(print_r($config));
if(empty($config)) { if(empty($config)) {
$config = null; $config = null;
} else { } else {

View file

@ -122,7 +122,11 @@ abstract class SupportedApps
public static function getFiles($app) public static function getFiles($app)
{ {
$zipurl = $app->files; $apps = json_decode(file_get_contents('https://apps.heimdall.site/list'));
$collect = collect($apps->apps);
$collapp = $collect->where('appid', $app->appid)->first();
$zipurl = $collapp->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('GET', $zipurl);
@ -139,20 +143,13 @@ abstract class SupportedApps
$zip->extractTo(app_path('SupportedApps')); // place in the directory with same name $zip->extractTo(app_path('SupportedApps')); // place in the directory with same name
$zip->close(); $zip->close();
unlink($src); //Deleting the Zipped file unlink($src); //Deleting the Zipped file
} else {
var_dump($x);
} }
} }
public static function saveApp($details, $app) public static function saveApp($details, $app)
{ {
if(!file_exists(storage_path('app/public/icons'))) {
mkdir(storage_path('app/public/icons'), 0777, true);
}
$img_src = app_path('SupportedApps/'.className($details->name).'/'.$details->icon);
$img_dest = storage_path('app/public/icons/'.$details->icon);
//die("i: ".$img_src);
@copy($img_src, $img_dest);
$app->appid = $details->appid; $app->appid = $details->appid;
$app->name = $details->name; $app->name = $details->name;
$app->sha = $details->sha ?? null; $app->sha = $details->sha ?? null;
@ -168,6 +165,7 @@ abstract class SupportedApps
$app->enhanced = $enhanced; $app->enhanced = $enhanced;
$app->tile_background = $details->tile_background; $app->tile_background = $details->tile_background;
$app->save(); $app->save();
return $app;
} }
} }

View file

@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddAppidToItems extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('items', function (Blueprint $table) {
$table->string('appid')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('items', function (Blueprint $table) {
$table->dropColumn(['appid']);
});
}
}

View file

@ -27,7 +27,7 @@
</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 config-item', 'id' => 'apptype', 'data-config' => 'type')) !!} {!! Form::select('appid', App\Application::applist(), null, array('class' => 'form-control config-item', 'id' => 'apptype', 'data-config' => 'type')) !!}
</div> </div>
<div class="input"> <div class="input">

View file

@ -49,23 +49,24 @@
$('.tags').select2(); $('.tags').select2();
function appload(appvalue) { function appload(appvalue) {
if(appvalue == 'None') { if(appvalue == 'null') {
$('#sapconfig').html('').hide(); $('#sapconfig').html('').hide();
$('#tile-preview .app-icon').attr('src', '/img/heimdall-icon-small.png'); $('#tile-preview .app-icon').attr('src', '/img/heimdall-icon-small.png');
$('#appimage').html("<img src='/img/heimdall-icon-small.png' />"); $('#appimage').html("<img src='/img/heimdall-icon-small.png' />");
$('#sapconfig').html('').hide();
} else { } else {
$.post('{{ route('appload') }}', { app: appvalue }, function(data) { $.post('{{ route('appload') }}', { app: appvalue }, function(data) {
// Main details // Main details
$('#appimage').html("<img src='"+data.iconview+"' /><input type='hidden' name='icon' value='"+data.icon+"' />"); $('#appimage').html("<img src='"+data.iconview+"' /><input type='hidden' name='icon' value='"+data.iconview+"' />");
$('input[name=colour]').val(data.colour); $('input[name=colour]').val(data.colour);
$('select[name=class]').val(data.appid); $('select[name=appid]').val(data.appid);
hueb.setColor( data.colour ); hueb.setColor( data.colour );
$('input[name=pinned]').prop('checked', true); $('input[name=pinned]').prop('checked', true);
// Preview details // Preview details
$('#tile-preview .app-icon').attr('src', data.iconview); $('#tile-preview .app-icon').attr('src', data.iconview);
$('#tile-preview .title').html(data.name); $('#tile-preview .title').html(data.name);
if(data.config != null) { if(data.custom != null) {
$.get(base+'view/'+data.config, function(getdata) { $.get(base+'view/'+data.custom, function(getdata) {
$('#sapconfig').html(getdata).show(); $('#sapconfig').html(getdata).show();
}); });
} else { } else {