Преглед на файлове

新增:删除转换后OFFICE、CAD、TIFF、压缩包源文件 默认开启 节约磁盘空间

gaoxiongzaq преди 1 година
родител
ревизия
61ae49f510

+ 3 - 0
server/src/main/config/application.properties

@@ -124,3 +124,6 @@ BeiAn =
 prohibit =exe,dll,dat
 #删除密码
 sc.password =123456
+
+#删除 转换后OFFICE、CAD、TIFF、压缩包源文件 默认开启 节约磁盘空间 
+delete.source.file = true

+ 15 - 0
server/src/main/java/cn/keking/config/ConfigConstants.java

@@ -46,6 +46,7 @@ public class ConfigConstants {
     private static String[] prohibit= {};
     private static String size;
     private static String password;
+    private static Boolean deletesourcefile;
 
     public static final String DEFAULT_CACHE_ENABLED = "true";
     public static final String DEFAULT_TXT_TYPE = "txt,html,htm,asp,jsp,xml,json,properties,md,gitignore,log,java,py,c,cpp,sql,sh,bat,m,bas,prg,cmd";
@@ -70,6 +71,7 @@ public class ConfigConstants {
     public static final String DEFAULT_size_DISABLE = "500MB";
     public static final String DEFAULT_prohibit_DISABLE = "exe,dll";
     public static final String DEFAULT_password_DISABLE = "123456";
+    public static final String DEFAULT_Delete_Source_File_PREVIEW_TYPE = "false";
 
     public static Boolean isCacheEnabled() {
         return cacheEnabled;
@@ -406,4 +408,17 @@ public class ConfigConstants {
         ConfigConstants.password = password;
     }
 
+    public static Boolean getdeletesourcefile() {
+        return deletesourcefile;
+    }
+
+    @Value("${delete.source.file:false}")
+    public void setdeletesourcefile(Boolean deletesourcefile) {
+        setdeletesourcefileValue(deletesourcefile);
+    }
+
+    public static void setdeletesourcefileValue(Boolean deletesourcefile) {
+        ConfigConstants.deletesourcefile = deletesourcefile;
+    }
+
 }

+ 3 - 0
server/src/main/java/cn/keking/config/ConfigRefreshComponent.java

@@ -58,6 +58,7 @@ public class ConfigRefreshComponent {
                 String BeiAn;
                 String size;
                 String password;
+                Boolean deletesourcefile;
                 while (true) {
                     FileReader fileReader = new FileReader(configFilePath);
                     BufferedReader bufferedReader = new BufferedReader(fileReader);
@@ -86,6 +87,7 @@ public class ConfigRefreshComponent {
                     BeiAn = properties.getProperty("BeiAn", ConfigConstants.DEFAULT_BeiAn_DISABLE);
                     prohibit = properties.getProperty("prohibit", ConfigConstants.DEFAULT_prohibit_DISABLE);
                     password = properties.getProperty("sc.password", ConfigConstants.DEFAULT_password_DISABLE);
+                    deletesourcefile =  Boolean.parseBoolean(properties.getProperty("delete.source.file", ConfigConstants.DEFAULT_Delete_Source_File_PREVIEW_TYPE));
                     prohibitArray = prohibit.split(",");
 
                     ConfigConstants.setCacheEnabledValueValue(cacheEnabled);
@@ -109,6 +111,7 @@ public class ConfigRefreshComponent {
                     ConfigConstants.setsizeValue(size);
                     ConfigConstants.setprohibitValue(prohibitArray);
                     ConfigConstants.setpasswordValue(password);
+                    ConfigConstants.setdeletesourcefileValue(deletesourcefile);
                     setWatermarkConfig(properties);
                     bufferedReader.close();
                     fileReader.close();

+ 4 - 0
server/src/main/java/cn/keking/service/impl/CadFilePreviewImpl.java

@@ -6,6 +6,7 @@ import cn.keking.model.ReturnResponse;
 import cn.keking.service.FilePreview;
 import cn.keking.utils.DownloadUtils;
 import cn.keking.service.FileHandlerService;
+import cn.keking.utils.KkFileUtils;
 import cn.keking.web.filter.BaseUrlFilter;
 import org.springframework.stereotype.Service;
 import org.springframework.ui.Model;
@@ -53,6 +54,9 @@ public class CadFilePreviewImpl implements FilePreview {
                 if (!convertResult) {
                     return otherFilePreview.notSupportedFile(model, fileAttribute, "cad文件转换异常,请联系管理员");
                 }
+                if( ConfigConstants.getdeletesourcefile()){  //是否保留CAD源文件
+                    KkFileUtils.deleteFileByPath(filePath);
+                }
                 if (ConfigConstants.isCacheEnabled()) {
                     // 加入缓存
                     fileHandlerService.addConvertedFile(pdfName, fileHandlerService.getRelativePath(outFilePath));

+ 4 - 0
server/src/main/java/cn/keking/service/impl/CompressFilePreviewImpl.java

@@ -7,6 +7,7 @@ import cn.keking.service.FilePreview;
 import cn.keking.utils.DownloadUtils;
 import cn.keking.service.FileHandlerService;
 import cn.keking.service.CompressFileReader;
+import cn.keking.utils.KkFileUtils;
 import org.apache.commons.lang3.exception.ExceptionUtils;
 import org.apache.poi.EncryptedDocumentException;
 import org.springframework.stereotype.Service;
@@ -59,6 +60,9 @@ public class CompressFilePreviewImpl implements FilePreview {
                 }
             }
             if (!ObjectUtils.isEmpty(fileTree)) {
+                if( ConfigConstants.getdeletesourcefile()){  //是否保留压缩包源文件
+                    KkFileUtils.deleteFileByPath(filePath);
+                }
                 if (ConfigConstants.isCacheEnabled()) {
                     // 加入缓存
                     fileHandlerService.addConvertedFile(fileName, fileTree);

+ 4 - 0
server/src/main/java/cn/keking/service/impl/OfficeFilePreviewImpl.java

@@ -7,6 +7,7 @@ import cn.keking.service.FileHandlerService;
 import cn.keking.service.FilePreview;
 import cn.keking.service.OfficeToPdfService;
 import cn.keking.utils.DownloadUtils;
+import cn.keking.utils.KkFileUtils;
 import cn.keking.utils.OfficeUtils;
 import cn.keking.web.filter.BaseUrlFilter;
 import org.jodconverter.core.office.OfficeException;
@@ -109,6 +110,9 @@ public class OfficeFilePreviewImpl implements FilePreview {
                         // 对转换后的文件进行操作(改变编码方式)
                         fileHandlerService.doActionConvertedFile(outFilePath);
                     }
+                    if(ConfigConstants.getdeletesourcefile()){  //是否保留OFFICE源文件
+                        KkFileUtils.deleteFileByPath(filePath);
+                    }
                     if (isUseCached) {
                         // 加入缓存
                         fileHandlerService.addConvertedFile(cacheFileName, fileHandlerService.getRelativePath(outFilePath));

+ 10 - 5
server/src/main/java/cn/keking/service/impl/TiffFilePreviewImpl.java

@@ -7,6 +7,7 @@ import cn.keking.service.FileHandlerService;
 import cn.keking.service.FilePreview;
 import cn.keking.utils.ConvertPicUtil;
 import cn.keking.utils.DownloadUtils;
+import cn.keking.utils.KkFileUtils;
 import cn.keking.web.filter.BaseUrlFilter;
 import org.springframework.stereotype.Service;
 import org.springframework.ui.Model;
@@ -57,20 +58,24 @@ public class TiffFilePreviewImpl implements FilePreview {
                             return otherFilePreview.notSupportedFile(model, fileAttribute, response.getMsg());
                         }
                         String filePath = response.getContent();
-                        if (ConfigConstants.isCacheEnabled()) {
-                            // 加入缓存
-                            fileHandlerService.addConvertedFile(pdfName, fileHandlerService.getRelativePath(outFilePath));
-                        }
                         if(ConvertPicUtil.convertJpg2Pdf(filePath, outFilePath)){
+                            if(ConfigConstants.getdeletesourcefile()){  //是否保留TIFF源文件
+                                KkFileUtils.deleteFileByPath(filePath);
+                            }
+                            if (ConfigConstants.isCacheEnabled()) {
+                                // 加入缓存
+                                fileHandlerService.addConvertedFile(pdfName, fileHandlerService.getRelativePath(outFilePath));
+                            }
                             model.addAttribute("pdfUrl", pdfName);
                             return PDF_FILE_PREVIEW_PAGE;
+                        }else {
+                            return NOT_SUPPORTED_FILE_PAGE;
                         }
                     }
                  else {
                     model.addAttribute("pdfUrl", pdfName);
                     return PDF_FILE_PREVIEW_PAGE;
                 }
-
             } else {
                 File fileTiff = new File(strLocalTif);
                 // 如果本地不存在这个tif文件,则下载