|
@@ -8,11 +8,13 @@ import com.zhiqiyun.open.core.service.SequenceService;
|
|
|
import com.zhiqiyun.open.core.service.UploadFileInfoService;
|
|
import com.zhiqiyun.open.core.service.UploadFileInfoService;
|
|
|
import com.zhiqiyun.open.exception.UploadException;
|
|
import com.zhiqiyun.open.exception.UploadException;
|
|
|
import com.zhiqiyun.open.utils.DateUtil;
|
|
import com.zhiqiyun.open.utils.DateUtil;
|
|
|
|
|
+import com.zhiqiyun.open.utils.ImageUtils2;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import net.coobird.thumbnailator.Thumbnails;
|
|
import net.coobird.thumbnailator.Thumbnails;
|
|
|
import net.sf.jmimemagic.Magic;
|
|
import net.sf.jmimemagic.Magic;
|
|
|
import net.sf.jmimemagic.MagicMatch;
|
|
import net.sf.jmimemagic.MagicMatch;
|
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
|
|
|
+import org.bytedeco.javacpp.Loader;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
@@ -20,12 +22,10 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import javax.imageio.ImageIO;
|
|
import javax.imageio.ImageIO;
|
|
|
import java.awt.image.BufferedImage;
|
|
import java.awt.image.BufferedImage;
|
|
|
-import java.io.ByteArrayInputStream;
|
|
|
|
|
-import java.io.File;
|
|
|
|
|
-import java.io.IOException;
|
|
|
|
|
-import java.io.RandomAccessFile;
|
|
|
|
|
|
|
+import java.io.*;
|
|
|
import java.util.Arrays;
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.Optional;
|
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
@@ -58,7 +58,7 @@ public class UploadFileInfoServiceImpl extends ServiceImpl<UploadFileInfoMapper,
|
|
|
throw new UploadException("上传文件大小不能超过" + (maxSize / 1024) + "M");
|
|
throw new UploadException("上传文件大小不能超过" + (maxSize / 1024) + "M");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- String pattern = ".[a-zA-Z]{3,4}$";
|
|
|
|
|
|
|
+ String pattern = ".[a-zA-Z0-9]{3,4}$";
|
|
|
|
|
|
|
|
String extension;
|
|
String extension;
|
|
|
String mimeType=null;
|
|
String mimeType=null;
|
|
@@ -66,7 +66,9 @@ public class UploadFileInfoServiceImpl extends ServiceImpl<UploadFileInfoMapper,
|
|
|
Matcher m = r.matcher(originalFilename);
|
|
Matcher m = r.matcher(originalFilename);
|
|
|
if (m.find()){
|
|
if (m.find()){
|
|
|
extension = m.group(0).substring(1);
|
|
extension = m.group(0).substring(1);
|
|
|
- }else {
|
|
|
|
|
|
|
+ }else if(originalFilename.equals("mp4")) {
|
|
|
|
|
+ extension= originalFilename;
|
|
|
|
|
+ }else{
|
|
|
MagicMatch magicMatch = Magic.getMagicMatch(fileBuff);
|
|
MagicMatch magicMatch = Magic.getMagicMatch(fileBuff);
|
|
|
|
|
|
|
|
extension = magicMatch.getExtension();
|
|
extension = magicMatch.getExtension();
|
|
@@ -86,6 +88,8 @@ public class UploadFileInfoServiceImpl extends ServiceImpl<UploadFileInfoMapper,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
String filePath = String.format("%s/%s", savePath, DateUtil.format("yyyy/MM/dd"));
|
|
String filePath = String.format("%s/%s", savePath, DateUtil.format("yyyy/MM/dd"));
|
|
|
|
|
+ String pathDate = filePath;
|
|
|
|
|
+ String date = DateUtil.format("yyyy/MM/dd");
|
|
|
File fileDir = new File(filePath);
|
|
File fileDir = new File(filePath);
|
|
|
if (!fileDir.exists()) {
|
|
if (!fileDir.exists()) {
|
|
|
boolean mkdirResult = fileDir.mkdirs();
|
|
boolean mkdirResult = fileDir.mkdirs();
|
|
@@ -111,8 +115,18 @@ public class UploadFileInfoServiceImpl extends ServiceImpl<UploadFileInfoMapper,
|
|
|
log.warn("upload is not image file", e);
|
|
log.warn("upload is not image file", e);
|
|
|
throw new UploadException("只能上传图片文件");
|
|
throw new UploadException("只能上传图片文件");
|
|
|
}
|
|
}
|
|
|
- }else {
|
|
|
|
|
- filePath = String.format("%s/%s.%s", filePath, originalFilename, extension);
|
|
|
|
|
|
|
+ }else if(extension.equals("mp4")){
|
|
|
|
|
+ filePath = String.format("%s/%s.%s", filePath, DigestUtils.md5Hex(fileBuff), extension);
|
|
|
|
|
+ File file = new File(filePath);
|
|
|
|
|
+ try {
|
|
|
|
|
+ RandomAccessFile file_test = new RandomAccessFile(file,"rw");
|
|
|
|
|
+ file_test.write(fileBuff);
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ log.warn("upload is failed", e);
|
|
|
|
|
+ throw new UploadException("文件上传失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ } else{
|
|
|
|
|
+ filePath = String.format("%s/%s", filePath, originalFilename);
|
|
|
File file = new File(filePath);
|
|
File file = new File(filePath);
|
|
|
try {
|
|
try {
|
|
|
RandomAccessFile file_test = new RandomAccessFile(file,"rw");
|
|
RandomAccessFile file_test = new RandomAccessFile(file,"rw");
|
|
@@ -132,6 +146,12 @@ public class UploadFileInfoServiceImpl extends ServiceImpl<UploadFileInfoMapper,
|
|
|
result.setSize(fileBuff.length);
|
|
result.setSize(fileBuff.length);
|
|
|
result.setExtension(extension);
|
|
result.setExtension(extension);
|
|
|
result.setId(this.sequenceService.nextId());
|
|
result.setId(this.sequenceService.nextId());
|
|
|
|
|
+//
|
|
|
|
|
+// ffmpegExtractImage(url,url+".png");
|
|
|
|
|
+ if(extension.equals("mp4")){
|
|
|
|
|
+ String cover = ImageUtils2.videoImage(filePath, pathDate);
|
|
|
|
|
+ result.setCover(fileHost +"/"+ date+"/"+cover);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
UploadFileInfo fileInfo = new UploadFileInfo();
|
|
UploadFileInfo fileInfo = new UploadFileInfo();
|
|
|
BeanUtils.copyProperties(result, fileInfo);
|
|
BeanUtils.copyProperties(result, fileInfo);
|