混剪优化

This commit is contained in:
2025-12-07 00:10:22 +08:00
parent 0fffd787bb
commit 7f7551f74f
14 changed files with 479 additions and 113 deletions

View File

@@ -85,4 +85,12 @@ public interface FileService {
*/
byte[] getFileContent(Long configId, String path) throws Exception;
/**
* 根据OSS URL删除文件
*
* @param ossUrl OSS文件完整URL
* @throws Exception 删除失败时抛出异常
*/
void deleteFileByUrl(String ossUrl) throws Exception;
}

View File

@@ -18,6 +18,7 @@ import cn.iocoder.yudao.module.infra.framework.file.core.utils.FileTypeUtils;
import com.google.common.annotations.VisibleForTesting;
import jakarta.annotation.Resource;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.List;
@@ -31,6 +32,7 @@ import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.FILE_NOT_EX
*
* @author 芋道源码
*/
@Slf4j
@Service
public class FileServiceImpl implements FileService {
@@ -198,4 +200,44 @@ public class FileServiceImpl implements FileService {
return client.getContent(path);
}
@Override
public void deleteFileByUrl(String ossUrl) throws Exception {
if (StrUtil.isEmpty(ossUrl)) {
return;
}
// 从URL中提取相对路径
// 例如: https://bucket.oss-region.aliyuncs.com/mix/20241206/video.mp4
// 需要提取出: mix/20241206/video.mp4
String path = extractPathFromUrl(ossUrl);
if (StrUtil.isEmpty(path)) {
log.warn("[FileService][删除文件][URL解析路径失败] ossUrl={}", ossUrl);
return;
}
// 使用默认的master客户端删除文件
FileClient client = fileConfigService.getMasterFileClient();
Assert.notNull(client, "客户端(master) 不能为空");
client.delete(path);
log.info("[FileService][删除文件成功] path={}, ossUrl={}", path, ossUrl);
}
/**
* 从OSS URL中提取相对路径
*/
private String extractPathFromUrl(String ossUrl) {
if (StrUtil.isEmpty(ossUrl)) {
return null;
}
// 查找 ".aliyuncs.com/" 的位置
int index = ossUrl.indexOf(".aliyuncs.com/");
if (index == -1) {
return null;
}
// 提取 "/" 后的路径
return ossUrl.substring(index + ".aliyuncs.com/".length());
}
}