Explorar el Código

普通文档不计算时长

yangfeng hace 1 año
padre
commit
5b8e88167d

+ 2 - 1
system/system-biz/src/main/java/org/jeecg/modules/system/controller/CommonController.java

@@ -12,6 +12,7 @@ import org.jeecg.common.util.filter.FileTypeFilter;
 import org.jeecg.common.util.oConvertUtils;
 import org.jeecg.modules.system.entity.FileInfo;
 import org.jeecg.modules.system.service.IFileInfoService;
+import org.jeecg.modules.system.util.FileUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.util.AntPathMatcher;
@@ -105,7 +106,7 @@ public class CommonController {
         //是否计算视频时长
         Boolean isVideoDuration = Boolean.parseBoolean(request.getParameter("isVideoDuration"));
         Long videoDuration = null;
-        if (isVideoDuration) {
+        if (isVideoDuration && FileUtil.isVideo(file.getOriginalFilename())) {
             File f = new File(tmpPath + File.separator + file.getOriginalFilename());
             FileUtils.copyInputStreamToFile(file.getInputStream(), f);
             videoDuration = CommonUtils.getVideoDuration(f);

+ 23 - 0
system/system-biz/src/main/java/org/jeecg/modules/system/util/FileUtil.java

@@ -0,0 +1,23 @@
+package org.jeecg.modules.system.util;
+
+import lombok.extern.slf4j.Slf4j;
+
+import java.util.Arrays;
+import java.util.List;
+
+@Slf4j
+public class FileUtil {
+
+    private static final List<String> videoExtensions = Arrays.asList("mp4", "avi", "mov");
+
+    /**
+     * 是否为视频
+     *
+     * @param fileName
+     * @return
+     */
+    public static boolean isVideo(String fileName) {
+        String fileExtension = fileName.substring(fileName.lastIndexOf(".") + 1);
+        return videoExtensions.contains(fileExtension);
+    }
+}