fix: 文件上传失败问题
This commit is contained in:
@@ -46,11 +46,7 @@ public class VideoChunkUploadServiceImpl implements VideoChunkUploadService {
|
||||
|
||||
@Override
|
||||
public List<Integer> checkUploadedChunks(String fileHash) {
|
||||
RSet<Integer> rSet = RedisUtils.getClient().getSet(CHUNK_KEY_PREFIX + fileHash);
|
||||
Set<Integer> uploaded = rSet.readAll();
|
||||
List<Integer> result = new ArrayList<>(uploaded);
|
||||
result.sort(Integer::compareTo);
|
||||
return result;
|
||||
return getUploadedChunkIndexes(fileHash);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -79,8 +75,8 @@ public class VideoChunkUploadServiceImpl implements VideoChunkUploadService {
|
||||
return Collections.singletonMap("taskId", saveCompletedTask(bo.getFileHash(), bo.getFileName(), cachedM3u8Url));
|
||||
}
|
||||
|
||||
RSet<Integer> uploadedSet = RedisUtils.getClient().getSet(CHUNK_KEY_PREFIX + bo.getFileHash());
|
||||
Set<Integer> uploaded = uploadedSet.readAll();
|
||||
List<Integer> uploadedChunkIndexes = getUploadedChunkIndexes(bo.getFileHash());
|
||||
Set<Integer> uploaded = new HashSet<>(uploadedChunkIndexes);
|
||||
for (int i = 0; i < bo.getTotalChunks(); i++) {
|
||||
if (!uploaded.contains(i)) {
|
||||
throw new ServiceException("存在未上传完成的分片,无法合并");
|
||||
@@ -261,6 +257,30 @@ public class VideoChunkUploadServiceImpl implements VideoChunkUploadService {
|
||||
RedisUtils.setCacheObject(TASK_KEY_PREFIX + taskInfo.getTaskId(), taskInfo, properties.taskExpireDuration());
|
||||
}
|
||||
|
||||
private List<Integer> getUploadedChunkIndexes(String fileHash) {
|
||||
File chunkDir = getChunkDir(fileHash);
|
||||
if (!chunkDir.exists() || !chunkDir.isDirectory()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
File[] chunkFiles = chunkDir.listFiles();
|
||||
if (chunkFiles == null || chunkFiles.length == 0) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<Integer> result = new ArrayList<>();
|
||||
for (File chunkFile : chunkFiles) {
|
||||
if (chunkFile == null || !chunkFile.isFile()) {
|
||||
continue;
|
||||
}
|
||||
String fileName = chunkFile.getName();
|
||||
if (!fileName.matches("\\d+")) {
|
||||
continue;
|
||||
}
|
||||
result.add(Integer.parseInt(fileName));
|
||||
}
|
||||
result.sort(Integer::compareTo);
|
||||
return result;
|
||||
}
|
||||
|
||||
private String getResolvedM3u8Url(String fileHash) {
|
||||
String cachedM3u8Url = RedisUtils.getCacheObject(RESULT_KEY_PREFIX + fileHash);
|
||||
if (isOssUrl(cachedM3u8Url)) {
|
||||
|
||||
Reference in New Issue
Block a user