!99 新增:删除转换后OFFICE、CAD、TIFF、压缩包源文件 默认开启 节约磁盘空间
Merge pull request !99 from 高雄/delete.source.file
This commit is contained in:
commit
5b6eb961cc
|
@ -124,3 +124,6 @@ BeiAn =
|
|||
prohibit =exe,dll,dat
|
||||
#删除密码
|
||||
sc.password =123456
|
||||
|
||||
#删除 转换后OFFICE、CAD、TIFF、压缩包源文件 默认开启 节约磁盘空间
|
||||
delete.source.file = true
|
||||
|
|
|
@ -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 = "true";
|
||||
|
||||
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:true}")
|
||||
public void setdeletesourcefile(Boolean deletesourcefile) {
|
||||
setdeletesourcefileValue(deletesourcefile);
|
||||
}
|
||||
|
||||
public static void setdeletesourcefileValue(Boolean deletesourcefile) {
|
||||
ConfigConstants.deletesourcefile = deletesourcefile;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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 = false;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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));
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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文件,则下载
|
||||
|
|
Loading…
Reference in New Issue