You've already forked FrameTour-BE
区分临时和本地存储
This commit is contained in:
@@ -4,9 +4,16 @@ import cn.hutool.core.thread.ThreadFactoryBuilder;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.ycwl.basic.constant.StorageConstant;
|
||||
import com.ycwl.basic.mapper.SourceMapper;
|
||||
import com.ycwl.basic.mapper.VideoMapper;
|
||||
import com.ycwl.basic.model.pc.scenic.entity.ScenicConfigEntity;
|
||||
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.VideoRepository;
|
||||
import com.ycwl.basic.repository.VideoTaskRepository;
|
||||
import com.ycwl.basic.service.pc.ScenicService;
|
||||
import com.ycwl.basic.storage.adapters.IStorageAdapter;
|
||||
import com.ycwl.basic.storage.enums.StorageAcl;
|
||||
import com.ycwl.basic.storage.utils.StorageUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -43,16 +50,14 @@ public class VideoReUploader {
|
||||
private SourceMapper sourceMapper;
|
||||
@Autowired
|
||||
private ScenicService scenicService;
|
||||
@Autowired
|
||||
private VideoMapper videoMapper;
|
||||
@Autowired
|
||||
private VideoRepository videoRepository;
|
||||
@Autowired
|
||||
private ScenicRepository scenicRepository;
|
||||
|
||||
public void addTask(String url, Long sourceId) {
|
||||
try {
|
||||
URL _url = new URL(url);
|
||||
if (!StringUtils.startsWith(_url.getHost(), "100.64.")) {
|
||||
return;
|
||||
}
|
||||
} catch (MalformedURLException ignored) {
|
||||
return;
|
||||
}
|
||||
SourceEntity entity = sourceMapper.getEntity(sourceId);
|
||||
if (entity == null) {
|
||||
return;
|
||||
@@ -63,6 +68,15 @@ public class VideoReUploader {
|
||||
if (entity.getType() != 1) {
|
||||
return;
|
||||
}
|
||||
ScenicConfigEntity scenicConfig = scenicRepository.getScenicConfig(entity.getScenicId());
|
||||
if (scenicConfig == null || scenicConfig.getLocalStoreType() == null || scenicConfig.getLocalStoreConfigJson() == null) {
|
||||
return;
|
||||
}
|
||||
final String dstFilePath = StorageUtil.joinPath(StorageConstant.VIDEO_PIECE_PATH, entity.getId().toString() + ".mp4");
|
||||
final IStorageAdapter adapter = scenicService.getScenicStorageAdapter(entity.getScenicId());
|
||||
if (StringUtils.equals(url, adapter.getUrl(dstFilePath))) {
|
||||
return;
|
||||
}
|
||||
String tmpFilePath = UUID.randomUUID().toString();
|
||||
executor.execute(() -> {
|
||||
// 先下载,后上传
|
||||
@@ -70,11 +84,9 @@ public class VideoReUploader {
|
||||
log.info("下载视频:{};sourceId:{}", url, sourceId);
|
||||
long size = HttpUtil.downloadFile(url, dstFile);
|
||||
log.info("下载视频完成:{};大小:{};sourceId:{}", url, size, sourceId);
|
||||
String dstFilePath = StorageUtil.joinPath(StorageConstant.VIDEO_PIECE_PATH, entity.getId().toString() + ".mp4");
|
||||
IStorageAdapter dstAdapter = scenicService.getScenicStorageAdapter(entity.getScenicId());
|
||||
try {
|
||||
log.info("开始上传:{};sourceId:{}", dstFilePath, sourceId);
|
||||
String newUrl = dstAdapter.uploadFile("video/mp4", dstFile, dstFilePath);
|
||||
String newUrl = adapter.uploadFile("video/mp4", dstFile, dstFilePath);
|
||||
log.info("上传成功:{};sourceId:{}", newUrl, sourceId);
|
||||
SourceEntity updateEntity = new SourceEntity();
|
||||
updateEntity.setId(sourceId);
|
||||
@@ -90,4 +102,48 @@ public class VideoReUploader {
|
||||
}
|
||||
});
|
||||
}
|
||||
public void addVideoTask(String url, Long videoId) {
|
||||
VideoEntity entity = videoMapper.getEntity(videoId);
|
||||
if (entity == null) {
|
||||
return;
|
||||
}
|
||||
if (entity.getScenicId() == null) {
|
||||
return;
|
||||
}
|
||||
ScenicConfigEntity scenicConfig = scenicRepository.getScenicConfig(entity.getScenicId());
|
||||
if (scenicConfig == null || scenicConfig.getTmpStoreType() == null || scenicConfig.getTmpStoreConfigJson() == null) {
|
||||
return;
|
||||
}
|
||||
final String dstFilePath = StorageUtil.joinPath(StorageConstant.VLOG_PATH, entity.getTaskId() + "_" + entity.getScenicId() + ".mp4");
|
||||
final IStorageAdapter adapter = scenicService.getScenicStorageAdapter(entity.getScenicId());
|
||||
if (StringUtils.equals(url, adapter.getUrl(dstFilePath))) {
|
||||
return;
|
||||
}
|
||||
String tmpFilePath = UUID.randomUUID().toString();
|
||||
executor.execute(() -> {
|
||||
// 先下载,后上传
|
||||
File dstFile = new File(tmpFilePath);
|
||||
log.info("下载视频:{};videoId:{}", url, videoId);
|
||||
long size = HttpUtil.downloadFile(url, dstFile);
|
||||
log.info("下载视频完成:{};大小:{};videoId:{}", url, 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