完善配置

This commit is contained in:
Wisp X 2022-02-14 14:04:19 +08:00
parent 11857bbe9d
commit 0e996b579d
19 changed files with 97 additions and 18 deletions

View File

@ -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';

View File

@ -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.
*

View File

@ -0,0 +1,23 @@
<?php
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');
}
}

View File

@ -2,13 +2,22 @@
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()

View File

@ -2,6 +2,7 @@
namespace App\Models;
use App\Enums\ConfigKey;
use App\Enums\ImagePermission;
use App\Enums\UserConfigKey;
use App\Utils;
@ -87,6 +88,9 @@ class User extends Authenticatable implements MustVerifyEmail
protected static function booted()
{
static::creating(function (self $user) {
// 初始容量
$user->capacity = Utils::config(ConfigKey::UserInitialCapacity);
$user->configs = collect([
UserConfigKey::DefaultAlbum => 0,
UserConfigKey::DefaultStrategy => 0,

View File

@ -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()));
// 初始化视图中的默认数据

View File

@ -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;

View File

@ -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;

View File

@ -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,

View File

@ -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;
}

View File

@ -40,6 +40,10 @@
<input type="hidden" name="is_enable_gallery" value="0">
<x-switch name="is_enable_gallery" value="1" :checked="(bool) $configs['is_enable_gallery']" />
</x-fieldset>
<x-fieldset title="是否启用接口" faq="启用或关闭接口功能,关闭后将无法通过接口上传图片、管理图片等操作。">
<input type="hidden" name="is_enable_api" value="0">
<x-switch name="is_enable_api" value="1" :checked="(bool) $configs['is_enable_api']" />
</x-fieldset>
<x-fieldset title="是否允许游客上传" faq="启用或关闭游客上传功能,游客上传受「系统默认组」控制。">
<input type="hidden" name="is_allow_guest_upload" value="0">
<x-switch name="is_allow_guest_upload" value="1" :checked="(bool) $configs['is_allow_guest_upload']" />

View File

@ -0,0 +1,11 @@
@section('title', '接口')
<x-app-layout>
<div class="my-6 md:my-9">
api
</div>
@push('scripts')
@endpush
</x-app-layout>

View File

@ -1 +1 @@
<span {{ $attributes }}>Lsky Pro</span>
<span {{ $attributes }}>{{ \App\Utils::config(\App\Enums\ConfigKey::SiteName) }}</span>

View File

@ -4,10 +4,10 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<meta name="csrf-token" content="{{ csrf_token() }}">
<meta name="keywords" content="Lsky Pro"/>
<meta name="description" content="Lsky Pro, Your photo album on the cloud."/>
<meta name="keywords" content="{{ \App\Utils::config(\App\Enums\ConfigKey::SiteKeywords) }}"/>
<meta name="description" content="{{ \App\Utils::config(\App\Enums\ConfigKey::SiteDescription) }}"/>
<title>{{ config('app.name', 'Laravel') }}</title>
<title>{{ \App\Utils::config(\App\Enums\ConfigKey::SiteName) }}</title>
<!-- Fonts -->
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700&display=swap">

View File

@ -4,10 +4,10 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="csrf-token" content="{{ csrf_token() }}">
<meta name="keywords" content="Lsky Pro"/>
<meta name="description" content="Lsky Pro, Your photo album on the cloud."/>
<meta name="keywords" content="{{ \App\Utils::config(\App\Enums\ConfigKey::SiteKeywords) }}"/>
<meta name="description" content="{{ \App\Utils::config(\App\Enums\ConfigKey::SiteDescription) }}"/>
<title>{{ config('app.name', 'Laravel') }}</title>
<title>{{ \App\Utils::config(\App\Enums\ConfigKey::SiteName) }}</title>
<!-- Fonts -->
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700&display=swap">

View File

@ -4,7 +4,7 @@
<a href="javascript:void(0)" @click="sidebarOpened = ! sidebarOpened" class="w-6 h-6 p-4 rounded-full sm:hidden -ml-1 mr-4 flex justify-center items-center">
<i class="fas fa-bars text-xl"></i>
</a>
<a href="" class="text-xl truncate" id="header-title">@yield('title', 'Lsky Pro')</a>
<a href="" class="text-xl truncate" id="header-title">@yield('title', \App\Utils::config(\App\Enums\ConfigKey::SiteName))</a>
</div>
<div class="flex justify-end items-center">
@include('layouts.user-nav')

View File

@ -4,7 +4,7 @@
'w-3/4': sidebarOpened
}">
<div class="px-6 h-14 flex justify-between sm:justify-center items-center bg-gray-600 text-white text-xl">
<a href="/" class="truncate">Lsky Pro</a>
<a href="/" class="truncate">{{ \App\Utils::config(\App\Enums\ConfigKey::SiteName) }}</a>
<a href="javascript:void(0)" class="sm:hidden block" @click="sidebarOpened = false"><i class="fas fa-times"></i></a>
</div>
@ -31,17 +31,23 @@
<x-slot name="name">设置</x-slot>
</x-nav-link>
</div>
@if(\App\Utils::config(\App\Enums\ConfigKey::IsEnableGallery) || \App\Utils::config(\App\Enums\ConfigKey::IsEnableApi))
<div class="flex flex-col space-y-2 mb-5">
<p class="text-gray-400 text-sm mx-4">公共</p>
@if(\App\Utils::config(\App\Enums\ConfigKey::IsEnableGallery))
<x-nav-link :href="route('gallery')" :active="request()->routeIs('gallery')">
<x-slot name="icon"><i class="fas fa-chalkboard text-blue-500"></i></x-slot>
<x-slot name="name">画廊</x-slot>
</x-nav-link>
<x-nav-link :active="request()->routeIs('apis')">
@endif
@if(\App\Utils::config(\App\Enums\ConfigKey::IsEnableApi))
<x-nav-link :href="route('api')" :active="request()->routeIs('apis')">
<x-slot name="icon"><i class="fas fa-link text-blue-500"></i></x-slot>
<x-slot name="name">接口</x-slot>
</x-nav-link>
@endif
</div>
@endif
<div class="flex flex-col space-y-2 mb-5">
<p class="text-gray-400 text-sm mx-4">系统</p>
<x-nav-link :href="route('admin.console')" :active="request()->is('admin/console*')">

View File

@ -3,14 +3,16 @@
<header class="w-full h-14 bg-gray-700 text-white flex justify-center fixed top-0 z-[9]">
<div class="container mx-auto px-5 sm:px-10 md:px-10 lg:px-10 xl:px-10 2xl:px-60 flex justify-between items-center">
<div class="flex justify-start items-center max-w-[70%]">
<a href="{{ route('/') }}" class="text-white text-xl truncate">Lsky Pro</a>
<a href="{{ route('/') }}" class="text-white text-xl truncate">{{ \App\Utils::config(\App\Enums\ConfigKey::SiteName) }}</a>
</div>
<div class="flex justify-end items-center space-x-3">
@if(Auth::check())
@include('layouts.user-nav')
@else
<a href="{{ route('login') }}" class="text-gray-300 hover:bg-gray-600 hover:text-white px-3 py-2 rounded-md text-sm font-medium">登录</a>
@if(\App\Utils::config(\App\Enums\ConfigKey::IsEnableRegistration))
<a href="{{ route('register') }}" class="text-gray-300 hover:bg-gray-600 hover:text-white px-3 py-2 rounded-md text-sm font-medium">注册</a>
@endif
@endif
</div>
</div>

View File

@ -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 () {