Commit 7b6b23da authored by yanzg's avatar yanzg

参数处理

parent 7ac79019
......@@ -41,6 +41,18 @@ public class YzgFileConfig {
return displayUrl;
}
/**
* 初始化视频
*
* @param serverFile
* @return
*/
public YzgFileBaseVo init(String serverFile) {
YzgFileBaseVo item = new YzgFileBaseVo();
init(item, serverFile);
return item;
}
/**
* 初始化文件对象
*
......@@ -53,17 +65,17 @@ public class YzgFileConfig {
item.setServer(fromUrl);
// 对外显示全路径
item.setDisplay(getUrl(this.getDisplayUrl(), fromUrl));
// 文件全路径
String serverFullPath = getUrl(this.getServerUrl(), fromUrl);
// 获取文件大小
File file = new File(serverFullPath);
if (file.exists()) {
item.setSize(file.length());
// 获取mime
item.setMime(FileHelper.getMimeType(serverFullPath));
item.setType(FileHelper.getMediaTypeByMime(item.getMime()));
}
}
/**
* 获取相对路径
......
......@@ -257,7 +257,29 @@ public class YzgFileServiceImpl implements YzgFileService {
*/
@Override
public void convertVideoFirst(YzgFileConvertVideoFirstReqVo req) {
checkFolder(req.getFrom());
checkFolder(req.getTo());
String fullFrom = fileConfig.getServerFullPath(req.getFrom());
YzgFileBaseVo fromInfo = fileConfig.init(fullFrom);
if (StringHelper.isEmpty(fromInfo.getMime())) {
throw new CodeException("来源文件不存在");
}
if (fromInfo.getType() != FileHelper.FILE_TYPE_VIDEO) {
throw new CodeException("来源文件不为视频");
}
try {
String fullTo = fileConfig.getServerFullPath(req.getTo());
File fileTo = new File(fullTo);
if (fileTo.exists()) {
fileTo.delete();
}
// 获取第一帧做为缩略图
MediaHelper.getVideoFirstImage(fullFrom, fullTo);
} catch (CodeException e) {
throw new CodeException("获取视频缩略图失败", e);
}
}
/**
......@@ -304,8 +326,7 @@ public class YzgFileServiceImpl implements YzgFileService {
// 来源文件路径
String from = fileConfig.getServerFullPath(req.getFrom());
YzgFileBaseVo fromInfo = new YzgFileBaseVo();
fileConfig.init(fromInfo, from);
YzgFileBaseVo fromInfo = fileConfig.init(from);
if (fromInfo.getType() != type) {
throw new CodeException("请传入" + tag + "文件");
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment