Selaa lähdekoodia

增加file.server配置保护措施,强制加上/结尾

luoshi 4 vuotta sitten
vanhempi
commit
6c2c1404bd

+ 3 - 0
stmms-biz/src/main/java/cn/com/qmth/stmms/biz/file/service/impl/FileServiceImpl.java

@@ -210,6 +210,9 @@ public class FileServiceImpl implements FileService, InitializingBean {
         if (fileStore == null) {
             throw new RuntimeException("invald property: ${file.store} should not be empty");
         }
+        if (!fileServer.endsWith("/")) {
+            fileServer = fileServer.concat("/");
+        }
         if (fileStore.startsWith("oss")) {
             store = new OssStore(fileStore);
         } else {

+ 5 - 2
stmms-biz/src/main/java/cn/com/qmth/stmms/biz/file/store/impl/OssStore.java

@@ -25,6 +25,8 @@ public class OssStore implements FileStore {
 
     private static final Logger log = LoggerFactory.getLogger(OssStore.class);
 
+    private static final String ENDPOINT_PREFIX = "https://";
+
     private static final Pattern CONFIG_PATTERN = Pattern.compile("^oss://([\\w]+):([\\w]+)@([\\w-]+).([\\w-.]+)$");
 
     private String endpoint;
@@ -36,7 +38,7 @@ public class OssStore implements FileStore {
     private String accessSecret;
 
     public OssStore(String config) {
-        String message = "[file.store]" + config + " pattern error";
+        String message = "[file.store]" + config + ": pattern error";
         Matcher m = CONFIG_PATTERN.matcher(config);
         if (m.find()) {
             accessKey = StringUtils.trimToNull(m.group(1));
@@ -49,7 +51,7 @@ public class OssStore implements FileStore {
             Assert.notNull(bucket, message);
             Assert.notNull(endpoint, message);
 
-            endpoint = "https://" + endpoint;
+            endpoint = ENDPOINT_PREFIX.concat(endpoint);
         } else {
             throw new IllegalArgumentException(message);
         }
@@ -80,6 +82,7 @@ public class OssStore implements FileStore {
         try {
             return ossClient.doesObjectExist(bucket, path);
         } catch (Exception e) {
+            log.error("oss exist operate error", e);
             return false;
         } finally {
             ossClient.shutdown();