From c4a6015d420552cbf61ad372dd7491bcfe783c19 Mon Sep 17 00:00:00 2001 From: WangNingkai <1655586865@qq.com> Date: Sun, 19 Jul 2020 16:11:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=90=8E=E5=8F=B0=E7=AE=A1?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + app/Console/Commands/InstallCommand.php | 4 +- app/Http/Controllers/AdminController.php | 32 ++++------- app/Http/Controllers/Auth/LoginController.php | 1 + app/Http/Controllers/ManageController.php | 26 ++++++--- app/Http/Middleware/Authenticate.php | 6 +- app/Http/Traits/ApiResponseTrait.php | 3 +- .../views/default/admin/file-manage.blade.php | 55 +++++++++++++++++-- resources/views/default/one-id.blade.php | 4 +- resources/views/default/one.blade.php | 4 +- routes/web.php | 2 +- storage/install/data/.gitignore | 1 + 12 files changed, 94 insertions(+), 45 deletions(-) diff --git a/.gitignore b/.gitignore index a79fedaa..483649ae 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ /.idea .env .env.backup +.env.bak .phpunit.result.cache Homestead.json Homestead.yaml diff --git a/app/Console/Commands/InstallCommand.php b/app/Console/Commands/InstallCommand.php index 8a11a6b5..6f05d5ef 100644 --- a/app/Console/Commands/InstallCommand.php +++ b/app/Console/Commands/InstallCommand.php @@ -58,7 +58,7 @@ public function handle(): void copy($sqlSampleFile, $sqlFile); } else { $this->warn('Already have database file,Re-creating...'); - rename($sqlFile, $sqlFile . '.' . date('YmdHis') . '.bak'); + rename($sqlFile, date('YmdHis') . '.' . $sqlFile . '.bak'); copy($sqlSampleFile, $sqlFile); } chmod($sqlFile, 0777); @@ -81,7 +81,7 @@ public function handle(): void $env = str_replace($_search, $_replace, $envExample); if (file_exists($envFile)) { if ($this->confirm('Already have [.env] ,overwrite?', true)) { - rename($envFile, $envFile . '.' . date('YmdHis') . '.bak'); + rename($envFile, date('YmdHis') . '.' . $envFile . '.bak'); file_put_contents($envFile, $env); } } else { diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index 22df8961..d89ebb5e 100644 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -9,6 +9,7 @@ namespace App\Http\Controllers; use App\Helpers\Tool; +use App\Http\Traits\ApiResponseTrait; use App\Models\Account; use App\Models\Setting; use App\Models\User; @@ -18,6 +19,7 @@ class AdminController extends BaseController { + use ApiResponseTrait; /** * 缓存清理 * @return \Illuminate\Http\RedirectResponse @@ -134,14 +136,10 @@ public function accountSet(Request $request) $id = $request->post('id', 0); $account = Account::find($id); if (!$account) { - return response()->json([ - 'error' => '账号不存在!' - ]); + return $this->fail('账号不存在'); } setting_set('primary_account', $id); - return response()->json([ - 'error' => '' - ]); + return $this->success(); } /** @@ -154,19 +152,15 @@ public function accountRemark($id, Request $request) { $account = Account::find($id); if (!$account) { - return response()->json([ - 'error' => '账号不存在!' - ]); + return $this->fail('账号不存在'); } $remark = $request->get('remark'); $account->remark = $remark; if ($account->save()) { Cache::forget('ac:list'); - return response()->json(); + return $this->success(); } - return response()->json([ - 'error' => '' - ]); + return $this->success(); } /** @@ -181,19 +175,13 @@ public function accountDelete(Request $request) $id = $request->post('id', 0); $account = Account::find($id); if (!$account) { - return response()->json([ - 'error' => '账号不存在!' - ]); + return $this->fail('账号不存在'); } if ($account->delete()) { Cache::forget('ac:list'); - return response()->json([ - 'error' => '' - ]); + return $this->success(); } - return response()->json([ - 'error' => '删除失败' - ]); + return $this->fail('删除失败'); } /** diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 82f00630..7d7fe4cb 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -74,5 +74,6 @@ public function redirectPath() Cache::forget('ac:list'); return '/admin/install'; } + return request()->get('redirect'); } } diff --git a/app/Http/Controllers/ManageController.php b/app/Http/Controllers/ManageController.php index 8fa6a8a0..6396f3a7 100644 --- a/app/Http/Controllers/ManageController.php +++ b/app/Http/Controllers/ManageController.php @@ -10,12 +10,15 @@ use App\Helpers\HashidsHelper; use App\Helpers\Tool; +use App\Http\Traits\ApiResponseTrait; use Illuminate\Http\Request; use Cache; use OneDrive; class ManageController extends BaseController { + use ApiResponseTrait; + public function query(Request $request, $hash, $query = '') { // 账号处理 @@ -84,6 +87,7 @@ public function query(Request $request, $hash, $query = '') $perPage = array_get($config, 'list_limit', 10); $list = $this->paginate($list, $perPage, false); + return view(config('olaindex.theme') . 'admin.file-manage', compact('accounts', 'hash', 'path', 'item', 'list', 'doc')); } @@ -151,8 +155,7 @@ public function edit(Request $request, $hash, $query = '') $content = ''; } - $file['content'] = $content; - ; + $file['content'] = $content;; return view(config('olaindex.theme') . 'editor', compact('accounts', 'hash', 'path', 'file')); } @@ -185,24 +188,31 @@ public function create(Request $request, $hash, $query = '') return redirect()->route('home'); } - public function delete(Request $request, $hash, $query = '') + public function delete(Request $request) { + $eTag = $request->get('eTag'); + $hash = $request->get('hash'); + $query = $request->get('id'); + if (!$eTag || !$hash || !$query) { + return $this->fail('参数错误!'); + } $accounts = Tool::fetchAccounts(); if (blank($accounts)) { Cache::forget('ac:list'); - abort(404, '请先绑定账号!'); + return $this->fail('请先绑定账号!'); } $account_id = HashidsHelper::decode($hash); if (!$account_id) { - abort(404, '账号不存在'); + return $this->fail('账号不存在'); + } $service = OneDrive::account($account_id); - $eTag = $request->get('eTag'); + $resp = $service->delete($query, $eTag); if (array_key_exists('code', $resp)) { - $this->showMessage(array_get($resp, 'message', '404NotFound'), true); + return $this->fail(array_get($resp, 'message', '404NotFound')); } - return redirect()->back(); + return $this->success(); } /** diff --git a/app/Http/Middleware/Authenticate.php b/app/Http/Middleware/Authenticate.php index 704089a7..9d1b1c1f 100644 --- a/app/Http/Middleware/Authenticate.php +++ b/app/Http/Middleware/Authenticate.php @@ -9,13 +9,13 @@ class Authenticate extends Middleware /** * Get the path the user should be redirected to when they are not authenticated. * - * @param \Illuminate\Http\Request $request + * @param \Illuminate\Http\Request $request * @return string|null */ protected function redirectTo($request) { - if (! $request->expectsJson()) { - return route('login'); + if (!$request->expectsJson()) { + return route('login', ['redirect' => $request->getRequestUri()]); } } } diff --git a/app/Http/Traits/ApiResponseTrait.php b/app/Http/Traits/ApiResponseTrait.php index a2af0bd6..7d5d8afe 100644 --- a/app/Http/Traits/ApiResponseTrait.php +++ b/app/Http/Traits/ApiResponseTrait.php @@ -35,7 +35,8 @@ public function buildResponse($data = [], $code = 0, $msg = 'ok') $data = [ 'data' => $data, 'msg' => $msg, - 'code' => $code + 'code' => $code, + 'error' => $code ? $msg : '', ]; return response()->json($data); } diff --git a/resources/views/default/admin/file-manage.blade.php b/resources/views/default/admin/file-manage.blade.php index 46a89813..9e4d32da 100644 --- a/resources/views/default/admin/file-manage.blade.php +++ b/resources/views/default/admin/file-manage.blade.php @@ -53,8 +53,9 @@ class="btn btn-primary btn-sm dropdown-toggle list-item-dropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">更多 @@ -104,17 +105,59 @@ class="btn btn-primary btn-sm dropdown-toggle list-item-dropdown" @stop @push('scripts') @endpush diff --git a/resources/views/default/one-id.blade.php b/resources/views/default/one-id.blade.php index 6dfc30ea..d04c1579 100644 --- a/resources/views/default/one-id.blade.php +++ b/resources/views/default/one-id.blade.php @@ -134,7 +134,9 @@