mirror of
https://github.com/thousmile/molly-multi-tenant.git
synced 2025-12-30 04:32:26 +00:00
1.更新 x-file-storage 的版本
2.给前端提供,上传token,可直连oss服务商
This commit is contained in:
@@ -25,7 +25,6 @@ public class JwtConst {
|
||||
String.format("%s/**", CAPTCHA_CODES_URL),
|
||||
String.format("%s/**", STOMP_ENDPOINT),
|
||||
"/actuator/**",
|
||||
"/sys/tenant/simple/search",
|
||||
"/v2/api-docs",
|
||||
"/v3/api-docs/**",
|
||||
"/doc.html",
|
||||
@@ -39,4 +38,11 @@ public class JwtConst {
|
||||
"/error/**"
|
||||
};
|
||||
|
||||
|
||||
// 不需要添加租户的路径
|
||||
public static final String[] TENANT_WHITE_LIST = {
|
||||
"/upload/**",
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.xaaef.molly.common.util;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.util.DefaultIndenter;
|
||||
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
@@ -98,7 +100,9 @@ public class JsonUtils {
|
||||
*/
|
||||
public static String toFormatJson(Object data) {
|
||||
try {
|
||||
return MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(data);
|
||||
var prettyPrinter = new DefaultPrettyPrinter();
|
||||
prettyPrinter.indentArraysWith(DefaultIndenter.SYSTEM_LINEFEED_INSTANCE);
|
||||
return MAPPER.writer().with(prettyPrinter).writeValueAsString(data);
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.xaaef.molly;
|
||||
|
||||
import cn.xuyanwu.spring.file.storage.spring.EnableFileStorage;
|
||||
import org.dromara.x.file.storage.spring.EnableFileStorage;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@@ -28,8 +28,8 @@ spring:
|
||||
time-to-live: 180s
|
||||
|
||||
|
||||
#文件存储配置
|
||||
file-storage:
|
||||
dromara:
|
||||
x-file-storage: #文件存储配置
|
||||
default-platform: qiniu-kodo-1 #默认使用的存储平台
|
||||
thumbnail-suffix: ".min.jpg" #缩略图后缀,例如【.min.jpg】【.png】
|
||||
qiniu-kodo: # 七牛云 kodo
|
||||
@@ -81,3 +81,4 @@ knife4j:
|
||||
setting:
|
||||
language: zh_cn
|
||||
version: 1.0.1
|
||||
|
||||
|
||||
@@ -35,8 +35,8 @@ spring:
|
||||
|
||||
|
||||
|
||||
#文件存储配置
|
||||
file-storage:
|
||||
dromara:
|
||||
x-file-storage: #文件存储配置
|
||||
default-platform: qiniu-kodo-1 #默认使用的存储平台
|
||||
thumbnail-suffix: ".min.jpg" #缩略图后缀,例如【.min.jpg】【.png】
|
||||
qiniu-kodo: # 七牛云 kodo
|
||||
|
||||
@@ -30,6 +30,21 @@ spring:
|
||||
time-to-live: 180s
|
||||
|
||||
|
||||
dromara:
|
||||
x-file-storage: #文件存储配置
|
||||
default-platform: qiniu-kodo-1 #默认使用的存储平台
|
||||
thumbnail-suffix: ".min.jpg" #缩略图后缀,例如【.min.jpg】【.png】
|
||||
qiniu-kodo: # 七牛云 kodo
|
||||
- platform: qiniu-kodo-1 # 存储平台标识
|
||||
enable-storage: true # 启用存储
|
||||
access-key: 123456
|
||||
secret-key: 123456
|
||||
bucket-name: 123456
|
||||
domain: https://oss.baidu.com/ # 访问域名,注意“/”结尾,例如:http://abc.hn-bkt.clouddn.com/
|
||||
base-path: molly/ # 基础路径
|
||||
|
||||
|
||||
|
||||
# mybatis-plus 日志打印
|
||||
mybatis-plus:
|
||||
configuration:
|
||||
|
||||
@@ -7,6 +7,7 @@ import cn.hutool.core.lang.tree.TreeUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.mysql.cj.jdbc.MysqlDataSource;
|
||||
import com.xaaef.molly.auth.jwt.JwtSecurityUtils;
|
||||
import com.xaaef.molly.common.consts.JwtConst;
|
||||
import com.xaaef.molly.common.util.JsonUtils;
|
||||
import liquibase.integration.spring.MultiTenantSpringLiquibase;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -17,7 +18,10 @@ import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static com.xaaef.molly.common.util.IpUtils.getLocalIPS;
|
||||
|
||||
@@ -105,4 +109,20 @@ public class NoSpringTests {
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void test11() throws Exception {
|
||||
// 登录接口,也需要,添加租户ID
|
||||
var whiteList = Stream.of(JwtConst.WHITE_LIST, JwtConst.TENANT_WHITE_LIST)
|
||||
.flatMap(Stream::of)
|
||||
.filter(s -> !JwtConst.LOGIN_URL.equals(s))
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
String formatJson = JsonUtils.toFormatJson(Map.of(
|
||||
"data", whiteList,
|
||||
"time", LocalTime.now()
|
||||
));
|
||||
System.out.println(formatJson);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -54,8 +54,8 @@
|
||||
|
||||
<!-- spring-file-storage 必须要引入 -->
|
||||
<dependency>
|
||||
<groupId>cn.xuyanwu</groupId>
|
||||
<artifactId>spring-file-storage</artifactId>
|
||||
<groupId>org.dromara.x-file-storage</groupId>
|
||||
<artifactId>x-file-storage-spring</artifactId>
|
||||
<version>${storage.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
package com.xaaef.molly.system.controller;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.xuyanwu.spring.file.storage.FileStorageService;
|
||||
import com.xaaef.molly.common.util.JsonResult;
|
||||
import com.xaaef.molly.system.po.ImageSizePO;
|
||||
import com.xaaef.molly.system.vo.FileInfoVO;
|
||||
import com.xaaef.molly.system.vo.FileUploadTokenVO;
|
||||
import com.xaaef.molly.web.repeat.NoRepeatSubmit;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.dromara.x.file.storage.core.FileStorageService;
|
||||
import org.dromara.x.file.storage.core.platform.QiniuKodoFileStorage;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.time.LocalDate;
|
||||
@@ -38,7 +37,6 @@ public class FileUploadController {
|
||||
|
||||
private final FileStorageService storageService;
|
||||
|
||||
|
||||
/**
|
||||
* 上传文件,成功返回文件 url
|
||||
*/
|
||||
@@ -119,6 +117,25 @@ public class FileUploadController {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取文件上传使用的token
|
||||
*/
|
||||
@NoRepeatSubmit
|
||||
@Operation(summary = "获取上传Token", description = "获取文件上传Token")
|
||||
@GetMapping("/token")
|
||||
public JsonResult<FileUploadTokenVO> uploadToken() {
|
||||
var fileStorage = (QiniuKodoFileStorage) storageService.getFileStorage();
|
||||
var uploadToken = fileStorage.getClient().getAuth().uploadToken(fileStorage.getBucketName());
|
||||
var result = new FileUploadTokenVO()
|
||||
.setToken(uploadToken)
|
||||
.setPlatform(fileStorage.getPlatform())
|
||||
.setBucketName(fileStorage.getBucketName())
|
||||
.setDomain(fileStorage.getDomain())
|
||||
.setBasePath(fileStorage.getBasePath());
|
||||
return JsonResult.success(result);
|
||||
}
|
||||
|
||||
|
||||
private static final String IMAGE_REG = ".+(.JPEG|.jpeg|.JPG|.jpg|.png|.PNG|.bmp|.BMP|.webp|.WEBP)$";
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,10 +5,8 @@ import com.xaaef.molly.system.entity.SysTenant;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
|
||||
public interface SysTenantMapper extends BaseMapper<SysTenant> {
|
||||
|
||||
@@ -3,8 +3,6 @@ package com.xaaef.molly.system.service.impl;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.lang.Dict;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.xuyanwu.spring.file.storage.FileInfo;
|
||||
import cn.xuyanwu.spring.file.storage.recorder.FileRecorder;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.xaaef.molly.common.util.JsonUtils;
|
||||
@@ -12,6 +10,8 @@ import com.xaaef.molly.system.entity.SysFileDetail;
|
||||
import com.xaaef.molly.system.mapper.SysFileDetailMapper;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.x.file.storage.core.FileInfo;
|
||||
import org.dromara.x.file.storage.core.recorder.FileRecorder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.xaaef.molly.system.vo;
|
||||
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
|
||||
/**
|
||||
* 文件上传token。给前端使用,前端直接上传到 oss 服务器。无需经过后端
|
||||
*
|
||||
* @author WangChenChen
|
||||
* @version 2.0
|
||||
* @date 2023/11/10 17:59
|
||||
*/
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@Accessors(chain = true)
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class FileUploadTokenVO {
|
||||
|
||||
@Schema(description = "上传凭证")
|
||||
private String token;
|
||||
|
||||
@Schema(description = "OSS服务提供商")
|
||||
private String platform;
|
||||
|
||||
@Schema(description = "桶名称")
|
||||
private String bucketName;
|
||||
|
||||
@Schema(description = "自定义域名")
|
||||
private String domain;
|
||||
|
||||
@Schema(description = "前缀路径")
|
||||
private String basePath;
|
||||
|
||||
}
|
||||
@@ -29,8 +29,12 @@ import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static com.xaaef.molly.common.util.IpUtils.getLocalIPS;
|
||||
|
||||
@@ -72,8 +76,10 @@ public class CustomSpringWebConfig implements WebMvcConfigurer {
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
// 登录接口,也需要,添加租户ID
|
||||
var whiteList = Arrays.stream(JwtConst.WHITE_LIST)
|
||||
var whiteList = Stream.of(JwtConst.WHITE_LIST, JwtConst.TENANT_WHITE_LIST)
|
||||
.flatMap(Stream::of)
|
||||
.filter(s -> !JwtConst.LOGIN_URL.equals(s))
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
var multiTenantProperties = tenantService.getByMultiTenantProperties();
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
|
||||
<!-- spring-file-storage -->
|
||||
<storage.version>1.0.3</storage.version>
|
||||
<storage.version>2.0.0</storage.version>
|
||||
<qiniu.version>7.14.0</qiniu.version>
|
||||
<oshi.version>6.4.6</oshi.version>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user