From 0e996b579d57efbb9ec8121f5429730ef377e3a7 Mon Sep 17 00:00:00 2001 From: Wisp X Date: Mon, 14 Feb 2022 14:04:19 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E5=AE=8C=E5=96=84=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Enums/ConfigKey.php | 3 +++ .../Auth/RegisteredUserController.php | 9 ++++++++ app/Http/Controllers/Common/ApiController.php | 23 +++++++++++++++++++ .../Controllers/Common/GalleryController.php | 9 ++++++++ app/Models/User.php | 4 ++++ app/Providers/AppServiceProvider.php | 2 ++ app/Services/ImageService.php | 1 - app/Utils.php | 1 + config/convention.php | 1 + public/css/app.css | 12 +++++----- resources/views/admin/setting/index.blade.php | 4 ++++ resources/views/common/api.blade.php | 11 +++++++++ .../components/application-logo.blade.php | 2 +- resources/views/layouts/app.blade.php | 6 ++--- resources/views/layouts/guest.blade.php | 6 ++--- resources/views/layouts/header.blade.php | 2 +- resources/views/layouts/sidebar.blade.php | 10 ++++++-- resources/views/welcome.blade.php | 4 +++- routes/web.php | 5 ++++ 19 files changed, 97 insertions(+), 18 deletions(-) create mode 100644 app/Http/Controllers/Common/ApiController.php create mode 100644 resources/views/common/api.blade.php diff --git a/app/Enums/ConfigKey.php b/app/Enums/ConfigKey.php index c4db87fb..f43cef54 100644 --- a/app/Enums/ConfigKey.php +++ b/app/Enums/ConfigKey.php @@ -10,6 +10,9 @@ final class ConfigKey /** @var string 是否启用画廊 */ const IsEnableGallery = 'is_enable_gallery'; + /** @var string 是否启用接口 */ + const IsEnableApi = 'is_enable_api'; + /** @var string 站点名称 */ const SiteName = 'site_name'; diff --git a/app/Http/Controllers/Auth/RegisteredUserController.php b/app/Http/Controllers/Auth/RegisteredUserController.php index 487fedb8..44e78bcc 100644 --- a/app/Http/Controllers/Auth/RegisteredUserController.php +++ b/app/Http/Controllers/Auth/RegisteredUserController.php @@ -2,9 +2,11 @@ namespace App\Http\Controllers\Auth; +use App\Enums\ConfigKey; use App\Http\Controllers\Controller; use App\Models\User; use App\Providers\RouteServiceProvider; +use App\Utils; use Illuminate\Auth\Events\Registered; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; @@ -13,6 +15,13 @@ use Illuminate\Validation\Rules; class RegisteredUserController extends Controller { + public function __construct() + { + if (! Utils::config(ConfigKey::IsEnableRegistration)) { + abort(404); + } + } + /** * Display the registration view. * diff --git a/app/Http/Controllers/Common/ApiController.php b/app/Http/Controllers/Common/ApiController.php new file mode 100644 index 00000000..c801ac27 --- /dev/null +++ b/app/Http/Controllers/Common/ApiController.php @@ -0,0 +1,23 @@ +capacity = Utils::config(ConfigKey::UserInitialCapacity); + $user->configs = collect([ UserConfigKey::DefaultAlbum => 0, UserConfigKey::DefaultStrategy => 0, diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 750ee0ef..a0cffde3 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -30,6 +30,8 @@ class AppServiceProvider extends ServiceProvider public function boot() { // 覆盖默认配置 + Config::set('app.name', Utils::config(ConfigKey::SiteName)); + Config::set('app.url', request()->getSchemeAndHttpHost()); Config::set('mail', array_merge(\config('mail'), Utils::config(ConfigKey::Mail)->toArray())); // 初始化视图中的默认数据 diff --git a/app/Services/ImageService.php b/app/Services/ImageService.php index 3d15bece..379a7b41 100644 --- a/app/Services/ImageService.php +++ b/app/Services/ImageService.php @@ -13,7 +13,6 @@ use App\Enums\UserStatus; use App\Enums\Watermark\FontOption; use App\Enums\Watermark\ImageOption; use App\Exceptions\UploadException; -use App\Models\Group; use App\Models\Image; use App\Models\Strategy; use App\Models\User; diff --git a/app/Utils.php b/app/Utils.php index 11bddf8b..26ebbb28 100644 --- a/app/Utils.php +++ b/app/Utils.php @@ -49,6 +49,7 @@ class Utils switch ($key) { case ConfigKey::IsAllowGuestUpload: case ConfigKey::IsEnableGallery: + case ConfigKey::IsEnableApi: case ConfigKey::IsEnableRegistration: case ConfigKey::IsUserNeedVerify: $value = (bool) $value; diff --git a/config/convention.php b/config/convention.php index bb2315df..745ae3a9 100644 --- a/config/convention.php +++ b/config/convention.php @@ -17,6 +17,7 @@ return [ ConfigKey::IcpNo => '', ConfigKey::IsEnableRegistration => 1, ConfigKey::IsEnableGallery => 1, + ConfigKey::IsEnableApi => 1, ConfigKey::IsAllowGuestUpload => 1, ConfigKey::UserInitialCapacity => 512000, ConfigKey::IsUserNeedVerify => 1, diff --git a/public/css/app.css b/public/css/app.css index 91530a6d..09e64ac5 100644 --- a/public/css/app.css +++ b/public/css/app.css @@ -859,6 +859,9 @@ select { .h-80 { height: 20rem; } +.h-20 { + height: 5rem; +} .h-screen { height: 100vh; } @@ -874,9 +877,6 @@ select { .h-16 { height: 4rem; } -.h-20 { - height: 5rem; -} .h-7 { height: 1.75rem; } @@ -913,6 +913,9 @@ select { .w-6 { width: 1.5rem; } +.w-20 { + width: 5rem; +} .w-3\/4 { width: 75%; } @@ -928,9 +931,6 @@ select { .w-\[90\%\] { width: 90%; } -.w-20 { - width: 5rem; -} .w-4 { width: 1rem; } diff --git a/resources/views/admin/setting/index.blade.php b/resources/views/admin/setting/index.blade.php index 32efe4cb..7640faba 100644 --- a/resources/views/admin/setting/index.blade.php +++ b/resources/views/admin/setting/index.blade.php @@ -40,6 +40,10 @@ + + + + diff --git a/resources/views/common/api.blade.php b/resources/views/common/api.blade.php new file mode 100644 index 00000000..3be2ee5d --- /dev/null +++ b/resources/views/common/api.blade.php @@ -0,0 +1,11 @@ +@section('title', '接口') + + +
+ api +
+ + @push('scripts') + + @endpush +
diff --git a/resources/views/components/application-logo.blade.php b/resources/views/components/application-logo.blade.php index 6743476e..f8a4e605 100644 --- a/resources/views/components/application-logo.blade.php +++ b/resources/views/components/application-logo.blade.php @@ -1 +1 @@ -Lsky Pro +{{ \App\Utils::config(\App\Enums\ConfigKey::SiteName) }} diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index d836e2db..e915ff0a 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -4,10 +4,10 @@ - - + + - {{ config('app.name', 'Laravel') }} + {{ \App\Utils::config(\App\Enums\ConfigKey::SiteName) }} diff --git a/resources/views/layouts/guest.blade.php b/resources/views/layouts/guest.blade.php index 9a8f9cf7..b434dc10 100644 --- a/resources/views/layouts/guest.blade.php +++ b/resources/views/layouts/guest.blade.php @@ -4,10 +4,10 @@ - - + + - {{ config('app.name', 'Laravel') }} + {{ \App\Utils::config(\App\Enums\ConfigKey::SiteName) }} diff --git a/resources/views/layouts/header.blade.php b/resources/views/layouts/header.blade.php index d9bd16dc..231535a6 100644 --- a/resources/views/layouts/header.blade.php +++ b/resources/views/layouts/header.blade.php @@ -4,7 +4,7 @@ - @yield('title', 'Lsky Pro') + @yield('title', \App\Utils::config(\App\Enums\ConfigKey::SiteName))
@include('layouts.user-nav') diff --git a/resources/views/layouts/sidebar.blade.php b/resources/views/layouts/sidebar.blade.php index 133a2430..d1784647 100644 --- a/resources/views/layouts/sidebar.blade.php +++ b/resources/views/layouts/sidebar.blade.php @@ -4,7 +4,7 @@ 'w-3/4': sidebarOpened }"> @@ -31,17 +31,23 @@ 设置
+ @if(\App\Utils::config(\App\Enums\ConfigKey::IsEnableGallery) || \App\Utils::config(\App\Enums\ConfigKey::IsEnableApi))

公共

+ @if(\App\Utils::config(\App\Enums\ConfigKey::IsEnableGallery)) 画廊 - + @endif + @if(\App\Utils::config(\App\Enums\ConfigKey::IsEnableApi)) + 接口 + @endif
+ @endif

系统

diff --git a/resources/views/welcome.blade.php b/resources/views/welcome.blade.php index 4f06d7ec..a6ce4a0d 100644 --- a/resources/views/welcome.blade.php +++ b/resources/views/welcome.blade.php @@ -3,14 +3,16 @@
@if(Auth::check()) @include('layouts.user-nav') @else 登录 + @if(\App\Utils::config(\App\Enums\ConfigKey::IsEnableRegistration)) 注册 + @endif @endif
diff --git a/routes/web.php b/routes/web.php index 9d921522..ce736444 100644 --- a/routes/web.php +++ b/routes/web.php @@ -17,6 +17,7 @@ use App\Http\Controllers\User\UserController; use App\Http\Controllers\User\ImageController; use App\Http\Controllers\User\AlbumController; use App\Http\Controllers\Common\GalleryController; +use App\Http\Controllers\Common\ApiController; use App\Http\Controllers\Admin\ConsoleController as AdminConsoleController; use App\Http\Controllers\Admin\GroupController as AdminGroupController; @@ -32,6 +33,10 @@ Route::group(['middleware' => ['auth']], function () { Route::get('settings', [UserController::class, 'settings'])->name('settings'); Route::put('settings', [UserController::class, 'update'])->name('settings.update'); + Route::group(['prefix' => 'api'], function () { + Route::get('', [ApiController::class, 'index'])->name('api'); + }); + Route::get('upload', fn () => view('user.upload'))->name('upload'); Route::get('images', [ImageController::class, 'index'])->name('images'); Route::group(['prefix' => 'user'], function () {