From 61ae49f510efea5a93a6cbe5310f8fb41cc408ba Mon Sep 17 00:00:00 2001 From: gaoxiongzaq Date: Fri, 21 Apr 2023 09:56:46 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=96=B0=E5=A2=9E:=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2=E5=90=8EOFFICE=E3=80=81CAD=E3=80=81TIFF?= =?UTF-8?q?=E3=80=81=E5=8E=8B=E7=BC=A9=E5=8C=85=E6=BA=90=E6=96=87=E4=BB=B6?= =?UTF-8?q?=20=E9=BB=98=E8=AE=A4=E5=BC=80=E5=90=AF=20=E8=8A=82=E7=BA=A6?= =?UTF-8?q?=E7=A3=81=E7=9B=98=E7=A9=BA=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/main/config/application.properties | 3 +++ .../java/cn/keking/config/ConfigConstants.java | 15 +++++++++++++++ .../cn/keking/config/ConfigRefreshComponent.java | 3 +++ .../keking/service/impl/CadFilePreviewImpl.java | 4 ++++ .../service/impl/CompressFilePreviewImpl.java | 4 ++++ .../service/impl/OfficeFilePreviewImpl.java | 4 ++++ .../keking/service/impl/TiffFilePreviewImpl.java | 15 ++++++++++----- 7 files changed, 43 insertions(+), 5 deletions(-) diff --git a/server/src/main/config/application.properties b/server/src/main/config/application.properties index c820771e..fb3f542a 100644 --- a/server/src/main/config/application.properties +++ b/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 diff --git a/server/src/main/java/cn/keking/config/ConfigConstants.java b/server/src/main/java/cn/keking/config/ConfigConstants.java index 6d40765d..87bd167b 100644 --- a/server/src/main/java/cn/keking/config/ConfigConstants.java +++ b/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; + } + } diff --git a/server/src/main/java/cn/keking/config/ConfigRefreshComponent.java b/server/src/main/java/cn/keking/config/ConfigRefreshComponent.java index d3cfcb83..322b496d 100644 --- a/server/src/main/java/cn/keking/config/ConfigRefreshComponent.java +++ b/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(); diff --git a/server/src/main/java/cn/keking/service/impl/CadFilePreviewImpl.java b/server/src/main/java/cn/keking/service/impl/CadFilePreviewImpl.java index 6489f58b..11944080 100644 --- a/server/src/main/java/cn/keking/service/impl/CadFilePreviewImpl.java +++ b/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)); diff --git a/server/src/main/java/cn/keking/service/impl/CompressFilePreviewImpl.java b/server/src/main/java/cn/keking/service/impl/CompressFilePreviewImpl.java index e2fc3376..011ce8c4 100644 --- a/server/src/main/java/cn/keking/service/impl/CompressFilePreviewImpl.java +++ b/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); diff --git a/server/src/main/java/cn/keking/service/impl/OfficeFilePreviewImpl.java b/server/src/main/java/cn/keking/service/impl/OfficeFilePreviewImpl.java index 751eaf88..2cf75496 100644 --- a/server/src/main/java/cn/keking/service/impl/OfficeFilePreviewImpl.java +++ b/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)); diff --git a/server/src/main/java/cn/keking/service/impl/TiffFilePreviewImpl.java b/server/src/main/java/cn/keking/service/impl/TiffFilePreviewImpl.java index 5324cbc2..9566998d 100644 --- a/server/src/main/java/cn/keking/service/impl/TiffFilePreviewImpl.java +++ b/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文件,则下载 From cfaa431e20f2c65e422c146a3dabf014931923c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E9=9B=84?= Date: Fri, 21 Apr 2023 03:31:27 +0000 Subject: [PATCH 2/4] =?UTF-8?q?update=20server/src/main/java/cn/keking/con?= =?UTF-8?q?fig/ConfigConstants.java.=20=E4=BF=AE=E5=A4=8D=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E6=BA=90=E6=96=87=E4=BB=B6=E9=BB=98=E8=AE=A4=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E7=9A=84=20=20=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 高雄 --- server/src/main/java/cn/keking/config/ConfigConstants.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/cn/keking/config/ConfigConstants.java b/server/src/main/java/cn/keking/config/ConfigConstants.java index 87bd167b..4e65d2f8 100644 --- a/server/src/main/java/cn/keking/config/ConfigConstants.java +++ b/server/src/main/java/cn/keking/config/ConfigConstants.java @@ -71,7 +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 final String DEFAULT_Delete_Source_File_PREVIEW_TYPE = "true"; public static Boolean isCacheEnabled() { return cacheEnabled; @@ -412,7 +412,7 @@ public class ConfigConstants { return deletesourcefile; } - @Value("${delete.source.file:false}") + @Value("${delete.source.file:true}") public void setdeletesourcefile(Boolean deletesourcefile) { setdeletesourcefileValue(deletesourcefile); } From fff3ea0e30de07bd79fc3914915bd1459bca5ff4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E9=9B=84?= Date: Fri, 21 Apr 2023 03:36:11 +0000 Subject: [PATCH 3/4] =?UTF-8?q?update=20server/src/main/java/cn/keking/mod?= =?UTF-8?q?el/FileAttribute.java.=20=E4=BF=AE=E5=A4=8D=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E6=BA=90=E6=96=87=E4=BB=B6=E9=BB=98=E8=AE=A4=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E7=9A=84=20=20=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 高雄 --- server/src/main/java/cn/keking/model/FileAttribute.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/main/java/cn/keking/model/FileAttribute.java b/server/src/main/java/cn/keking/model/FileAttribute.java index 265750e0..442c586a 100644 --- a/server/src/main/java/cn/keking/model/FileAttribute.java +++ b/server/src/main/java/cn/keking/model/FileAttribute.java @@ -17,7 +17,7 @@ public class FileAttribute { private String userToken; private String officePreviewType = ConfigConstants.getOfficePreviewType(); private String tifPreviewType; - private Boolean skipDownLoad = false; + private Boolean skipDownLoad = true; public FileAttribute() { } From 87df3bedd0fc1540dd75e4ecbfe35310e5e597df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E9=9B=84?= Date: Fri, 21 Apr 2023 05:50:33 +0000 Subject: [PATCH 4/4] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20serv?= =?UTF-8?q?er/src/main/java/cn/keking/model/FileAttribute.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/keking/model/FileAttribute.java | 120 ------------------ 1 file changed, 120 deletions(-) delete mode 100644 server/src/main/java/cn/keking/model/FileAttribute.java diff --git a/server/src/main/java/cn/keking/model/FileAttribute.java b/server/src/main/java/cn/keking/model/FileAttribute.java deleted file mode 100644 index 442c586a..00000000 --- a/server/src/main/java/cn/keking/model/FileAttribute.java +++ /dev/null @@ -1,120 +0,0 @@ -package cn.keking.model; - -import cn.keking.config.ConfigConstants; - -/** - * Created by kl on 2018/1/17. - * Content : - */ -public class FileAttribute { - - private FileType type; - private String suffix; - private String name; - private String url; - private String fileKey; - private String filePassword; - private String userToken; - private String officePreviewType = ConfigConstants.getOfficePreviewType(); - private String tifPreviewType; - private Boolean skipDownLoad = true; - - public FileAttribute() { - } - - public FileAttribute(FileType type, String suffix, String name, String url) { - this.type = type; - this.suffix = suffix; - this.name = name; - this.url = url; - } - - public FileAttribute(FileType type, String suffix, String name, String url, String officePreviewType) { - this.type = type; - this.suffix = suffix; - this.name = name; - this.url = url; - this.officePreviewType = officePreviewType; - } - - public String getFileKey() { - return fileKey; - } - - public void setFileKey(String fileKey) { - this.fileKey = fileKey; - } - - public String getFilePassword() { - return filePassword; - } - - public void setFilePassword(String filePassword) { - this.filePassword = filePassword; - } - - public String getUserToken() { - return userToken; - } - - public void setUserToken(String userToken) { - this.userToken = userToken; - } - - public String getOfficePreviewType() { - return officePreviewType; - } - - public void setOfficePreviewType(String officePreviewType) { - this.officePreviewType = officePreviewType; - } - - public FileType getType() { - return type; - } - - public void setType(FileType type) { - this.type = type; - } - - public String getSuffix() { - return suffix; - } - - public void setSuffix(String suffix) { - this.suffix = suffix; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - - public Boolean getSkipDownLoad() { - return skipDownLoad; - } - - public void setSkipDownLoad(Boolean skipDownLoad) { - this.skipDownLoad = skipDownLoad; - } - - public String getTifPreviewType() { - return tifPreviewType; - } - - public void setTifPreviewType(String previewType) { - this.tifPreviewType = previewType; - } - -}