mirror of
https://github.com/lsky-org/lsky-pro.git
synced 2025-01-08 11:57:52 +08:00
compatible swoole
This commit is contained in:
parent
b0c6a6defa
commit
37c6ccd29d
@ -17,7 +17,7 @@ use Illuminate\View\View;
|
||||
|
||||
class GroupController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
private function share()
|
||||
{
|
||||
\Illuminate\Support\Facades\View::share([
|
||||
'default' => Group::getDefaultConfigs(),
|
||||
@ -31,17 +31,25 @@ class GroupController extends Controller
|
||||
$groups = Group::query()->when($request->query('keywords'), function (Builder $builder, $keywords) {
|
||||
$builder->where('name', 'like', "%{$keywords}%");
|
||||
})->withCount('users')->withCount('strategies')->latest()->paginate();
|
||||
|
||||
$this->share();
|
||||
|
||||
return view('admin.group.index', compact('groups'));
|
||||
}
|
||||
|
||||
public function add(): View
|
||||
{
|
||||
$this->share();
|
||||
|
||||
return view('admin.group.add');
|
||||
}
|
||||
|
||||
public function edit(Request $request): View
|
||||
{
|
||||
$group = Group::query()->findOrFail($request->route('id'));
|
||||
|
||||
$this->share();
|
||||
|
||||
return view('admin.group.edit', compact('group'));
|
||||
}
|
||||
|
||||
@ -53,6 +61,8 @@ class GroupController extends Controller
|
||||
$group->save();
|
||||
});
|
||||
|
||||
$this->share();
|
||||
|
||||
return $this->success('创建成功');
|
||||
}
|
||||
|
||||
|
@ -15,13 +15,6 @@ use Illuminate\Validation\Rules;
|
||||
|
||||
class RegisteredUserController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
if (! Utils::config(ConfigKey::IsEnableRegistration)) {
|
||||
abort(404);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the registration view.
|
||||
*
|
||||
|
@ -2,20 +2,11 @@
|
||||
|
||||
namespace App\Http\Controllers\Common;
|
||||
|
||||
use App\Enums\ConfigKey;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Utils;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class ApiController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
if (! Utils::config(ConfigKey::IsEnableApi)) {
|
||||
abort(404);
|
||||
}
|
||||
}
|
||||
|
||||
public function index(): View
|
||||
{
|
||||
return view('common.api');
|
||||
|
@ -2,22 +2,13 @@
|
||||
|
||||
namespace App\Http\Controllers\Common;
|
||||
|
||||
use App\Enums\ConfigKey;
|
||||
use App\Enums\ImagePermission;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Image;
|
||||
use App\Utils;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class GalleryController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
if (! Utils::config(ConfigKey::IsEnableGallery)) {
|
||||
abort(404);
|
||||
}
|
||||
}
|
||||
|
||||
public function index(): View
|
||||
{
|
||||
$images = Image::query()
|
||||
|
@ -15,7 +15,10 @@ class CheckIsEnableApi
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
if (! Utils::config(ConfigKey::IsEnableApi)) {
|
||||
return $this->fail('管理员未启用 API')->setStatusCode(403);
|
||||
if ($request->expectsJson()) {
|
||||
return $this->fail('管理员未启用 API')->setStatusCode(403);
|
||||
}
|
||||
abort(404);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
|
26
app/Http/Middleware/CheckIsEnableGallery.php
Normal file
26
app/Http/Middleware/CheckIsEnableGallery.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Enums\ConfigKey;
|
||||
use App\Http\Result;
|
||||
use App\Utils;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CheckIsEnableGallery
|
||||
{
|
||||
use Result;
|
||||
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
if (! Utils::config(ConfigKey::IsEnableGallery)) {
|
||||
if ($request->expectsJson()) {
|
||||
return $this->fail('管理员未启用画廊功能')->setStatusCode(403);
|
||||
}
|
||||
abort(404);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
26
app/Http/Middleware/CheckIsEnableRegistration.php
Normal file
26
app/Http/Middleware/CheckIsEnableRegistration.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Enums\ConfigKey;
|
||||
use App\Http\Result;
|
||||
use App\Utils;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CheckIsEnableRegistration
|
||||
{
|
||||
use Result;
|
||||
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
if (! Utils::config(ConfigKey::IsEnableRegistration)) {
|
||||
if ($request->expectsJson()) {
|
||||
return $this->fail('站点管理员关闭了注册功能')->setStatusCode(403);
|
||||
}
|
||||
abort(404);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
@ -229,10 +229,9 @@ return [
|
||||
*/
|
||||
'swoole' => [
|
||||
'options' => [
|
||||
Constant::OPTION_MAX_REQUEST => 100000,
|
||||
Constant::OPTION_PACKAGE_MAX_LENGTH => 50 * 1024 * 1024,
|
||||
Constant::OPTION_SOCKET_BUFFER_SIZE => 50 * 1024 * 1024,
|
||||
Constant::OPTION_BUFFER_OUTPUT_SIZE => 50 * 1024 * 1024,
|
||||
Constant::OPTION_MAX_REQUEST => env('SWOOLE_MAX_REQUEST', 100000),
|
||||
Constant::OPTION_PACKAGE_MAX_LENGTH => env('SWOOLE_PACKAGE_MAX_LENGTH', 50) * 1024 * 1024,
|
||||
Constant::OPTION_BUFFER_OUTPUT_SIZE => env('SWOOLE_BUFFER_OUTPUT_SIZE', 50) * 1024 * 1024,
|
||||
]
|
||||
]
|
||||
|
||||
|
@ -8,15 +8,16 @@ use App\Http\Controllers\Auth\NewPasswordController;
|
||||
use App\Http\Controllers\Auth\PasswordResetLinkController;
|
||||
use App\Http\Controllers\Auth\RegisteredUserController;
|
||||
use App\Http\Controllers\Auth\VerifyEmailController;
|
||||
use App\Http\Middleware\CheckIsEnableRegistration;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::get('/register', [
|
||||
RegisteredUserController::class, 'create'
|
||||
])->middleware('guest')->name('register');
|
||||
])->middleware('guest')->middleware(CheckIsEnableRegistration::class)->name('register');
|
||||
|
||||
Route::post('/register', [
|
||||
RegisteredUserController::class, 'store'
|
||||
])->middleware('guest');
|
||||
])->middleware('guest')->middleware(CheckIsEnableRegistration::class);
|
||||
|
||||
Route::get('/login', [
|
||||
AuthenticatedSessionController::class, 'create',
|
||||
|
@ -11,6 +11,8 @@
|
||||
|
|
||||
*/
|
||||
|
||||
use App\Http\Middleware\CheckIsEnableApi;
|
||||
use App\Http\Middleware\CheckIsEnableGallery;
|
||||
use App\Http\Middleware\CheckIsEnableGuestUpload;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use App\Http\Middleware\CheckIsInstalled;
|
||||
@ -37,7 +39,7 @@ Route::any('install', [Controller::class, 'install'])->name('install');
|
||||
Route::post('upload', [Controller::class, 'upload']);
|
||||
Route::group(['middleware' => ['auth']], function () {
|
||||
Route::get('dashboard', [UserController::class, 'dashboard'])->name('dashboard');
|
||||
Route::get('gallery', [GalleryController::class, 'index'])->name('gallery');
|
||||
Route::get('gallery', [GalleryController::class, 'index'])->middleware(CheckIsEnableGallery::class)->name('gallery');
|
||||
|
||||
Route::prefix('settings')->group(function () {
|
||||
Route::get('', [UserController::class, 'settings'])->name('settings');
|
||||
@ -45,7 +47,10 @@ Route::group(['middleware' => ['auth']], function () {
|
||||
Route::put('set-strategy', [UserController::class, 'setStrategy'])->name('settings.strategy.set');
|
||||
});
|
||||
|
||||
Route::group(['prefix' => 'api'], function () {
|
||||
Route::group([
|
||||
'prefix' => 'api',
|
||||
'middleware' => CheckIsEnableApi::class
|
||||
], function () {
|
||||
Route::get('', [ApiController::class, 'index'])->name('api');
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user