More work on apps
This commit is contained in:
parent
bdeae6a722
commit
8499d100ff
7 changed files with 121 additions and 64 deletions
|
@ -66,10 +66,38 @@ class Application extends Model
|
|||
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)
|
||||
{
|
||||
$apps = self::apps();
|
||||
$app = $apps->where('appid', $appid)->first();
|
||||
if ($app === null) return null;
|
||||
$classname = preg_replace('/[^\p{L}\p{N}]/u', '', $app->name);
|
||||
$app->class = '\App\SupportedApps\\'.$classname.'\\'.$classname;
|
||||
return $app;
|
||||
|
|
|
@ -145,15 +145,9 @@ class ItemController extends Controller
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
public function storelogic($request, $id = null)
|
||||
{
|
||||
//
|
||||
$application = Application::single($request->input('appid'));
|
||||
$validatedData = $request->validate([
|
||||
'title' => 'required|max:255',
|
||||
'url' => 'required',
|
||||
|
@ -164,6 +158,14 @@ class ItemController extends Controller
|
|||
$request->merge([
|
||||
'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'));
|
||||
|
@ -180,14 +182,28 @@ class ItemController extends Controller
|
|||
}
|
||||
|
||||
|
||||
//die(print_r($request->input('config')));
|
||||
|
||||
$item = Item::create($request->all());
|
||||
if($id === null) {
|
||||
$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);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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', []);
|
||||
return redirect($route)
|
||||
->with('success', __('app.alert.success.item_created'));
|
||||
|
@ -232,39 +248,7 @@ class ItemController extends Controller
|
|||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$validatedData = $request->validate([
|
||||
'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);
|
||||
|
||||
$this->storelogic($request, $id);
|
||||
$route = route('dash', []);
|
||||
return redirect($route)
|
||||
->with('success',__('app.alert.success.item_updated'));
|
||||
|
@ -320,6 +304,8 @@ class ItemController extends Controller
|
|||
{
|
||||
$output = [];
|
||||
$appid = $request->input('app');
|
||||
|
||||
if($appid === "null") return null;
|
||||
/*$appname = $request->input('app');
|
||||
//die($appname);
|
||||
|
||||
|
@ -340,9 +326,20 @@ class ItemController extends Controller
|
|||
} else {
|
||||
$output['config'] = null;
|
||||
}*/
|
||||
|
||||
$output['config'] = null;
|
||||
$output['custom'] = null;
|
||||
|
||||
$app = Application::single($appid);
|
||||
$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['iconview'] = 'https://raw.githubusercontent.com/linuxserver/Heimdall-Apps/master/' . preg_replace('/[^\p{L}\p{N}]/u', '', $app->name) . '/' . $app->icon;
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ class Item extends Model
|
|||
|
||||
//
|
||||
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)
|
||||
{
|
||||
// die(print_r($config));
|
||||
if(empty($config)) {
|
||||
$config = null;
|
||||
} else {
|
||||
|
|
|
@ -122,7 +122,11 @@ abstract class SupportedApps
|
|||
|
||||
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]);
|
||||
$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->close();
|
||||
unlink($src); //Deleting the Zipped file
|
||||
} else {
|
||||
var_dump($x);
|
||||
}
|
||||
}
|
||||
|
||||
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->name = $details->name;
|
||||
$app->sha = $details->sha ?? null;
|
||||
|
@ -168,6 +165,7 @@ abstract class SupportedApps
|
|||
$app->enhanced = $enhanced;
|
||||
$app->tile_background = $details->tile_background;
|
||||
$app->save();
|
||||
return $app;
|
||||
}
|
||||
|
||||
}
|
32
database/migrations/2022_03_15_140911_add_appid_to_items.php
Normal file
32
database/migrations/2022_03_15_140911_add_appid_to_items.php
Normal 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']);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -27,7 +27,7 @@
|
|||
</div>
|
||||
<div class="input">
|
||||
<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 class="input">
|
||||
|
|
|
@ -49,23 +49,24 @@
|
|||
$('.tags').select2();
|
||||
|
||||
function appload(appvalue) {
|
||||
if(appvalue == 'None') {
|
||||
if(appvalue == 'null') {
|
||||
$('#sapconfig').html('').hide();
|
||||
$('#tile-preview .app-icon').attr('src', '/img/heimdall-icon-small.png');
|
||||
$('#appimage').html("<img src='/img/heimdall-icon-small.png' />");
|
||||
$('#sapconfig').html('').hide();
|
||||
} else {
|
||||
$.post('{{ route('appload') }}', { app: appvalue }, function(data) {
|
||||
// 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);
|
||||
$('select[name=class]').val(data.appid);
|
||||
$('select[name=appid]').val(data.appid);
|
||||
hueb.setColor( data.colour );
|
||||
$('input[name=pinned]').prop('checked', true);
|
||||
// Preview details
|
||||
$('#tile-preview .app-icon').attr('src', data.iconview);
|
||||
$('#tile-preview .title').html(data.name);
|
||||
if(data.config != null) {
|
||||
$.get(base+'view/'+data.config, function(getdata) {
|
||||
if(data.custom != null) {
|
||||
$.get(base+'view/'+data.custom, function(getdata) {
|
||||
$('#sapconfig').html(getdata).show();
|
||||
});
|
||||
} else {
|
||||
|
|
Loading…
Add table
Reference in a new issue