fix(文件中心): 增加文件访问过期时间从1小时变为24小时,替换url,取消url后面的参数
This commit is contained in:
+25
-3
@@ -163,7 +163,9 @@ public class OrderController {
|
||||
for (OrderFile orderFile : list){
|
||||
Map<String,String> imgMap = new HashMap<>();
|
||||
String url = fileCenterService.getViewUrlByPath(orderFile.getFilePath());
|
||||
imgMap.put("url", url.replace(cdnOssUrl,cdnUrl));
|
||||
// 去掉URL中的参数并替换域名
|
||||
String cleanUrl = removeUrlParams(url.replace(cdnOssUrl, cdnUrl));
|
||||
imgMap.put("url", cleanUrl);
|
||||
imgMap.put("contentType", orderFile.getFileType());
|
||||
fileMap.put("path",orderFile.getFilePath());
|
||||
imgMap.put("viewUrl", fileCenterService.getViewUrlByPathStyle(fileMap));
|
||||
@@ -584,7 +586,9 @@ public class OrderController {
|
||||
for (OrderFile orderFile : orderFiles) {
|
||||
Map<String, String> fileInfo = new HashMap<>();
|
||||
String url = fileCenterService.getViewUrlByPath(orderFile.getFilePath());
|
||||
fileInfo.put("url", url.replace(cdnOssUrl, cdnUrl));
|
||||
// 去掉URL中的参数并替换域名
|
||||
String cleanUrl = removeUrlParams(url.replace(cdnOssUrl, cdnUrl));
|
||||
fileInfo.put("url", cleanUrl);
|
||||
fileInfo.put("contentType", orderFile.getFileType());
|
||||
fileMap.put("path", orderFile.getFilePath());
|
||||
fileInfo.put("viewUrl", fileCenterService.getViewUrlByPathStyle(fileMap));
|
||||
@@ -662,7 +666,9 @@ public class OrderController {
|
||||
for (String orderFile : list){
|
||||
Map<String,String> imgMap = new HashMap<>();
|
||||
String url = fileCenterService.getViewUrlByPath(orderFile);
|
||||
imgMap.put("url", url.replace(cdnOssUrl,cdnUrl));
|
||||
// 去掉URL中的参数并替换域名
|
||||
String cleanUrl = removeUrlParams(url.replace(cdnOssUrl, cdnUrl));
|
||||
imgMap.put("url", cleanUrl);
|
||||
if (orderFile.endsWith(".jpeg") || orderFile.endsWith(".png")){
|
||||
imgMap.put("contentType", "image/jpeg");
|
||||
}
|
||||
@@ -681,4 +687,20 @@ public class OrderController {
|
||||
}
|
||||
return new PageResult<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除URL中的参数
|
||||
* @param url 原始URL
|
||||
* @return 移除参数后的URL
|
||||
*/
|
||||
private String removeUrlParams(String url) {
|
||||
if (url == null || url.isEmpty()) {
|
||||
return url;
|
||||
}
|
||||
int questionMarkIndex = url.indexOf('?');
|
||||
if (questionMarkIndex != -1) {
|
||||
return url.substring(0, questionMarkIndex);
|
||||
}
|
||||
return url;
|
||||
}
|
||||
}
|
||||
|
||||
+7
-12
@@ -3,12 +3,7 @@ package com.central.oss.template;
|
||||
import com.aliyun.oss.HttpMethod;
|
||||
import com.aliyun.oss.OSS;
|
||||
import com.aliyun.oss.OSSClientBuilder;
|
||||
import com.aliyun.oss.model.GeneratePresignedUrlRequest;
|
||||
import com.aliyun.oss.model.OSSObject;
|
||||
import com.aliyun.oss.model.ObjectMetadata;
|
||||
import com.aliyun.oss.model.ObjectListing;
|
||||
import com.aliyun.oss.model.OSSObjectSummary;
|
||||
import com.aliyun.oss.model.PutObjectRequest;
|
||||
import com.aliyun.oss.model.*;
|
||||
import com.central.oss.model.ObjectInfo;
|
||||
import com.central.oss.properties.FileServerProperties;
|
||||
import lombok.SneakyThrows;
|
||||
@@ -38,7 +33,7 @@ public class OssTemplate implements InitializingBean {
|
||||
|
||||
private static final String DEF_CONTEXT_TYPE = "application/octet-stream";
|
||||
private static final String PATH_SPLIT = "/";
|
||||
private static final int DEFAULT_EXPIRE_TYPE = 60;
|
||||
private static final int DEFAULT_EXPIRE_TYPE = 60 * 24;
|
||||
|
||||
@Autowired
|
||||
private FileServerProperties fileProperties;
|
||||
@@ -218,7 +213,7 @@ public class OssTemplate implements InitializingBean {
|
||||
/**
|
||||
* 获取OSS客户端实例
|
||||
* 用于高级操作,如文件迁移等
|
||||
*
|
||||
*
|
||||
* @return OSS客户端
|
||||
*/
|
||||
public OSS getOssClient() {
|
||||
@@ -227,7 +222,7 @@ public class OssTemplate implements InitializingBean {
|
||||
|
||||
/**
|
||||
* 检查对象是否存在
|
||||
*
|
||||
*
|
||||
* @param bucketName bucket名称
|
||||
* @param objectName 对象名称
|
||||
* @return 是否存在
|
||||
@@ -238,7 +233,7 @@ public class OssTemplate implements InitializingBean {
|
||||
|
||||
/**
|
||||
* 检查默认bucket中的对象是否存在
|
||||
*
|
||||
*
|
||||
* @param objectName 对象名称
|
||||
* @return 是否存在
|
||||
*/
|
||||
@@ -248,7 +243,7 @@ public class OssTemplate implements InitializingBean {
|
||||
|
||||
/**
|
||||
* 获取对象元数据
|
||||
*
|
||||
*
|
||||
* @param bucketName bucket名称
|
||||
* @param objectName 对象名称
|
||||
* @return 对象元数据
|
||||
@@ -259,7 +254,7 @@ public class OssTemplate implements InitializingBean {
|
||||
|
||||
/**
|
||||
* 获取默认bucket中对象的元数据
|
||||
*
|
||||
*
|
||||
* @param objectName 对象名称
|
||||
* @return 对象元数据
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user