fix(文件中心): 增加文件访问过期时间从1小时变为24小时,替换url,取消url后面的参数

This commit is contained in:
2025-07-14 15:26:44 +08:00
parent d8c3239a63
commit 04df758543
2 changed files with 32 additions and 15 deletions
@@ -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;
}
}