瀏覽代碼

修改客户端缓存过期时间

xiaofei 2 年之前
父節點
當前提交
0c7d447954

+ 1 - 1
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/TeachcloudCommonServiceImpl.java

@@ -524,7 +524,7 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
                 pathUrl = fileStoreUtil.getPrivateUrl(filePath, uploadFileEnum.getFssType());
             }
         } else {
-            pathUrl = fileStoreUtil.getPrivateUrl(filePath, uploadFileEnum.getFssType());
+            pathUrl = fileStoreUtil.getPrivateUrlExpire(filePath, uploadFileEnum.getFssType(), isExpire);
         }
         map.put("url", pathUrl);
         if (attachment.getType().equals(SystemConstant.HTML_PREFIX)) {

+ 30 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/util/FileStoreUtil.java

@@ -227,6 +227,36 @@ public class FileStoreUtil {
         }
     }
 
+    /**
+     * 获取文件访问url
+     *
+     * @param objectPath 文件路径
+     * @param type       文件上传的类型
+     * @return
+     */
+    public String getPrivateUrlExpire(String objectPath, String type, Boolean isExpire) {
+        String server = null;
+        if ("public".equals(type)) {
+            server = dictionaryConfig.fssPublicDomain().getServer();
+            return server + "/" + objectPath;
+        } else if ("private".equals(type)) {
+            Boolean oss = dictionaryConfig.sysDomain().isOss();
+            if (Objects.nonNull(oss) && oss && dictionaryConfig.fssPrivateDomain().getConfig().startsWith("oss:") &&
+                    (dictionaryConfig.fssPrivateDomain().getServer().startsWith("http:") || dictionaryConfig.fssPrivateDomain().getServer().startsWith("https:"))) {
+                FileStore fileStore = fileService.getFileStore(type);
+                if(isExpire) {
+                    return fileStore.getPresignedUrl(objectPath, Duration.ofMinutes(5L));
+                } else {
+                    return fileStore.getPresignedUrl(objectPath, Duration.ofMinutes(300L));
+                }
+            } else {
+                return dictionaryConfig.fssPrivateDomain().getServer() + "/" + objectPath;
+            }
+        } else {
+            throw ExceptionResultEnum.ERROR.exception("文件存储store类型不存在");
+        }
+    }
+
     /**
      * 根据数据库文件路径判断文件上传类型
      *