You've already forked FrameTour-BE
refactor(task): 移除视频上传相关代码
- 删除了 TaskTaskServiceImpl 中的视频上传调用 - 移除了 VideoReUploader 中的 addVideoTask 方法和相关代码 - 优化了代码结构,减少了不必要的导入
This commit is contained in:
@@ -492,7 +492,6 @@ public class TaskTaskServiceImpl implements TaskService {
|
|||||||
String hash = MD5.create().digestHex(task.getTaskParams());
|
String hash = MD5.create().digestHex(task.getTaskParams());
|
||||||
String filename = StorageUtil.joinPath(StorageConstant.VLOG_PATH, hash + "_" + task.getScenicId() + ".mp4");
|
String filename = StorageUtil.joinPath(StorageConstant.VLOG_PATH, hash + "_" + task.getScenicId() + ".mp4");
|
||||||
adapter.setAcl(StorageAcl.PUBLIC_READ, filename);
|
adapter.setAcl(StorageAcl.PUBLIC_READ, filename);
|
||||||
videoReUploader.addVideoTask(video.getId());
|
|
||||||
int isBuy = 0;
|
int isBuy = 0;
|
||||||
FaceEntity face = faceRepository.getFace(task.getFaceId());
|
FaceEntity face = faceRepository.getFace(task.getFaceId());
|
||||||
if (face != null) {
|
if (face != null) {
|
||||||
|
@@ -7,15 +7,12 @@ import com.ycwl.basic.mapper.SourceMapper;
|
|||||||
import com.ycwl.basic.mapper.VideoMapper;
|
import com.ycwl.basic.mapper.VideoMapper;
|
||||||
import com.ycwl.basic.model.pc.scenic.entity.ScenicConfigEntity;
|
import com.ycwl.basic.model.pc.scenic.entity.ScenicConfigEntity;
|
||||||
import com.ycwl.basic.model.pc.source.entity.SourceEntity;
|
import com.ycwl.basic.model.pc.source.entity.SourceEntity;
|
||||||
import com.ycwl.basic.model.pc.video.entity.VideoEntity;
|
|
||||||
import com.ycwl.basic.repository.ScenicRepository;
|
import com.ycwl.basic.repository.ScenicRepository;
|
||||||
import com.ycwl.basic.repository.VideoRepository;
|
import com.ycwl.basic.repository.VideoRepository;
|
||||||
import com.ycwl.basic.service.pc.ScenicService;
|
import com.ycwl.basic.service.pc.ScenicService;
|
||||||
import com.ycwl.basic.storage.adapters.IStorageAdapter;
|
import com.ycwl.basic.storage.adapters.IStorageAdapter;
|
||||||
import com.ycwl.basic.storage.enums.StorageAcl;
|
|
||||||
import com.ycwl.basic.storage.utils.StorageUtil;
|
import com.ycwl.basic.storage.utils.StorageUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.apache.commons.lang3.Strings;
|
import org.apache.commons.lang3.Strings;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@@ -94,44 +91,4 @@ public class VideoReUploader {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
public void addVideoTask(Long videoId) {
|
|
||||||
VideoEntity entity = videoMapper.getEntity(videoId);
|
|
||||||
if (entity == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (entity.getScenicId() == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final String dstFilePath = StorageUtil.joinPath(StorageConstant.VLOG_PATH, entity.getTaskId() + "_" + entity.getScenicId() + ".mp4");
|
|
||||||
final IStorageAdapter adapter = scenicService.getScenicStorageAdapter(entity.getScenicId());
|
|
||||||
if (Strings.CS.equals(entity.getVideoUrl(), adapter.getUrl(dstFilePath))) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String tmpFilePath = UUID.randomUUID().toString();
|
|
||||||
executor.execute(() -> {
|
|
||||||
// 先下载,后上传
|
|
||||||
File dstFile = new File(tmpFilePath);
|
|
||||||
log.info("下载视频:{};videoId:{}", entity.getVideoUrl(), videoId);
|
|
||||||
long size = HttpUtil.downloadFile(entity.getVideoUrl(), dstFile);
|
|
||||||
log.info("下载视频完成:{};大小:{};videoId:{}", entity.getVideoUrl(), size, videoId);
|
|
||||||
try {
|
|
||||||
log.info("开始上传:{};videoId:{}", dstFilePath, videoId);
|
|
||||||
String newUrl = adapter.uploadFile("video/mp4", dstFile, dstFilePath);
|
|
||||||
adapter.setAcl(StorageAcl.PUBLIC_READ, dstFilePath);
|
|
||||||
log.info("上传成功:{};videoId:{}", newUrl, videoId);
|
|
||||||
VideoEntity updateEntity = new VideoEntity();
|
|
||||||
updateEntity.setId(videoId);
|
|
||||||
updateEntity.setVideoUrl(newUrl);
|
|
||||||
videoMapper.update(updateEntity);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.info("上传失败:{};videoId:{}", dstFilePath, videoId, e);
|
|
||||||
} finally {
|
|
||||||
videoRepository.clearVideoCache(videoId);
|
|
||||||
try {
|
|
||||||
dstFile.delete();
|
|
||||||
} catch (Exception ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user