优化文件的 type 识别与存储

pull/2/head
YunaiV 2022-07-10 00:02:21 +08:00
parent b0d635e1f0
commit 33a31cfb0f
8 changed files with 15 additions and 25 deletions

View File

@ -42,7 +42,7 @@
文档地址:<http://www.iocoder.cn/categories/Yudao/> 文档地址:<http://www.iocoder.cn/categories/Yudao/>
* [《如何搭建环境》](http://www.iocoder.cn/categories/Yudao/?yudao) * [《如何搭建环境》](http://www.iocoder.cn/categories/Yudao/?yudao)
> 未来会补充文档和视频,方便胖友冲冲冲! 视频教程:<https://doc.iocoder.cn/video/>
## 🐼 内置功能 ## 🐼 内置功能

View File

@ -64,19 +64,21 @@ public class FileUtils {
} }
/** /**
*
*
* @param content * @param content
* @param originalName * @param originalName
* @return path * @return path
*/ */
public static String generatePath(byte[] content, String originalName) { public static String generatePath(byte[] content, String originalName) {
String sha256Hex = DigestUtil.sha256Hex(content); String sha256Hex = DigestUtil.sha256Hex(content);
// 如果存在name则优先使用name的后缀 // 情况一:如果存在 name则优先使用 name 的后缀
if (StrUtil.isNotBlank(originalName)) { if (StrUtil.isNotBlank(originalName)) {
String extName = FileNameUtil.extName(originalName); String extName = FileNameUtil.extName(originalName);
return StrUtil.isBlank(extName) ? sha256Hex : sha256Hex + "." + extName; return StrUtil.isBlank(extName) ? sha256Hex : sha256Hex + "." + extName;
} else {
return sha256Hex + '.' + FileTypeUtil.getType(new ByteArrayInputStream(content));
} }
// 情况二:基于 content 计算
return sha256Hex + '.' + FileTypeUtil.getType(new ByteArrayInputStream(content));
} }
} }

View File

@ -5,8 +5,6 @@ import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import lombok.*; import lombok.*;
import java.io.InputStream;
/** /**
* *
* *
@ -46,7 +44,7 @@ public class FileDO extends BaseDO {
*/ */
private String url; private String url;
/** /**
* MIME"application/octet-stream" * MIME "application/octet-stream"
*/ */
private String type; private String type;
/** /**

View File

@ -1,6 +1,5 @@
package cn.iocoder.yudao.module.infra.service.file; package cn.iocoder.yudao.module.infra.service.file;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.lang.Assert; import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;

View File

@ -1,17 +1,16 @@
package cn.iocoder.yudao.module.system.controller.admin.auth.vo; package cn.iocoder.yudao.module.system.controller.admin.auth.vo;
import cn.iocoder.yudao.framework.common.validation.Mobile;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Pattern;
@ApiModel("管理后台 - 短信验证码的呢老姑 Request VO") @ApiModel("管理后台 - 短信验证码的登录 Request VO")
@Data @Data
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@ -20,19 +19,11 @@ public class AuthSmsLoginReqVO {
@ApiModelProperty(value = "手机号", required = true, example = "yudaoyuanma") @ApiModelProperty(value = "手机号", required = true, example = "yudaoyuanma")
@NotEmpty(message = "手机号不能为空") @NotEmpty(message = "手机号不能为空")
@Length(min = 11, max = 11, message = "手机号格式错误,仅支持大陆手机号") @Mobile
@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 = "账号格式为数字以及字母")
private String mobile; private String mobile;
@ApiModelProperty(value = "短信验证码", required = true, example = "1024")
@NotEmpty(message = "验证码不能为空")
@ApiModelProperty(value = "短信验证码", required = true, example = "1024", notes = "验证码开启时,需要传递")
@NotEmpty(message = "验证码不能为空", groups = CodeEnableGroup.class)
private String code; private String code;
/**
* Group
*/
public interface CodeEnableGroup {}
} }

View File

@ -52,7 +52,7 @@ public class AdminUserDO extends TenantBaseDO {
*/ */
private String remark; private String remark;
/** /**
* ID * ID
*/ */
private Long deptId; private Long deptId;
/** /**

View File

@ -123,7 +123,7 @@ public class AdminAuthServiceImpl implements AdminAuthService {
throw exception(USER_NOT_EXISTS); throw exception(USER_NOT_EXISTS);
} }
// 缓存登陆用户到 Redis 中,返回 sessionId 编号 // 创建 Token 令牌,记录登录日志
return createTokenAfterLoginSuccess(user.getId(), reqVO.getMobile(), LoginLogTypeEnum.LOGIN_MOBILE); return createTokenAfterLoginSuccess(user.getId(), reqVO.getMobile(), LoginLogTypeEnum.LOGIN_MOBILE);
} }

View File

@ -87,7 +87,7 @@ public class AdminUserServiceImpl implements AdminUserService {
// 插入用户 // 插入用户
AdminUserDO user = UserConvert.INSTANCE.convert(reqVO); AdminUserDO user = UserConvert.INSTANCE.convert(reqVO);
user.setStatus(CommonStatusEnum.ENABLE.getStatus()); // 默认开启 user.setStatus(CommonStatusEnum.ENABLE.getStatus()); // 默认开启
user.setPassword(passwordEncoder.encode(reqVO.getPassword())); // 加密密码 user.setPassword(encodePassword(reqVO.getPassword())); // 加密密码
userMapper.insert(user); userMapper.insert(user);
// 插入关联岗位 // 插入关联岗位
if (CollectionUtil.isNotEmpty(user.getPostIds())) { if (CollectionUtil.isNotEmpty(user.getPostIds())) {