区分临时和本地存储
This commit is contained in:
parent
d0d4e37526
commit
b5b9064f30
@ -40,7 +40,7 @@ public class VptController {
|
||||
}
|
||||
@PostMapping("/scenic/{scenicId}/{taskId}/uploadUrl")
|
||||
public String uploadUrl(@PathVariable("scenicId") Long scenicId, @PathVariable("taskId") Long taskId) {
|
||||
IStorageAdapter adapter = scenicService.getScenicTmpStorageAdapter(scenicId);
|
||||
IStorageAdapter adapter = scenicService.getScenicLocalStorageAdapter(scenicId);
|
||||
String filename = StorageUtil.joinPath(StorageConstant.VIDEO_PIECE_PATH, taskId.toString() + ".mp4");
|
||||
String urlForUpload = adapter.getUrlForUpload(new Date(System.currentTimeMillis() + 1000 * 60 * 60), "video/mp4", filename);
|
||||
urlForUpload = urlForUpload.replace("-internal.aliyuncs.com", ".aliyuncs.com");
|
||||
@ -48,7 +48,7 @@ public class VptController {
|
||||
}
|
||||
@PostMapping("/scenic/{scenicId}/{taskId}/success")
|
||||
public ApiResponse<String> success(@PathVariable("scenicId") Long scenicId, @PathVariable("taskId") Long taskId, @RequestBody FileObject fileObject) {
|
||||
IStorageAdapter adapter = scenicService.getScenicTmpStorageAdapter(scenicId);
|
||||
IStorageAdapter adapter = scenicService.getScenicLocalStorageAdapter(scenicId);
|
||||
String filename = StorageUtil.joinPath(StorageConstant.VIDEO_PIECE_PATH, taskId.toString() + ".mp4");
|
||||
fileObject.setUrl(adapter.getUrl(filename));
|
||||
adapter.setAcl(StorageAcl.PUBLIC_READ, filename);
|
||||
|
@ -45,7 +45,7 @@ public class WvpController {
|
||||
|
||||
@PostMapping("/scenic/{scenicId}/{taskId}/uploadUrl")
|
||||
public String uploadUrl(@PathVariable("scenicId") Long scenicId, @PathVariable("taskId") Long taskId) {
|
||||
IStorageAdapter adapter = scenicService.getScenicTmpStorageAdapter(scenicId);
|
||||
IStorageAdapter adapter = scenicService.getScenicLocalStorageAdapter(scenicId);
|
||||
String filename = StorageUtil.joinPath(StorageConstant.VIDEO_PIECE_PATH, taskId.toString() + ".mp4");
|
||||
String urlForUpload = adapter.getUrlForUpload(new Date(System.currentTimeMillis() + 1000 * 60 * 60), "video/mp4", filename);
|
||||
urlForUpload = urlForUpload.replace("-internal.aliyuncs.com", ".aliyuncs.com");
|
||||
@ -53,7 +53,7 @@ public class WvpController {
|
||||
}
|
||||
@PostMapping("/scenic/{scenicId}/{taskId}/success")
|
||||
public ApiResponse<String> success(@PathVariable("scenicId") Long scenicId, @PathVariable("taskId") Long taskId, @RequestBody FileObject fileObject) {
|
||||
IStorageAdapter adapter = scenicService.getScenicTmpStorageAdapter(scenicId);
|
||||
IStorageAdapter adapter = scenicService.getScenicLocalStorageAdapter(scenicId);
|
||||
String filename = StorageUtil.joinPath(StorageConstant.VIDEO_PIECE_PATH, taskId.toString() + ".mp4");
|
||||
fileObject.setUrl(adapter.getUrl(filename));
|
||||
adapter.setAcl(StorageAcl.PUBLIC_READ, filename);
|
||||
|
@ -73,6 +73,8 @@ public class ScenicConfigEntity {
|
||||
private String storeConfigJson;
|
||||
private StorageType tmpStoreType;
|
||||
private String tmpStoreConfigJson;
|
||||
private StorageType localStoreType;
|
||||
private String localStoreConfigJson;
|
||||
private BigDecimal brokerDirectRate;
|
||||
private Integer faceDetectHelperThreshold;
|
||||
|
||||
|
@ -38,5 +38,7 @@ public interface ScenicService {
|
||||
|
||||
IStorageAdapter getScenicTmpStorageAdapter(Long scenicId);
|
||||
|
||||
IStorageAdapter getScenicLocalStorageAdapter(Long scenicId);
|
||||
|
||||
IFaceBodyAdapter getScenicFaceBodyAdapter(Long scenicId);
|
||||
}
|
||||
|
@ -199,6 +199,7 @@ public class ScenicServiceImpl implements ScenicService {
|
||||
scenicFaceBodyAdapterMap.remove(config.getScenicId());
|
||||
scenicStorageAdapterMap.remove(config.getScenicId());
|
||||
scenicTmpStorageAdapterMap.remove(config.getScenicId());
|
||||
scenicLocalStorageAdapterMap.remove(config.getScenicId());
|
||||
}
|
||||
|
||||
|
||||
@ -240,6 +241,26 @@ public class ScenicServiceImpl implements ScenicService {
|
||||
return adapter;
|
||||
});
|
||||
}
|
||||
private static final Map<Long, IStorageAdapter> scenicLocalStorageAdapterMap = new ConcurrentHashMap<>();
|
||||
@Override
|
||||
public IStorageAdapter getScenicLocalStorageAdapter(Long scenicId) {
|
||||
return scenicLocalStorageAdapterMap.computeIfAbsent(scenicId, (key) -> {
|
||||
IStorageAdapter adapter;
|
||||
ScenicConfigEntity scenicConfig = scenicRepository.getScenicConfig(scenicId);
|
||||
if (scenicConfig != null && scenicConfig.getLocalStoreType() != null) {
|
||||
try {
|
||||
adapter = StorageFactory.get(scenicConfig.getLocalStoreType());
|
||||
adapter.loadConfig(JSONObject.parseObject(scenicConfig.getLocalStoreConfigJson(), Map.class));
|
||||
} catch (StorageUnsupportedException ignored) {
|
||||
return getScenicStorageAdapter(scenicId);
|
||||
}
|
||||
} else {
|
||||
return getScenicStorageAdapter(scenicId);
|
||||
}
|
||||
return adapter;
|
||||
});
|
||||
}
|
||||
|
||||
private static final Map<Long, IFaceBodyAdapter> scenicFaceBodyAdapterMap = new ConcurrentHashMap<>();
|
||||
@Override
|
||||
public IFaceBodyAdapter getScenicFaceBodyAdapter(Long scenicId) {
|
||||
|
@ -58,6 +58,7 @@ import com.ycwl.basic.storage.utils.StorageUtil;
|
||||
import com.ycwl.basic.task.VideoPieceGetter;
|
||||
import com.ycwl.basic.repository.TemplateRepository;
|
||||
import com.ycwl.basic.utils.SnowFlakeUtil;
|
||||
import com.ycwl.basic.utils.VideoReUploader;
|
||||
import lombok.NonNull;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -124,6 +125,8 @@ public class TaskTaskServiceImpl implements TaskService {
|
||||
private TaskStatusBiz taskStatusBiz;
|
||||
@Autowired
|
||||
private DeviceRepository deviceRepository;
|
||||
@Autowired
|
||||
private VideoReUploader videoReUploader;
|
||||
|
||||
|
||||
private RenderWorkerEntity getWorker(@NonNull WorkerAuthReqVo req) {
|
||||
@ -587,9 +590,10 @@ public class TaskTaskServiceImpl implements TaskService {
|
||||
videoMapper.add(video);
|
||||
}
|
||||
ScenicConfigEntity scenicConfig = scenicRepository.getScenicConfig(task.getScenicId());
|
||||
IStorageAdapter adapter = scenicService.getScenicStorageAdapter(task.getScenicId());
|
||||
IStorageAdapter adapter = scenicService.getScenicTmpStorageAdapter(task.getScenicId());
|
||||
String filename = StorageUtil.joinPath(StorageConstant.VLOG_PATH, task.getId() + "_" + task.getScenicId() + ".mp4");
|
||||
adapter.setAcl(StorageAcl.PUBLIC_READ, filename);
|
||||
videoReUploader.addVideoTask(task.getVideoUrl(), video.getId());
|
||||
int isBuy = 0;
|
||||
FaceEntity face = faceRepository.getFace(task.getFaceId());
|
||||
if (face != null) {
|
||||
@ -646,7 +650,7 @@ public class TaskTaskServiceImpl implements TaskService {
|
||||
if (task == null) {
|
||||
return null;
|
||||
}
|
||||
IStorageAdapter adapter = scenicService.getScenicStorageAdapter(task.getScenicId());
|
||||
IStorageAdapter adapter = scenicService.getScenicTmpStorageAdapter(task.getScenicId());
|
||||
String filename = StorageUtil.joinPath(StorageConstant.VLOG_PATH, task.getId() + "_" + task.getScenicId() + ".mp4");
|
||||
if (StringUtils.isBlank(task.getVideoUrl())) {
|
||||
// 生成
|
||||
|
@ -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) {
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -111,6 +111,8 @@
|
||||
store_config_json=#{storeConfigJson},
|
||||
tmp_store_type=#{tmpStoreType},
|
||||
tmp_store_config_json=#{tmpStoreConfigJson},
|
||||
local_store_type=#{localStoreType},
|
||||
local_store_config_json=#{localStoreConfigJson},
|
||||
broker_direct_rate=#{brokerDirectRate},
|
||||
watermark_type=#{watermarkType},
|
||||
watermark_scenic_text=#{watermarkScenicText},
|
||||
|
Loading…
x
Reference in New Issue
Block a user