Commit 33a31cfb0fae16317c043761ea7c7e26312806e5

Authored by YunaiV
1 parent b0d635e1

优化文件的 type 识别与存储

README.md
... ... @@ -42,7 +42,7 @@
42 42 文档地址:<http://www.iocoder.cn/categories/Yudao/>
43 43 * [《如何搭建环境》](http://www.iocoder.cn/categories/Yudao/?yudao)
44 44  
45   -> 未来会补充文档和视频,方便胖友冲冲冲!
  45 +视频教程:<https://doc.iocoder.cn/video/>
46 46  
47 47 ## 🐼 内置功能
48 48  
... ...
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/io/FileUtils.java
... ... @@ -64,19 +64,21 @@ public class FileUtils {
64 64 }
65 65  
66 66 /**
  67 + * 生成文件路径
  68 + *
67 69 * @param content 文件内容
68 70 * @param originalName 原始文件名
69 71 * @return path,唯一不可重复
70 72 */
71 73 public static String generatePath(byte[] content, String originalName) {
72 74 String sha256Hex = DigestUtil.sha256Hex(content);
73   - // 如果存在name,则优先使用name的后缀
  75 + // 情况一:如果存在 name,则优先使用 name 的后缀
74 76 if (StrUtil.isNotBlank(originalName)) {
75 77 String extName = FileNameUtil.extName(originalName);
76 78 return StrUtil.isBlank(extName) ? sha256Hex : sha256Hex + "." + extName;
77   - } else {
78   - return sha256Hex + '.' + FileTypeUtil.getType(new ByteArrayInputStream(content));
79 79 }
  80 + // 情况二:基于 content 计算
  81 + return sha256Hex + '.' + FileTypeUtil.getType(new ByteArrayInputStream(content));
80 82 }
81 83  
82 84 }
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/file/FileDO.java
... ... @@ -5,8 +5,6 @@ import com.baomidou.mybatisplus.annotation.KeySequence;
5 5 import com.baomidou.mybatisplus.annotation.TableName;
6 6 import lombok.*;
7 7  
8   -import java.io.InputStream;
9   -
10 8 /**
11 9 * 文件表
12 10 * 每次文件上传,都会记录一条记录到该表中
... ... @@ -46,7 +44,7 @@ public class FileDO extends BaseDO {
46 44 */
47 45 private String url;
48 46 /**
49   - * 文件的MIME类型,例如"application/octet-stream"
  47 + * 文件的 MIME 类型,例如 "application/octet-stream"
50 48 */
51 49 private String type;
52 50 /**
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileServiceImpl.java
1 1 package cn.iocoder.yudao.module.infra.service.file;
2 2  
3   -import cn.hutool.core.io.FileUtil;
4 3 import cn.hutool.core.lang.Assert;
5 4 import cn.hutool.core.util.StrUtil;
6 5 import cn.iocoder.yudao.framework.common.pojo.PageResult;
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/vo/AuthSmsLoginReqVO.java
1 1 package cn.iocoder.yudao.module.system.controller.admin.auth.vo;
2 2  
  3 +import cn.iocoder.yudao.framework.common.validation.Mobile;
3 4 import io.swagger.annotations.ApiModel;
4 5 import io.swagger.annotations.ApiModelProperty;
5 6 import lombok.AllArgsConstructor;
6 7 import lombok.Builder;
7 8 import lombok.Data;
8 9 import lombok.NoArgsConstructor;
9   -import org.hibernate.validator.constraints.Length;
10 10  
11 11 import javax.validation.constraints.NotEmpty;
12   -import javax.validation.constraints.Pattern;
13 12  
14   -@ApiModel("管理后台 - 短信验证码的呢老姑 Request VO")
  13 +@ApiModel("管理后台 - 短信验证码的登录 Request VO")
15 14 @Data
16 15 @NoArgsConstructor
17 16 @AllArgsConstructor
... ... @@ -20,19 +19,11 @@ public class AuthSmsLoginReqVO {
20 19  
21 20 @ApiModelProperty(value = "手机号", required = true, example = "yudaoyuanma")
22 21 @NotEmpty(message = "手机号不能为空")
23   - @Length(min = 11, max = 11, message = "手机号格式错误,仅支持大陆手机号")
24   - @Pattern(regexp = "^[1](([3][0-9])|([4][5-9])|([5][0-3,5-9])|([6][5,6])|([7][0-8])|([8][0-9])|([9][1,8,9]))[0-9]{8}$", message = "账号格式为数字以及字母")
  22 + @Mobile
25 23 private String mobile;
26 24  
27   -
28   -
29   - @ApiModelProperty(value = "短信验证码", required = true, example = "1024", notes = "验证码开启时,需要传递")
30   - @NotEmpty(message = "验证码不能为空", groups = CodeEnableGroup.class)
  25 + @ApiModelProperty(value = "短信验证码", required = true, example = "1024")
  26 + @NotEmpty(message = "验证码不能为空")
31 27 private String code;
32 28  
33   - /**
34   - * 开启验证码的 Group
35   - */
36   - public interface CodeEnableGroup {}
37   -
38 29 }
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/user/AdminUserDO.java
... ... @@ -52,7 +52,7 @@ public class AdminUserDO extends TenantBaseDO {
52 52 */
53 53 private String remark;
54 54 /**
55   - * 部门ID
  55 + * 部门 ID
56 56 */
57 57 private Long deptId;
58 58 /**
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImpl.java
... ... @@ -123,7 +123,7 @@ public class AdminAuthServiceImpl implements AdminAuthService {
123 123 throw exception(USER_NOT_EXISTS);
124 124 }
125 125  
126   - // 缓存登陆用户到 Redis 中,返回 sessionId 编号
  126 + // 创建 Token 令牌,记录登录日志
127 127 return createTokenAfterLoginSuccess(user.getId(), reqVO.getMobile(), LoginLogTypeEnum.LOGIN_MOBILE);
128 128 }
129 129  
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java
... ... @@ -87,7 +87,7 @@ public class AdminUserServiceImpl implements AdminUserService {
87 87 // 插入用户
88 88 AdminUserDO user = UserConvert.INSTANCE.convert(reqVO);
89 89 user.setStatus(CommonStatusEnum.ENABLE.getStatus()); // 默认开启
90   - user.setPassword(passwordEncoder.encode(reqVO.getPassword())); // 加密密码
  90 + user.setPassword(encodePassword(reqVO.getPassword())); // 加密密码
91 91 userMapper.insert(user);
92 92 // 插入关联岗位
93 93 if (CollectionUtil.isNotEmpty(user.getPostIds())) {
... ...