mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-09-13 02:57:13 +08:00
refactor: 优化登录验证码开关代码
This commit is contained in:
@@ -18,9 +18,7 @@ package top.continew.admin.auth.model.req;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import org.checkerframework.checker.units.qual.N;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
@@ -52,20 +50,15 @@ public class AccountLoginReq implements Serializable {
|
||||
@NotBlank(message = "密码不能为空")
|
||||
private String password;
|
||||
|
||||
@Schema(description = "是否开启验证码", example = "true")
|
||||
private Boolean unCaptcha;
|
||||
|
||||
/**
|
||||
* 验证码
|
||||
*/
|
||||
@Schema(description = "验证码", example = "ABCD")
|
||||
// @NotBlank(message = "验证码不能为空")
|
||||
private String captcha;
|
||||
|
||||
/**
|
||||
* 验证码标识
|
||||
*/
|
||||
@Schema(description = "验证码标识", example = "090b9a2c-1691-4fca-99db-e4ed0cff362f")
|
||||
// @NotBlank(message = "验证码标识不能为空")
|
||||
private String uuid;
|
||||
}
|
||||
|
@@ -54,4 +54,22 @@ public class CaptchaResp implements Serializable {
|
||||
*/
|
||||
@Schema(description = "过期时间戳", example = "1714376969409")
|
||||
private Long expireTime;
|
||||
|
||||
/**
|
||||
* 是否启用
|
||||
*/
|
||||
@Schema(description = "是否启用", example = "true")
|
||||
private Boolean isEnabled;
|
||||
|
||||
/**
|
||||
* 构建验证码信息
|
||||
*
|
||||
* @param uuid 验证码标识
|
||||
* @param img 验证码图片(Base64编码,带图片格式:data:image/gif;base64)
|
||||
* @param expireTime 过期时间戳
|
||||
* @return 验证码信息
|
||||
*/
|
||||
public static CaptchaResp of(String uuid, String img, Long expireTime) {
|
||||
return CaptchaResp.builder().uuid(uuid).img(img).expireTime(expireTime).isEnabled(true).build();
|
||||
}
|
||||
}
|
||||
|
@@ -40,7 +40,7 @@ public enum OptionCategoryEnum {
|
||||
MAIL,
|
||||
|
||||
/**
|
||||
* 验证码配置
|
||||
* 登录配置
|
||||
*/
|
||||
CAPTCHA,
|
||||
LOGIN,
|
||||
}
|
||||
|
@@ -94,20 +94,20 @@ public class FileDO extends BaseDO {
|
||||
fileInfo.setUrl(this.url);
|
||||
fileInfo.setSize(this.size);
|
||||
fileInfo.setFilename(StrUtil.contains(this.url, StringConstants.SLASH)
|
||||
? StrUtil.subAfter(this.url, StringConstants.SLASH, true)
|
||||
: this.url);
|
||||
? StrUtil.subAfter(this.url, StringConstants.SLASH, true)
|
||||
: this.url);
|
||||
fileInfo.setOriginalFilename(StrUtils
|
||||
.blankToDefault(this.extension, this.name, ex -> this.name + StringConstants.DOT + ex));
|
||||
.blankToDefault(this.extension, this.name, ex -> this.name + StringConstants.DOT + ex));
|
||||
fileInfo.setBasePath(StringConstants.EMPTY);
|
||||
// 优化 path 处理
|
||||
fileInfo.setPath(extractRelativePath(this.url,storageDO));
|
||||
fileInfo.setPath(extractRelativePath(this.url, storageDO));
|
||||
|
||||
fileInfo.setExt(this.extension);
|
||||
fileInfo.setPlatform(storageDO.getCode());
|
||||
fileInfo.setThUrl(this.thumbnailUrl);
|
||||
fileInfo.setThFilename(StrUtil.contains(this.thumbnailUrl, StringConstants.SLASH)
|
||||
? StrUtil.subAfter(this.thumbnailUrl, StringConstants.SLASH, true)
|
||||
: this.thumbnailUrl);
|
||||
? StrUtil.subAfter(this.thumbnailUrl, StringConstants.SLASH, true)
|
||||
: this.thumbnailUrl);
|
||||
fileInfo.setThSize(this.thumbnailSize);
|
||||
return fileInfo;
|
||||
}
|
||||
@@ -117,22 +117,21 @@ public class FileDO extends BaseDO {
|
||||
* 例如:
|
||||
* http://domain.cn/bucketName/2024/11/27/6746ec3b2907f0de80afdd70.png => 2024/11/27/
|
||||
* http://bucketName.domain.cn/2024/11/27/6746ec3b2907f0de80afdd70.png => 2024/11/27/
|
||||
* @param url 文件路径
|
||||
*
|
||||
* @param url 文件路径
|
||||
* @param storageDO 存储桶信息
|
||||
* @return
|
||||
*/
|
||||
@SneakyThrows
|
||||
private static String extractRelativePath(String url, StorageDO storageDO) {
|
||||
url = StrUtil.subBefore(url, StringConstants.SLASH, true) + StringConstants.SLASH;
|
||||
if (storageDO.getType().equals(StorageTypeEnum.LOCAL)){
|
||||
return url;
|
||||
}
|
||||
url = StrUtil.subBefore(url, StringConstants.SLASH, true) + StringConstants.SLASH;
|
||||
if (storageDO.getType().equals(StorageTypeEnum.LOCAL)) {
|
||||
return url;
|
||||
}
|
||||
// 提取 URL 中的路径部分
|
||||
String fullPath = new URL(url).getPath();
|
||||
// 移除开头的斜杠
|
||||
String relativePath = fullPath.startsWith(StringConstants.SLASH)
|
||||
? fullPath.substring(1)
|
||||
: fullPath;
|
||||
String relativePath = fullPath.startsWith(StringConstants.SLASH) ? fullPath.substring(1) : fullPath;
|
||||
// 如果路径以 bucketName 开头,则移除 bucketName 例如: bucketName/2024/11/27/ -> 2024/11/27/
|
||||
if (relativePath.startsWith(storageDO.getBucketName())) {
|
||||
return StrUtil.split(relativePath, storageDO.getBucketName()).get(1);
|
||||
|
Reference in New Issue
Block a user