diff --git a/app/Console/Commands/Upgrade/V11_0_0.php b/app/Console/Commands/Upgrade/V11_0_0.php index 550018ae3..566cad7b0 100644 --- a/app/Console/Commands/Upgrade/V11_0_0.php +++ b/app/Console/Commands/Upgrade/V11_0_0.php @@ -5,6 +5,7 @@ namespace App\Console\Commands\Upgrade; use Artisan; +use DB; use File; use Illuminate\Console\Command; @@ -29,5 +30,65 @@ public function handle() Artisan::call('storage:link --relative'); } + + $updatedConfigs = [ + 160 => 'filesystems.disks.oss_backups.access_key', + 161 => 'filesystems.disks.oss_backups.secret_key', + 162 => 'filesystems.disks.oss_backups.bucket', + 163 => 'filesystems.disks.oss_backups.endpoint', + ]; + + foreach ($updatedConfigs as $id => $name) { + DB::table('configs')->where('id', $id)->update([ + 'name' => $name, + ]); + } + + DB::table('configs')->where('id', 164)->update([ + 'value' => str_replace('"oss"', '"oss_backups"', DB::table('configs')->where('id', 164)->value('value')) + ]); + + DB::table('configs')->insertOrIgnore([ + [ + 'id' => 200, + 'name' => 'filesystems.disks.oss_uploads.access_key', + 'value' => '', + 'created_at' => '2020-06-26 23:29:52', + 'updated_at' => '2020-06-26 23:29:52', + 'deleted_at' => null, + ], + [ + 'id' => 201, + 'name' => 'filesystems.disks.oss_uploads.secret_key', + 'value' => '', + 'created_at' => '2020-06-26 23:29:52', + 'updated_at' => '2020-06-26 23:29:52', + 'deleted_at' => null, + ], + [ + 'id' => 202, + 'name' => 'filesystems.disks.oss_uploads.bucket', + 'value' => '', + 'created_at' => '2020-06-26 23:29:52', + 'updated_at' => '2020-06-26 23:29:52', + 'deleted_at' => null, + ], + [ + 'id' => 203, + 'name' => 'filesystems.disks.oss_uploads.endpoint', + 'value' => '', + 'created_at' => '2020-06-26 23:29:52', + 'updated_at' => '2020-06-26 23:29:52', + 'deleted_at' => null, + ], + [ + 'id' => 204, + 'name' => 'bjyblog.upload_disks', + 'value' => '["public"]', + 'created_at' => '2018-12-04 22:29:52', + 'updated_at' => '2018-12-04 22:29:52', + 'deleted_at' => null, + ], + ]); } } diff --git a/app/Http/Controllers/Admin/ArticleController.php b/app/Http/Controllers/Admin/ArticleController.php index 0c924935a..c5dfade6c 100644 --- a/app/Http/Controllers/Admin/ArticleController.php +++ b/app/Http/Controllers/Admin/ArticleController.php @@ -51,7 +51,9 @@ public function create() public function uploadImage(Request $request) { - $imagePath = $request->file('editormd-image-file')->store('uploads/article/' . Date::now()->format('Ymd'), 'public'); + foreach (config('bjyblog.upload_disks') as $disk) { + $imagePath = $request->file('editormd-image-file')->store('uploads/article/' . Date::now()->format('Ymd'), $disk); + } return response()->json([ 'success' => 1, @@ -65,7 +67,10 @@ public function store(Store $request) $article = $request->except('_token'); if ($request->hasFile('cover')) { - $imagePath = $request->file('cover')->store('uploads/article/' . Date::now()->format('Ymd'), 'public'); + foreach (config('bjyblog.upload_disks') as $disk) { + $imagePath = $request->file('cover')->store('uploads/article/' . Date::now()->format('Ymd'), $disk); + } + $article['cover'] = '/' . $imagePath; } @@ -95,7 +100,10 @@ public function update(Store $request, ArticleTag $articleTagModel, $id) // 上传封面图 if ($request->hasFile('cover')) { - $imagePath = $request->file('cover')->store('uploads/article/' . Date::now()->format('Ymd'), 'public'); + foreach (config('bjyblog.upload_disks') as $disk) { + $imagePath = $request->file('cover')->store('uploads/article/' . Date::now()->format('Ymd'), $disk); + } + $article['cover'] = '/' . $imagePath; } diff --git a/app/Http/Controllers/Admin/ConfigController.php b/app/Http/Controllers/Admin/ConfigController.php index 07968b3d5..689524e8e 100644 --- a/app/Http/Controllers/Admin/ConfigController.php +++ b/app/Http/Controllers/Admin/ConfigController.php @@ -36,6 +36,11 @@ public function backup() return view('admin.config.backup'); } + public function upload() + { + return view('admin.config.upload'); + } + public function seo() { return view('admin.config.seo'); @@ -71,7 +76,10 @@ public function update(Request $request) $configs = $request->except('_token'); if ($request->hasFile('153')) { - $imagePath = $request->file('153')->store('uploads/images', 'public'); + foreach (config('bjyblog.upload_disks') as $disk) { + $imagePath = $request->file('153')->store('uploads/images', $disk); + } + $configs['153'] = '/' . $imagePath; } diff --git a/app/Http/Controllers/Resources/ArticleCoverController.php b/app/Http/Controllers/Resources/ArticleCoverController.php index 3991ec575..b78122bc8 100644 --- a/app/Http/Controllers/Resources/ArticleCoverController.php +++ b/app/Http/Controllers/Resources/ArticleCoverController.php @@ -11,7 +11,9 @@ class ArticleCoverController extends Controller { public function store(Store $request) { - $imagePath = $request->file('cover')->store('uploads/article' . Date::now()->format('Ymd'), 'public'); + foreach (config('bjyblog.upload_disks') as $disk) { + $imagePath = $request->file('cover')->store('uploads/article/' . Date::now()->format('Ymd'), $disk); + } return response()->json([ 'success' => 1, diff --git a/app/Http/Controllers/Resources/ConfigController.php b/app/Http/Controllers/Resources/ConfigController.php index 88cbcc0cc..36900fb5a 100644 --- a/app/Http/Controllers/Resources/ConfigController.php +++ b/app/Http/Controllers/Resources/ConfigController.php @@ -17,7 +17,9 @@ class ConfigController extends Controller public function uploadQqQunOrCode(QqQunOrCode $request) { - $imagePath = $request->file('file')->store('uploads/images', 'public'); + foreach (config('bjyblog.upload_disks') as $disk) { + $imagePath = $request->file('file')->store('uploads/images', $disk); + } return response()->json([ 'url' => $imagePath, diff --git a/config/bjyblog.php b/config/bjyblog.php index 655c16091..682b8c54c 100644 --- a/config/bjyblog.php +++ b/config/bjyblog.php @@ -63,4 +63,5 @@ 'language' => '', ], 'theme' => '', + 'upload_disks' => '', ]; diff --git a/config/filesystems.php b/config/filesystems.php index 4faf3e4da..abc7f6184 100644 --- a/config/filesystems.php +++ b/config/filesystems.php @@ -64,14 +64,24 @@ 'url' => env('AWS_URL'), ], - 'oss' => [ + 'oss_backups' => [ 'driver' => 'oss', 'root' => '', - 'access_key' => env('OSS_ACCESS_KEY'), - 'secret_key' => env('OSS_SECRET_KEY'), - 'endpoint' => env('OSS_ENDPOINT'), - 'bucket' => env('OSS_BUCKET'), - 'isCName' => env('OSS_IS_CNAME', false), + 'access_key' => '', + 'secret_key' => '', + 'endpoint' => '', + 'bucket' => '', + 'isCName' => false, + ], + + 'oss_uploads' => [ + 'driver' => 'oss', + 'root' => '', + 'access_key' => '', + 'secret_key' => '', + 'endpoint' => '', + 'bucket' => '', + 'isCName' => false, ], ], diff --git a/database/seeds/ConfigsTableSeeder.php b/database/seeds/ConfigsTableSeeder.php index ea3ee7c76..ea27bfbc6 100644 --- a/database/seeds/ConfigsTableSeeder.php +++ b/database/seeds/ConfigsTableSeeder.php @@ -250,7 +250,7 @@ public function run() ], [ 'id' => 160, - 'name' => 'filesystems.disks.oss.access_key', + 'name' => 'filesystems.disks.oss_backups.access_key', 'value' => '', 'created_at' => '2018-12-04 22:29:52', 'updated_at' => '2018-12-04 22:29:52', @@ -258,7 +258,7 @@ public function run() ], [ 'id' => 161, - 'name' => 'filesystems.disks.oss.secret_key', + 'name' => 'filesystems.disks.oss_backups.secret_key', 'value' => '', 'created_at' => '2018-12-04 22:29:52', 'updated_at' => '2018-12-04 22:29:52', @@ -266,7 +266,7 @@ public function run() ], [ 'id' => 162, - 'name' => 'filesystems.disks.oss.bucket', + 'name' => 'filesystems.disks.oss_backups.bucket', 'value' => '', 'created_at' => '2018-12-04 22:29:52', 'updated_at' => '2018-12-04 22:29:52', @@ -274,7 +274,7 @@ public function run() ], [ 'id' => 163, - 'name' => 'filesystems.disks.oss.endpoint', + 'name' => 'filesystems.disks.oss_backups.endpoint', 'value' => '', 'created_at' => '2018-12-04 22:29:52', 'updated_at' => '2018-12-04 22:29:52', @@ -575,6 +575,46 @@ public function run() 'updated_at' => '2020-05-12 23:06:00', 'deleted_at' => null, ], + [ + 'id' => 200, + 'name' => 'filesystems.disks.oss_uploads.access_key', + 'value' => '', + 'created_at' => '2020-06-26 23:29:52', + 'updated_at' => '2020-06-26 23:29:52', + 'deleted_at' => null, + ], + [ + 'id' => 201, + 'name' => 'filesystems.disks.oss_uploads.secret_key', + 'value' => '', + 'created_at' => '2020-06-26 23:29:52', + 'updated_at' => '2020-06-26 23:29:52', + 'deleted_at' => null, + ], + [ + 'id' => 202, + 'name' => 'filesystems.disks.oss_uploads.bucket', + 'value' => '', + 'created_at' => '2020-06-26 23:29:52', + 'updated_at' => '2020-06-26 23:29:52', + 'deleted_at' => null, + ], + [ + 'id' => 203, + 'name' => 'filesystems.disks.oss_uploads.endpoint', + 'value' => '', + 'created_at' => '2020-06-26 23:29:52', + 'updated_at' => '2020-06-26 23:29:52', + 'deleted_at' => null, + ], + [ + 'id' => 204, + 'name' => 'bjyblog.upload_disks', + 'value' => '["public"]', + 'created_at' => '2018-12-04 22:29:52', + 'updated_at' => '2018-12-04 22:29:52', + 'deleted_at' => null, + ], ]); } } diff --git a/resources/lang/fr.json b/resources/lang/fr.json index 2eedc7394..8b27d4d00 100644 --- a/resources/lang/fr.json +++ b/resources/lang/fr.json @@ -205,6 +205,7 @@ "URL": "URL", "Update Success": "Mise à jour réussie", "Upgrade": "Améliorer", + "Upload": "Télécharger", "Use Slug": "Utilisation Slug", "User": "Utilisateur", "User Counts": "Nombre utilisateurs", diff --git a/resources/lang/ru.json b/resources/lang/ru.json index 9675bd22f..3d2aa183f 100644 --- a/resources/lang/ru.json +++ b/resources/lang/ru.json @@ -205,6 +205,7 @@ "URL": "URL", "Update Success": "Успешно обновлено", "Upgrade": "Обновление", + "Upload": "Загрузить", "Use Slug": "Использовать слаги", "User": "Пользователи", "User Counts": "Количество пользователей", diff --git a/resources/lang/zh-CN.json b/resources/lang/zh-CN.json index 26f4cc49d..8cdfa9f92 100644 --- a/resources/lang/zh-CN.json +++ b/resources/lang/zh-CN.json @@ -205,6 +205,7 @@ "URL": "链接", "Update Success": "修改成功", "Upgrade": "升级", + "Upload": "上传", "Use Slug": "使用 Slug", "User": "用户", "User Counts": "登录用户", diff --git a/resources/views/admin/config/backup.blade.php b/resources/views/admin/config/backup.blade.php index 7d5d241b2..6d7becc18 100644 --- a/resources/views/admin/config/backup.blade.php +++ b/resources/views/admin/config/backup.blade.php @@ -13,7 +13,7 @@ {{ __('Local') }}   - {{ __('Aliyun') }} OSS + {{ __('Aliyun') }} OSS @@ -31,25 +31,25 @@ {{ __('Aliyun') }} AccessKeyID: - + {{ __('Aliyun') }} AccessKeySecret: - + {{ __('Aliyun') }} BUCKET: - + {{ __('Aliyun') }} ENDPOINT: - + diff --git a/resources/views/admin/config/upload.blade.php b/resources/views/admin/config/upload.blade.php new file mode 100644 index 000000000..fac72147c --- /dev/null +++ b/resources/views/admin/config/upload.blade.php @@ -0,0 +1,51 @@ +@extends('admin.layouts.admin') + +@section('title', __('Upload')) + +@section('nav', __('Upload')) + +@section('content') +
+ {{ csrf_field() }} + + + + + + + + + + + + + + + + + + + + + + + + + +
{{ __('Type') }}: + {{ __('Local') }} +   + {{ __('Aliyun') }} OSS +
{{ __('Aliyun') }} AccessKeyID: + +
{{ __('Aliyun') }} AccessKeySecret: + +
{{ __('Aliyun') }} BUCKET: + +
{{ __('Aliyun') }} ENDPOINT: + +
+ +
+
+@endsection diff --git a/resources/views/admin/layouts/admin.blade.php b/resources/views/admin/layouts/admin.blade.php index 210304392..a7710efb8 100644 --- a/resources/views/admin/layouts/admin.blade.php +++ b/resources/views/admin/layouts/admin.blade.php @@ -89,6 +89,7 @@
  • QQ群
  • @endif
  • {{ __('Backup') }}
  • +
  • {{ __('Upload') }}
  • {{ __('SEO') }}
  • {{ __('Social Share') }}
  • {{ __('Social Links') }}
  • diff --git a/routes/web.php b/routes/web.php index b48832bbd..1dce186e6 100644 --- a/routes/web.php +++ b/routes/web.php @@ -257,6 +257,8 @@ Route::get('qqQun', 'ConfigController@qqQun'); // 编辑备份配置页面 Route::get('backup', 'ConfigController@backup'); + // Upload + Route::get('upload', 'ConfigController@upload'); // SEO Route::get('seo', 'ConfigController@seo'); // Social Share diff --git a/tests/Commands/Upgrade/V11_0_0/CommandTest.php b/tests/Commands/Upgrade/V11_0_0/CommandTest.php index 9bf1d6bda..1b7d6ed22 100644 --- a/tests/Commands/Upgrade/V11_0_0/CommandTest.php +++ b/tests/Commands/Upgrade/V11_0_0/CommandTest.php @@ -4,10 +4,75 @@ namespace Tests\Commands\Upgrade\V11_0_0; +use DB; + class CommandTest extends \Tests\Commands\Upgrade\TestCase { public function testCommand() { + $updatedConfigs = [ + 160 => 'filesystems.disks.oss_backups.access_key', + 161 => 'filesystems.disks.oss_backups.secret_key', + 162 => 'filesystems.disks.oss_backups.bucket', + 163 => 'filesystems.disks.oss_backups.endpoint', + ]; + + foreach ($updatedConfigs as $id => $name) { + static::assertNotSame($name, DB::table('configs')->where('id', $id)->value('name')); + } + + static::assertEquals(0, DB::table('configs')->where('id', '>=', 200)->count()); + $this->artisan('upgrade:v11.0.0')->assertExitCode(0); + + static::assertEquals(5, DB::table('configs')->where('id', '>=', 200)->count()); + + $savedConfigs = [ + [ + 'id' => 200, + 'name' => 'filesystems.disks.oss_uploads.access_key', + 'value' => '', + 'created_at' => '2020-06-26 23:29:52', + 'updated_at' => '2020-06-26 23:29:52', + 'deleted_at' => null, + ], + [ + 'id' => 201, + 'name' => 'filesystems.disks.oss_uploads.secret_key', + 'value' => '', + 'created_at' => '2020-06-26 23:29:52', + 'updated_at' => '2020-06-26 23:29:52', + 'deleted_at' => null, + ], + [ + 'id' => 202, + 'name' => 'filesystems.disks.oss_uploads.bucket', + 'value' => '', + 'created_at' => '2020-06-26 23:29:52', + 'updated_at' => '2020-06-26 23:29:52', + 'deleted_at' => null, + ], + [ + 'id' => 203, + 'name' => 'filesystems.disks.oss_uploads.endpoint', + 'value' => '', + 'created_at' => '2020-06-26 23:29:52', + 'updated_at' => '2020-06-26 23:29:52', + 'deleted_at' => null, + ], + [ + 'id' => 204, + 'name' => 'bjyblog.upload_disks', + 'value' => '["public"]', + 'created_at' => '2018-12-04 22:29:52', + 'updated_at' => '2018-12-04 22:29:52', + 'deleted_at' => null, + ], + ]; + + foreach ($savedConfigs as $savedConfig) { + static::assertDatabaseHas('configs', $savedConfig); + } + } } diff --git a/tests/Feature/_baseline/Resources/ConfigControllerTest/index.json b/tests/Feature/_baseline/Resources/ConfigControllerTest/index.json index 4fff02c4d..bbe756c71 100644 --- a/tests/Feature/_baseline/Resources/ConfigControllerTest/index.json +++ b/tests/Feature/_baseline/Resources/ConfigControllerTest/index.json @@ -252,7 +252,7 @@ }, { "id": 160, - "name": "filesystems.disks.oss.access_key", + "name": "filesystems.disks.oss_backups.access_key", "value": "", "created_at": "2018-12-04 22:29:52", "updated_at": "2018-12-04 22:29:52", @@ -260,7 +260,7 @@ }, { "id": 161, - "name": "filesystems.disks.oss.secret_key", + "name": "filesystems.disks.oss_backups.secret_key", "value": "", "created_at": "2018-12-04 22:29:52", "updated_at": "2018-12-04 22:29:52", @@ -268,7 +268,7 @@ }, { "id": 162, - "name": "filesystems.disks.oss.bucket", + "name": "filesystems.disks.oss_backups.bucket", "value": "", "created_at": "2018-12-04 22:29:52", "updated_at": "2018-12-04 22:29:52", @@ -276,7 +276,7 @@ }, { "id": 163, - "name": "filesystems.disks.oss.endpoint", + "name": "filesystems.disks.oss_backups.endpoint", "value": "", "created_at": "2018-12-04 22:29:52", "updated_at": "2018-12-04 22:29:52", @@ -569,6 +569,48 @@ "created_at": "2020-05-12 23:06:00", "updated_at": "2020-05-12 23:06:00", "deleted_at": null + }, + { + "id": 200, + "name": "filesystems.disks.oss_uploads.access_key", + "value": "", + "created_at": "2020-06-26 23:29:52", + "updated_at": "2020-06-26 23:29:52", + "deleted_at": null + }, + { + "id": 201, + "name": "filesystems.disks.oss_uploads.secret_key", + "value": "", + "created_at": "2020-06-26 23:29:52", + "updated_at": "2020-06-26 23:29:52", + "deleted_at": null + }, + { + "id": 202, + "name": "filesystems.disks.oss_uploads.bucket", + "value": "", + "created_at": "2020-06-26 23:29:52", + "updated_at": "2020-06-26 23:29:52", + "deleted_at": null + }, + { + "id": 203, + "name": "filesystems.disks.oss_uploads.endpoint", + "value": "", + "created_at": "2020-06-26 23:29:52", + "updated_at": "2020-06-26 23:29:52", + "deleted_at": null + }, + { + "id": 204, + "name": "bjyblog.upload_disks", + "value": [ + "public" + ], + "created_at": "2018-12-04 22:29:52", + "updated_at": "2018-12-04 22:29:52", + "deleted_at": null } ], "links": { @@ -583,8 +625,8 @@ "last_page": 1, "path": "http:\/\/laravel-bjyblog.test\/api\/configs", "per_page": 1000, - "to": 69, - "total": 69 + "to": 74, + "total": 74 } } } \ No newline at end of file