diff --git a/app/Http/Controllers/User/UserController.php b/app/Http/Controllers/User/UserController.php index 4a70fd4b..8e5d2fa7 100644 --- a/app/Http/Controllers/User/UserController.php +++ b/app/Http/Controllers/User/UserController.php @@ -2,12 +2,12 @@ namespace App\Http\Controllers\User; -use App\Enums\ConfigKey; +use App\Enums\UserConfigKey; use App\Http\Controllers\Controller; use App\Http\Requests\UserSettingRequest; use App\Models\User; -use App\Utils; use Illuminate\Auth\Events\PasswordReset; +use Illuminate\Http\Request; use Illuminate\Http\Response; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Hash; @@ -20,14 +20,8 @@ class UserController extends Controller { /** @var User $user */ $user = Auth::user(); - - // 组配置 - $configs = Utils::config(ConfigKey::Group); - if ($user->group) { - $configs = $user->group->configs; - } - - $strategies = $user->group ? $user->group->strategies()->get() : []; + $configs = $user->group->configs; + $strategies = $user->group->strategies()->get(); return view('user.dashboard', compact('strategies', 'configs', 'user')); } @@ -56,4 +50,15 @@ class UserController extends Controller $user->save(); return $this->success('保存成功'); } + + public function setStrategy(Request $request): Response + { + /** @var User $user */ + $user = Auth::user(); + if (! $strategy = $user->group->strategies()->find($request->id)) { + return $this->error('没有找到该策略'); + } + $user->update(['configs->'.UserConfigKey::DefaultStrategy => $strategy->id]); + return $this->success('设置成功'); + } } diff --git a/app/Services/ImageService.php b/app/Services/ImageService.php index 2f4125f8..9e264ebe 100644 --- a/app/Services/ImageService.php +++ b/app/Services/ImageService.php @@ -103,15 +103,19 @@ class ImageService // 图片默认权限 $image->permission = ImagePermission::Private; - // 默认储存策略 - if (is_null($user)) { - // 游客随机一个储存,TODO 适配前端切换 - $strategy = $strategies->random(1)->first(); - $image->strategy_id = $strategy->id; + if ($request->has('strategy_id')) { + if (! $strategy = $strategies->find($request->input('strategy_id'))) { + throw new UploadException('选定的策略不存在'); + } } else { - /** @var Strategy $strategy */ - $strategy = $strategies->find($user->configs->get(UserConfigKey::DefaultStrategy, 0), $strategies->first()); + // 没有指定则选择第一个策略 + $strategy = $strategies->first(); + } + $image->strategy_id = $strategy->id; + + // 默认储存策略 + if (! is_null($user)) { if (Utils::config(ConfigKey::IsUserNeedVerify) && ! $user->email_verified_at) { throw new UploadException('账户未验证'); } @@ -131,7 +135,6 @@ class ImageService } } - $image->strategy_id = $strategy->id; $image->user_id = $user->id; // 用户设置的图片默认权限 $image->permission = $user->configs->get(UserConfigKey::DefaultPermission, ImagePermission::Private); diff --git a/composer.lock b/composer.lock index fbf3c596..7007dea6 100644 --- a/composer.lock +++ b/composer.lock @@ -6090,16 +6090,16 @@ }, { "name": "symfony/http-foundation", - "version": "v6.0.5", + "version": "v6.0.6", "source": { "type": "git", "url": "https://github.com/symfony/http-foundation.git", - "reference": "b460fb15905eef449c4c43a4f0c113eccee103b9" + "reference": "a000fcf2298a1bc79a1dcff22608792506534719" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-foundation/zipball/b460fb15905eef449c4c43a4f0c113eccee103b9", - "reference": "b460fb15905eef449c4c43a4f0c113eccee103b9", + "url": "https://api.github.com/repos/symfony/http-foundation/zipball/a000fcf2298a1bc79a1dcff22608792506534719", + "reference": "a000fcf2298a1bc79a1dcff22608792506534719", "shasum": "", "mirrors": [ { @@ -6148,7 +6148,7 @@ "description": "Defines an object-oriented layer for the HTTP specification", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/http-foundation/tree/v6.0.5" + "source": "https://github.com/symfony/http-foundation/tree/v6.0.6" }, "funding": [ { @@ -6164,20 +6164,20 @@ "type": "tidelift" } ], - "time": "2022-02-21T17:15:17+00:00" + "time": "2022-03-05T21:04:00+00:00" }, { "name": "symfony/http-kernel", - "version": "v6.0.5", + "version": "v6.0.6", "source": { "type": "git", "url": "https://github.com/symfony/http-kernel.git", - "reference": "5ad3f5e5fa772a8b5c6bb217f8379b533afac2ba" + "reference": "f9e49ad9fe16895b24cd7a09dc28d3364282e21a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-kernel/zipball/5ad3f5e5fa772a8b5c6bb217f8379b533afac2ba", - "reference": "5ad3f5e5fa772a8b5c6bb217f8379b533afac2ba", + "url": "https://api.github.com/repos/symfony/http-kernel/zipball/f9e49ad9fe16895b24cd7a09dc28d3364282e21a", + "reference": "f9e49ad9fe16895b24cd7a09dc28d3364282e21a", "shasum": "", "mirrors": [ { @@ -6263,7 +6263,7 @@ "description": "Provides a structured process for converting a Request into a Response", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/http-kernel/tree/v6.0.5" + "source": "https://github.com/symfony/http-kernel/tree/v6.0.6" }, "funding": [ { @@ -6279,7 +6279,7 @@ "type": "tidelift" } ], - "time": "2022-02-28T08:05:03+00:00" + "time": "2022-03-05T21:19:20+00:00" }, { "name": "symfony/mailer", @@ -7493,16 +7493,16 @@ }, { "name": "symfony/translation", - "version": "v6.0.5", + "version": "v6.0.6", "source": { "type": "git", "url": "https://github.com/symfony/translation.git", - "reference": "e69501c71107cc3146b32aaa45f4edd0c3427875" + "reference": "f6639cb9b5e0c57fe31e3263b900a77eedb0c908" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/translation/zipball/e69501c71107cc3146b32aaa45f4edd0c3427875", - "reference": "e69501c71107cc3146b32aaa45f4edd0c3427875", + "url": "https://api.github.com/repos/symfony/translation/zipball/f6639cb9b5e0c57fe31e3263b900a77eedb0c908", + "reference": "f6639cb9b5e0c57fe31e3263b900a77eedb0c908", "shasum": "", "mirrors": [ { @@ -7574,7 +7574,7 @@ "description": "Provides tools to internationalize your application", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/translation/tree/v6.0.5" + "source": "https://github.com/symfony/translation/tree/v6.0.6" }, "funding": [ { @@ -7590,7 +7590,7 @@ "type": "tidelift" } ], - "time": "2022-02-09T15:52:48+00:00" + "time": "2022-03-02T12:58:14+00:00" }, { "name": "symfony/translation-contracts", @@ -7678,16 +7678,16 @@ }, { "name": "symfony/var-dumper", - "version": "v6.0.5", + "version": "v6.0.6", "source": { "type": "git", "url": "https://github.com/symfony/var-dumper.git", - "reference": "60d6a756d5f485df5e6e40b337334848f79f61ce" + "reference": "38358405ae948963c50a3aae3dfea598223ba15e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/var-dumper/zipball/60d6a756d5f485df5e6e40b337334848f79f61ce", - "reference": "60d6a756d5f485df5e6e40b337334848f79f61ce", + "url": "https://api.github.com/repos/symfony/var-dumper/zipball/38358405ae948963c50a3aae3dfea598223ba15e", + "reference": "38358405ae948963c50a3aae3dfea598223ba15e", "shasum": "", "mirrors": [ { @@ -7752,7 +7752,7 @@ "dump" ], "support": { - "source": "https://github.com/symfony/var-dumper/tree/v6.0.5" + "source": "https://github.com/symfony/var-dumper/tree/v6.0.6" }, "funding": [ { @@ -7768,7 +7768,7 @@ "type": "tidelift" } ], - "time": "2022-02-21T17:15:17+00:00" + "time": "2022-03-02T12:58:14+00:00" }, { "name": "tijsverkoyen/css-to-inline-styles", @@ -9659,16 +9659,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.5.16", + "version": "9.5.17", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "5ff8c545a50226c569310a35f4fa89d79f1ddfdc" + "reference": "5c5abcfaa2cbd44b2203995d7a339ef910fe0c8f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/5ff8c545a50226c569310a35f4fa89d79f1ddfdc", - "reference": "5ff8c545a50226c569310a35f4fa89d79f1ddfdc", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/5c5abcfaa2cbd44b2203995d7a339ef910fe0c8f", + "reference": "5c5abcfaa2cbd44b2203995d7a339ef910fe0c8f", "shasum": "", "mirrors": [ { @@ -9752,7 +9752,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.16" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.17" }, "funding": [ { @@ -9764,7 +9764,7 @@ "type": "github" } ], - "time": "2022-02-23T17:10:58+00:00" + "time": "2022-03-05T16:54:31+00:00" }, { "name": "sebastian/cli-parser", diff --git a/resources/views/components/upload.blade.php b/resources/views/components/upload.blade.php index f65cf8f1..258ac922 100644 --- a/resources/views/components/upload.blade.php +++ b/resources/views/components/upload.blade.php @@ -4,8 +4,8 @@

Image Upload

- 最大可上传 {{ \App\Utils::formatSize($groupConfigs->get(\App\Enums\GroupConfigKey::MaximumFileSize) * 1024) }} 的图片,上传队列最多 - {{ $groupConfigs->get(\App\Enums\GroupConfigKey::ConcurrentUploadNum) }} + 最大可上传 {{ \App\Utils::formatSize($_group->configs->get(\App\Enums\GroupConfigKey::MaximumFileSize) * 1024) }} 的图片,上传队列最多 + {{ $_group->configs->get(\App\Enums\GroupConfigKey::ConcurrentUploadNum) }} 张。本站已托管 {{ \App\Models\Image::query()->count() }} 张图片。

@@ -73,8 +73,8 @@ @endpush @push('scripts') +@endpush diff --git a/resources/views/user/settings.blade.php b/resources/views/user/settings.blade.php index 9ee54966..671eff55 100644 --- a/resources/views/user/settings.blade.php +++ b/resources/views/user/settings.blade.php @@ -4,6 +4,7 @@

基础设置

+ @csrf
diff --git a/resources/views/welcome.blade.php b/resources/views/welcome.blade.php index b552691b..9307e97d 100644 --- a/resources/views/welcome.blade.php +++ b/resources/views/welcome.blade.php @@ -9,7 +9,11 @@ -
+
+ @if($_group->strategies->isNotEmpty()) + @include('layouts.strategies') + @endif + @if(Auth::check()) @include('layouts.user-nav') @else diff --git a/routes/web.php b/routes/web.php index 34c79619..64e546ef 100644 --- a/routes/web.php +++ b/routes/web.php @@ -33,8 +33,12 @@ 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('settings', [UserController::class, 'settings'])->name('settings'); - Route::put('settings', [UserController::class, 'update'])->name('settings.update'); + + Route::prefix('settings')->group(function () { + Route::get('', [UserController::class, 'settings'])->name('settings'); + Route::put('', [UserController::class, 'update'])->name('settings.update'); + Route::put('set-strategy', [UserController::class, 'setStrategy'])->name('settings.strategy.set'); + }); Route::group(['prefix' => 'api'], function () { Route::get('', [ApiController::class, 'index'])->name('api');