From 0a4de78aa1429a54c6229fca14ae49cb99c7d72a Mon Sep 17 00:00:00 2001 From: WispX <1591788658@qq.com> Date: Tue, 1 Jan 2019 12:29:33 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E4=BF=AE=E5=A4=8D=E4=B8=8A=E4=B8=AA?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E4=B8=83=E7=89=9B=E4=BA=91=E3=80=81=E5=8F=88?= =?UTF-8?q?=E6=8B=8D=E4=BA=91=E5=9B=BE=E7=89=87=E6=97=A0=E6=B3=95=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E7=9A=84bug=20-=20=E5=A2=9E=E5=8A=A0=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E9=BB=98=E8=AE=A4=E6=96=87=E4=BB=B6=E5=A4=B9=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/common/validate/Users.php | 29 +++++++++++++---------- application/index/controller/Install.php | 7 ++++-- application/index/controller/Upload.php | 25 ++++++++++++++++--- application/index/view/user/settings.html | 4 ++++ install.sql | 2 +- update.sql | 5 ++++ 6 files changed, 53 insertions(+), 19 deletions(-) diff --git a/application/common/validate/Users.php b/application/common/validate/Users.php index c0e3f361..ec9a02a8 100644 --- a/application/common/validate/Users.php +++ b/application/common/validate/Users.php @@ -15,29 +15,32 @@ class Users extends Validate protected $rule = [ 'username' => 'require|max:15|unique:users', 'nickname' => 'max:15', + 'default_folder' => 'max:30|chsAlphaNum', 'email' => 'require|email|max:50|unique:users', 'password' => 'require|confirm', 'captcha' => 'require|captcha|token', ]; protected $message = [ - 'username.require' => '用户名不能为空', - 'username.max' => '用户名字符长度超出', - 'username.unique' => '用户名已存在,请更换', - 'nickname.max' => '昵称字符长度超出', - 'email.require' => '邮箱不能为空', - 'email.email' => '邮箱格式不正确', - 'email.max' => '邮箱字符长度超出', - 'email.unique' => '邮箱已存在', - 'password.require' => '密码不能为空', - 'password.confirm' => '两次输入的密码不一致', - 'captcha.require' => '请输入验证码', - 'captcha.captcha' => '验证码错误', + 'username.require' => '用户名不能为空', + 'username.max' => '用户名字符长度超出', + 'username.unique' => '用户名已存在,请更换', + 'nickname.max' => '昵称字符长度超出', + 'default_folder.max' => '默认上传文件夹名称长度超出', + 'default_folder.chsAlphaNum'=> '默认上传文件夹名称只能是汉字、字母和数字', + 'email.require' => '邮箱不能为空', + 'email.email' => '邮箱格式不正确', + 'email.max' => '邮箱字符长度超出', + 'email.unique' => '邮箱已存在', + 'password.require' => '密码不能为空', + 'password.confirm' => '两次输入的密码不一致', + 'captcha.require' => '请输入验证码', + 'captcha.captcha' => '验证码错误', ]; public function sceneEdit() { - return $this->only(['nickname', 'password'])->remove('password', 'require'); + return $this->only(['nickname', 'default_folder', 'password'])->remove('password', 'require'); } public function sceneAdminEdit() diff --git a/application/index/controller/Install.php b/application/index/controller/Install.php index 47b4ab74..67602355 100644 --- a/application/index/controller/Install.php +++ b/application/index/controller/Install.php @@ -217,8 +217,11 @@ EOT; // 新建表字段 $tableFields = [ 'lsky_images' => [ - 'folder_id' => 'ALTER TABLE `lsky_images` ADD `folder_id` INT NOT NULL DEFAULT \'0\' COMMENT \'文件夹ID\' AFTER `user_id`;' - ] + 'folder_id' => "ALTER TABLE `lsky_images` ADD `folder_id` INT NOT NULL DEFAULT '0' COMMENT '文件夹ID' AFTER `user_id`;" + ], + 'lsky_users' => [ + 'default_folder' => "ALTER TABLE `lsky_users` ADD `default_folder` VARCHAR(32) DEFAULT NULL COMMENT '默认上传文件夹' AFTER `quota`;" + ], ]; foreach ($tableFields as $table => $fields) { diff --git a/application/index/controller/Upload.php b/application/index/controller/Upload.php index 85604690..2a1b78c8 100644 --- a/application/index/controller/Upload.php +++ b/application/index/controller/Upload.php @@ -8,6 +8,7 @@ namespace app\index\controller; +use app\common\model\Folders; use app\common\model\Images; use app\common\model\Users; use GuzzleHttp\Client; @@ -77,7 +78,7 @@ class Upload extends Base if (Config::get('app.app_debug')) { throw new Exception($strategy->getError()); } - throw new Exception('上传失败'); + throw new Exception('上传失败,请检查策略配置是否正确!'); } $cdnDomain = $currentStrategy . '_cdn_domain'; @@ -107,7 +108,7 @@ class Upload extends Base } } - if (!Images::create([ + $imageData = [ 'user_id' => $user ? $user->id : 0, 'strategy' => $currentStrategy, 'path' => dirname($pathname), @@ -117,7 +118,25 @@ class Upload extends Base 'mime' => $mime, 'sha1' => $sha1, 'md5' => $md5 - ])) { + ]; + + // 默认上传文件夹,暂只支持一级 + if ($this->user->default_folder) { + $folderId = $this->user->folders()->where('name', $this->user->default_folder)->value('id'); + if (!$folderId) { + if (!$folderId = $this->user->folders()->insertGetId([ + 'user_id' => $this->user->id, + 'parent_id' => 0, + 'name' => $this->user->default_folder + ])) { + throw new Exception('文件夹创建失败!'); + } + } + + $imageData['folder_id'] = $folderId; + } + + if (!Images::create($imageData)) { $strategy->delete($pathname); throw new Exception('图片数据保存失败'); } diff --git a/application/index/view/user/settings.html b/application/index/view/user/settings.html index 44d501ca..c08295f6 100644 --- a/application/index/view/user/settings.html +++ b/application/index/view/user/settings.html @@ -19,6 +19,10 @@ +
+ + +
diff --git a/install.sql b/install.sql index 8b8534fd..4b56eb4f 100644 --- a/install.sql +++ b/install.sql @@ -205,4 +205,4 @@ ALTER TABLE `lsky_users` -- 使用表AUTO_INCREMENT `lsky_folders` -- ALTER TABLE `lsky_folders` - MODIFY `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID', AUTO_INCREMENT=1; + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID', AUTO_INCREMENT=1; \ No newline at end of file diff --git a/update.sql b/update.sql index 77ab1e96..21d12a90 100644 --- a/update.sql +++ b/update.sql @@ -41,3 +41,8 @@ CREATE TABLE IF NOT EXISTS `lsky_folders` ( `update_time` int(11) DEFAULT NULL COMMENT '更新时间', `create_time` int(11) DEFAULT NULL COMMENT '添加时间' ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='文件夹表'; + +-- v1.4.2 +UPDATE `lsky_config` SET `value` = '1.4.2' WHERE `lsky_config`.`name` = 'system_version'; +UPDATE `lsky`.`lsky_images` SET `strategy` = 'uss' WHERE `lsky_images`.`strategy` = 'upyun'; +UPDATE `lsky`.`lsky_images` SET `strategy` = 'kodo' WHERE `lsky_images`.`strategy` = 'qiniu'; \ No newline at end of file