From 53e90f652c82fad5302b8ef3c1c37d84a0a231bd Mon Sep 17 00:00:00 2001 From: weizhihong Date: Mon, 10 Oct 2022 17:04:01 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90MINIO=E8=BF=9E=E6=8E=A5=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E6=9B=BF=E6=8D=A2http->https=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rtss/configuration/MinioClientConfig.java | 3 ++ .../rtss/services/org/OrgProjectService.java | 9 +++++- .../joylink/rtss/util/MinioClientUtil.java | 31 +++++++++++++++++-- .../rtss/vo/client/org/OrgProjectVO.java | 2 ++ src/main/resources/application.yml | 12 +++++-- 5 files changed, 51 insertions(+), 6 deletions(-) diff --git a/src/main/java/club/joylink/rtss/configuration/MinioClientConfig.java b/src/main/java/club/joylink/rtss/configuration/MinioClientConfig.java index 4cdc69075..30ccb63be 100644 --- a/src/main/java/club/joylink/rtss/configuration/MinioClientConfig.java +++ b/src/main/java/club/joylink/rtss/configuration/MinioClientConfig.java @@ -24,6 +24,9 @@ public class MinioClientConfig { @Value("${minio.bucket}") private String bucket; + @Value("${minio.replaceHttps}") + private Boolean replaceHttps; + private MinioClient minioClient; @PostConstruct diff --git a/src/main/java/club/joylink/rtss/services/org/OrgProjectService.java b/src/main/java/club/joylink/rtss/services/org/OrgProjectService.java index 16b22acd4..619b8e6ec 100644 --- a/src/main/java/club/joylink/rtss/services/org/OrgProjectService.java +++ b/src/main/java/club/joylink/rtss/services/org/OrgProjectService.java @@ -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 diff --git a/src/main/java/club/joylink/rtss/util/MinioClientUtil.java b/src/main/java/club/joylink/rtss/util/MinioClientUtil.java index b85bb0890..de77eb830 100644 --- a/src/main/java/club/joylink/rtss/util/MinioClientUtil.java +++ b/src/main/java/club/joylink/rtss/util/MinioClientUtil.java @@ -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 reqParams = new HashMap(); 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; diff --git a/src/main/java/club/joylink/rtss/vo/client/org/OrgProjectVO.java b/src/main/java/club/joylink/rtss/vo/client/org/OrgProjectVO.java index 801c1629d..3d0544974 100644 --- a/src/main/java/club/joylink/rtss/vo/client/org/OrgProjectVO.java +++ b/src/main/java/club/joylink/rtss/vo/client/org/OrgProjectVO.java @@ -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(); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 58a57d051..e051eee67 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -97,10 +97,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 @@ -124,10 +125,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 @@ -151,10 +153,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 @@ -182,6 +186,7 @@ minio: accessKey: jladmin secretKey: Joylink@0503 bucket: oss-rtss + replaceHttps: false common: env: test @@ -208,6 +213,7 @@ minio: accessKey: jladmin secretKey: Joylink@0503 bucket: oss-rtss + replaceHttps: false common: env: prd