Test #2
+19
-1
@@ -6,6 +6,7 @@ import com.aliyuncs.cdn.model.v20180510.*;
|
||||
import com.aliyuncs.profile.DefaultProfile;
|
||||
import com.central.file.config.CdnConfig;
|
||||
import com.central.file.service.ICdnService;
|
||||
import com.central.file.utils.CdnUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -14,6 +15,7 @@ import org.springframework.util.CollectionUtils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* CDN服务实现类
|
||||
@@ -94,9 +96,25 @@ public class CdnServiceImpl implements ICdnService {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 过滤掉视频文件:视频体积大且点播命中率低,预热会造成大量CDN回源流量
|
||||
List<String> nonVideoUrls = urls.stream()
|
||||
.filter(url -> {
|
||||
if (CdnUtils.isVideoFile(url)) {
|
||||
log.info("跳过视频文件预热: {}", url);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (nonVideoUrls.isEmpty()) {
|
||||
log.info("过滤后无需要预热的文件(均为视频),跳过预热");
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
PushObjectCacheRequest request = new PushObjectCacheRequest();
|
||||
request.setObjectPath(String.join("\n", urls));
|
||||
request.setObjectPath(String.join("\n", nonVideoUrls));
|
||||
if (area != null && !area.isEmpty()) {
|
||||
request.setArea(area);
|
||||
}
|
||||
|
||||
+15
-1
@@ -477,9 +477,14 @@ public class OrderFileController {
|
||||
return;
|
||||
}
|
||||
|
||||
// 收集所有文件的URL
|
||||
// 收集所有文件的URL(跳过视频文件,视频不做预热,避免CDN回源流量暴增)
|
||||
List<String> fileUrls = new ArrayList<>();
|
||||
for (OrderFile orderFile : orderFiles) {
|
||||
// 跳过视频文件:视频体积大且点播命中率低,预热会造成大量CDN回源流量
|
||||
if (isVideoFile(orderFile.getFileType())) {
|
||||
log.debug("跳过视频文件预热,文件路径: {}, 类型: {}", orderFile.getFilePath(), orderFile.getFileType());
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
String viewUrl = fileCenterService.getViewUrlByPath(orderFile.getFilePath());
|
||||
if (viewUrl != null && !viewUrl.trim().isEmpty()) {
|
||||
@@ -532,6 +537,15 @@ public class OrderFileController {
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为视频文件
|
||||
* @param fileType 文件类型(如 video/mp4、image/jpeg)
|
||||
* @return 是否为视频
|
||||
*/
|
||||
private boolean isVideoFile(String fileType) {
|
||||
return fileType != null && fileType.startsWith("video/");
|
||||
}
|
||||
|
||||
|
||||
@Operation(summary = "删除文件")
|
||||
@DeleteMapping( "/{id}")
|
||||
|
||||
Reference in New Issue
Block a user