Merge branch 'test-training2' of https://git.code.tencent.com/lian-cbtc/rtss-server into test-training2-zhouyin

This commit is contained in:
tiger_zhou 2022-10-11 08:48:05 +08:00
commit 3bf5996bee
5 changed files with 51 additions and 6 deletions

View File

@ -24,6 +24,9 @@ public class MinioClientConfig {
@Value("${minio.bucket}")
private String bucket;
@Value("${minio.replaceHttps}")
private Boolean replaceHttps;
private MinioClient minioClient;
@PostConstruct

View File

@ -105,7 +105,14 @@ public class OrgProjectService implements IOrgProjectService {
if (CollectionUtils.isEmpty(orgUserList)) {
throw new SimulationException(SimulationExceptionType.Illegal_Argument);
}
loginInfo.setOrgProjectVO(new OrgProjectVO(topOrg));
// 是否是顶级组织的管理员
OrgUser orgUser = orgUserList.stream().filter(o -> loginInfo.getAccountVO().getId().longValue() == o.getUserId().longValue()
&& o.getOrgId().longValue() == orgId.longValue()).findFirst().orElse(null);
OrgProjectVO orgProjectVO = new OrgProjectVO(topOrg);
if (orgUser != null) {
orgProjectVO.setRole(orgUser.getRole());
}
loginInfo.setOrgProjectVO(orgProjectVO);
}
@Override

View File

@ -20,12 +20,22 @@ import java.time.LocalDateTime;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
public class MinioClientUtil {
private final static String PATH_SEPARATOR = "/";
private final static String HTTP_PROTOCOL = "http:";
private final static String HTTPS_PROTOCOL = "https:";
/**
* 用来判断生成链接是 http|https:// + IP + : + 端口
*/
private final static Pattern IP_PORT_PATTERN = Pattern.compile("(\\w+):\\/\\/([^/:]+)(:\\d*)");
private MinioClientConfig config;
/**
@ -215,9 +225,10 @@ public class MinioClientUtil {
public String getDownLoadPathByPath(String path) {
try {
return config.getMinioClient().getPresignedObjectUrl(GetPresignedObjectUrlArgs.builder()
String downLoadPath = config.getMinioClient().getPresignedObjectUrl(GetPresignedObjectUrlArgs.builder()
.bucket(config.getBucket())
.object(path).method(Method.GET).build());
return pathProtocolReplace(downLoadPath);
} catch (Exception e) {
throw new SimulationException(SimulationExceptionType.System_Fault, e);
}
@ -230,13 +241,14 @@ public class MinioClientUtil {
try {
Map<String, String> reqParams = new HashMap<String, String>();
reqParams.put("response-content-type", "application/json");
return config.getMinioClient().getPresignedObjectUrl(
String uploadPath = config.getMinioClient().getPresignedObjectUrl(
GetPresignedObjectUrlArgs.builder().method(method)
.bucket(config.getBucket()).object(getSavePath(fileName))
.expiry(60 * 60 * 24)
.extraQueryParams(reqParams)
.build()
);
return pathProtocolReplace(uploadPath);
} catch (Exception e) {
throw new SimulationException(SimulationExceptionType.System_Fault, e);
}
@ -246,6 +258,21 @@ public class MinioClientUtil {
return FileInfo.getStoragePath(directory, fileName);
}
/**
* 替换访问协议
*/
private String pathProtocolReplace(String path) {
String resultPath = path;
// 判断是否是IP加端口模式,替换后会引起问题则不做处理
if (IP_PORT_PATTERN.matcher(path).find()) {
return path;
}
if (config.getReplaceHttps() != null && config.getReplaceHttps() && path.startsWith(HTTP_PROTOCOL)) {
resultPath = path.replace(HTTP_PROTOCOL, HTTPS_PROTOCOL);
}
return resultPath;
}
@Data
public static class FileInfo {
private String fileName;

View File

@ -13,6 +13,8 @@ public class OrgProjectVO {
private Long topOrgId;
private String role;
public OrgProjectVO(Org org) {
this.orgId = org.getId();
this.name = org.getName();

View File

@ -99,10 +99,11 @@ logging:
club.joylink.rtss: DEBUG
minio:
endpoint: https://192.168.3.233
endpoint: http://192.168.3.233
accessKey: jladmin
secretKey: Joylink@0503
bucket: oss-rtss
replaceHttps: true
common:
env: dev
@ -126,10 +127,11 @@ logging:
club.joylink.rtss: INFO
minio:
endpoint: https://192.168.3.233
endpoint: http://192.168.3.233
accessKey: jladmin
secretKey: Joylink@0503
bucket: oss-rtss
replaceHttps: true
common:
env: test
@ -153,10 +155,12 @@ logging:
club.joylink.rtss: INFO
minio:
endpoint: https://192.168.3.233
endpoint: http://192.168.3.233
accessKey: jladmin
secretKey: Joylink@0503
bucket: oss-rtss
replaceHttps: true
common:
env: local
@ -184,6 +188,7 @@ minio:
accessKey: jladmin
secretKey: Joylink@0503
bucket: oss-rtss
replaceHttps: false
common:
env: test
@ -210,6 +215,7 @@ minio:
accessKey: jladmin
secretKey: Joylink@0503
bucket: oss-rtss
replaceHttps: false
common:
env: prd