mirror of
https://github.com/bs-community/blessing-skin-server.git
synced 2024-12-15 06:09:58 +08:00
add PluginController
This commit is contained in:
parent
94495614c3
commit
55f8c87b92
@ -10,7 +10,6 @@ use App\Models\User;
|
||||
use App\Models\Player;
|
||||
use App\Models\Texture;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Services\PluginManager;
|
||||
use App\Exceptions\PrettyPageException;
|
||||
use App\Services\Repositories\UserRepository;
|
||||
|
||||
@ -80,90 +79,6 @@ class AdminController extends Controller
|
||||
return view('admin.options')->with('forms', compact('general', 'cache'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Upload Checking & Downloading
|
||||
*
|
||||
* @param Request $request
|
||||
* @return void
|
||||
*/
|
||||
public function update(Request $request)
|
||||
{
|
||||
if ($request->action == "check") {
|
||||
$updater = new \Updater(\App::version());
|
||||
|
||||
if ($updater->newVersionAvailable()) {
|
||||
return json([
|
||||
'new_version_available' => true,
|
||||
'latest_version' => $updater->latest_version
|
||||
]);
|
||||
} else {
|
||||
return json([
|
||||
'new_version_available' => false,
|
||||
'latest_version' => $updater->current_version
|
||||
]);
|
||||
}
|
||||
} elseif ($request->action == "download") {
|
||||
return view('admin.download');
|
||||
} else {
|
||||
return view('admin.update');
|
||||
}
|
||||
}
|
||||
|
||||
public function plugins(Request $request, PluginManager $plugins)
|
||||
{
|
||||
if ($request->has('action') && $request->has('id')) {
|
||||
$id = $request->get('id');
|
||||
|
||||
if ($plugins->getPlugins()->has($id)) {
|
||||
$plugin = $plugins->getPlugin($id);
|
||||
switch ($request->get('action')) {
|
||||
case 'enable':
|
||||
$plugins->enable($id);
|
||||
|
||||
return redirect('admin/plugins/manage');
|
||||
break;
|
||||
|
||||
case 'disable':
|
||||
$plugins->disable($id);
|
||||
|
||||
return redirect('admin/plugins/manage');
|
||||
break;
|
||||
|
||||
case 'delete':
|
||||
if ($request->isMethod('post')) {
|
||||
event(new Events\PluginWasDeleted($plugin));
|
||||
|
||||
$plugins->uninstall($id);
|
||||
|
||||
return json('插件已被成功删除', 0);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'config':
|
||||
if ($plugin->isEnabled() && $plugin->hasConfigView()) {
|
||||
return View::file($plugin->getViewPath('config'));
|
||||
} else {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
# code...
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$data = [
|
||||
'installed' => $plugins->getPlugins(),
|
||||
'enabled' => $plugins->getEnabledPlugins()
|
||||
];
|
||||
|
||||
return view('admin.plugins', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show Manage Page of Users.
|
||||
*
|
||||
|
71
app/Http/Controllers/PluginController.php
Normal file
71
app/Http/Controllers/PluginController.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use View;
|
||||
use App\Events;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Services\PluginManager;
|
||||
|
||||
class PluginController extends Controller
|
||||
{
|
||||
public function showMarket()
|
||||
{
|
||||
return "developing";
|
||||
}
|
||||
|
||||
public function manage(Request $request, PluginManager $plugins)
|
||||
{
|
||||
if ($request->has('action') && $request->has('id')) {
|
||||
$id = $request->get('id');
|
||||
|
||||
if ($plugins->getPlugins()->has($id)) {
|
||||
$plugin = $plugins->getPlugin($id);
|
||||
switch ($request->get('action')) {
|
||||
case 'enable':
|
||||
$plugins->enable($id);
|
||||
|
||||
return redirect('admin/plugins/manage');
|
||||
break;
|
||||
|
||||
case 'disable':
|
||||
$plugins->disable($id);
|
||||
|
||||
return redirect('admin/plugins/manage');
|
||||
break;
|
||||
|
||||
case 'delete':
|
||||
if ($request->isMethod('post')) {
|
||||
event(new Events\PluginWasDeleted($plugin));
|
||||
|
||||
$plugins->uninstall($id);
|
||||
|
||||
return json('插件已被成功删除', 0);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'config':
|
||||
if ($plugin->isEnabled() && $plugin->hasConfigView()) {
|
||||
return View::file($plugin->getViewPath('config'));
|
||||
} else {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
# code...
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$data = [
|
||||
'installed' => $plugins->getPlugins(),
|
||||
'enabled' => $plugins->getEnabledPlugins()
|
||||
];
|
||||
|
||||
return view('admin.plugins', $data);
|
||||
}
|
||||
}
|
@ -98,21 +98,24 @@ Route::group(['middleware' => 'admin', 'prefix' => 'admin'], function ()
|
||||
{
|
||||
Route::get('/', 'AdminController@index');
|
||||
|
||||
Route::any('/plugins/manage', 'AdminController@plugins');
|
||||
|
||||
Route::any('/customize', 'AdminController@customize');
|
||||
Route::any('/score', 'AdminController@score');
|
||||
Route::any('/options', 'AdminController@options');
|
||||
|
||||
Route::any('/update', 'UpdateController@showUpdatePage');
|
||||
|
||||
Route::any('/update/download', 'UpdateController@download');
|
||||
|
||||
Route::get('/update/check', 'UpdateController@checkUpdates');
|
||||
|
||||
Route::get('/users', 'AdminController@users');
|
||||
Route::get('/players', 'AdminController@players');
|
||||
// ajax handlers
|
||||
Route::post('/users', 'AdminController@userAjaxHandler');
|
||||
Route::post('/players', 'AdminController@playerAjaxHandler');
|
||||
|
||||
Route::group(['prefix' => 'plugins'], function () {
|
||||
Route::get('/manage', 'PluginController@manage');
|
||||
Route::any('/market', 'PluginController@showMarket');
|
||||
});
|
||||
|
||||
Route::group(['prefix' => 'update'], function () {
|
||||
Route::any('/update', 'UpdateController@showUpdatePage');
|
||||
Route::get('/update/check', 'UpdateController@checkUpdates');
|
||||
Route::any('/update/download', 'UpdateController@download');
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user