加入是否启用缓存配置项
This commit is contained in:
parent
98ec3d7dab
commit
b003a05775
|
@ -31,6 +31,9 @@ spring.http.multipart.max-file-size=100MB
|
|||
cache.clean = true
|
||||
|
||||
#######################################可在运行时动态配置#######################################
|
||||
#是否启用缓存
|
||||
cache.enabled = false
|
||||
|
||||
#文本类型,默认如下,可自定义添加
|
||||
#simText = txt,html,xml,properties,md,java,py,c,cpp,sql
|
||||
#多媒体类型,默认如下,可自定义添加
|
||||
|
|
|
@ -14,6 +14,7 @@ import java.io.File;
|
|||
@Component
|
||||
public class ConfigConstants {
|
||||
|
||||
private static Boolean cacheEnabled;
|
||||
private static String[] simText = {};
|
||||
private static String[] media = {};
|
||||
private static String convertedFileCharset;
|
||||
|
@ -23,6 +24,14 @@ public class ConfigConstants {
|
|||
private static String ftpControlEncoding;
|
||||
private static String fileDir = OfficeUtils.getHomePath() + File.separator + "file" + File.separator;
|
||||
|
||||
public static Boolean isCacheEnabled() {
|
||||
return cacheEnabled;
|
||||
}
|
||||
|
||||
public static void setCacheEnabled(Boolean cacheEnabled) {
|
||||
ConfigConstants.cacheEnabled = cacheEnabled;
|
||||
}
|
||||
|
||||
public static String[] getSimText() {
|
||||
return simText;
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ public class ConfigRefreshComponent {
|
|||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigRefreshComponent.class);
|
||||
|
||||
public static final String DEFAULT_CACHE_ENABLED = "true";
|
||||
public static final String DEFAULT_TXT_TYPE = "txt,html,xml,properties,md,java,py,c,cpp,sql";
|
||||
public static final String DEFAULT_MEDIA_TYPE = "mp3,wav,mp4,flv";
|
||||
public static final String DEFAULT_CONVERTER_CHARSET = System.getProperty("sun.jnu.encoding");
|
||||
|
@ -43,6 +44,7 @@ public class ConfigRefreshComponent {
|
|||
Properties properties = new Properties();
|
||||
String text;
|
||||
String media;
|
||||
Boolean cacheEnabled;
|
||||
String[] textArray;
|
||||
String[] mediaArray;
|
||||
String convertedFileCharset;
|
||||
|
@ -55,6 +57,7 @@ public class ConfigRefreshComponent {
|
|||
FileReader fileReader = new FileReader(configFilePath);
|
||||
BufferedReader bufferedReader = new BufferedReader(fileReader);
|
||||
properties.load(bufferedReader);
|
||||
cacheEnabled = new Boolean(properties.getProperty("cache.enabled", DEFAULT_CACHE_ENABLED));
|
||||
text = properties.getProperty("simText", DEFAULT_TXT_TYPE);
|
||||
media = properties.getProperty("media", DEFAULT_MEDIA_TYPE);
|
||||
convertedFileCharset = properties.getProperty("converted.file.charset", DEFAULT_CONVERTER_CHARSET);
|
||||
|
@ -64,6 +67,7 @@ public class ConfigRefreshComponent {
|
|||
ftpControlEncoding = properties.getProperty("ftp.control.encoding", DEFAULT_FTP_CONTROL_ENCODING);
|
||||
textArray = text.split(",");
|
||||
mediaArray = media.split(",");
|
||||
ConfigConstants.setCacheEnabled(cacheEnabled);
|
||||
ConfigConstants.setSimText(textArray);
|
||||
ConfigConstants.setMedia(mediaArray);
|
||||
ConfigConstants.setConvertedFileCharset(convertedFileCharset);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package cn.keking.service.impl;
|
||||
|
||||
import cn.keking.config.ConfigConstants;
|
||||
import cn.keking.model.FileAttribute;
|
||||
import cn.keking.model.ReturnResponse;
|
||||
import cn.keking.service.FilePreview;
|
||||
|
@ -33,7 +34,7 @@ public class CompressFilePreviewImpl implements FilePreview{
|
|||
String suffix=fileAttribute.getSuffix();
|
||||
String fileTree = null;
|
||||
// 判断文件名是否存在(redis缓存读取)
|
||||
if (!StringUtils.hasText(fileUtils.getConvertedFile(fileName))) {
|
||||
if (!StringUtils.hasText(fileUtils.getConvertedFile(fileName)) || !ConfigConstants.isCacheEnabled()) {
|
||||
ReturnResponse<String> response = downloadUtils.downLoad(fileAttribute, fileName);
|
||||
if (0 != response.getCode()) {
|
||||
model.addAttribute("fileType", suffix);
|
||||
|
@ -48,7 +49,7 @@ public class CompressFilePreviewImpl implements FilePreview{
|
|||
} else if ("7z".equalsIgnoreCase(suffix)) {
|
||||
fileTree = zipReader.read7zFile(filePath, fileName);
|
||||
}
|
||||
if (fileTree != null && !"null".equals(fileTree)) {
|
||||
if (fileTree != null && !"null".equals(fileTree) && ConfigConstants.isCacheEnabled()) {
|
||||
fileUtils.addConvertedFile(fileName, fileTree);
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -52,7 +52,7 @@ public class OfficeFilePreviewImpl implements FilePreview {
|
|||
String pdfName = fileName.substring(0, fileName.lastIndexOf(".") + 1) + (isHtml ? "html" : "pdf");
|
||||
String outFilePath = fileDir + pdfName;
|
||||
// 判断之前是否已转换过,如果转换过,直接返回,否则执行转换
|
||||
if (!fileUtils.listConvertedFiles().containsKey(pdfName)) {
|
||||
if (!fileUtils.listConvertedFiles().containsKey(pdfName) || !ConfigConstants.isCacheEnabled()) {
|
||||
String filePath = fileDir + fileName;
|
||||
if (!new File(filePath).exists()) {
|
||||
ReturnResponse<String> response = downloadUtils.downLoad(fileAttribute, null);
|
||||
|
@ -69,12 +69,14 @@ public class OfficeFilePreviewImpl implements FilePreview {
|
|||
if (f.exists()) {
|
||||
f.delete();
|
||||
}
|
||||
if (isHtml) {
|
||||
// 对转换后的文件进行操作(改变编码方式)
|
||||
fileUtils.doActionConvertedFile(outFilePath);
|
||||
if (ConfigConstants.isCacheEnabled()) {
|
||||
if (isHtml) {
|
||||
// 对转换后的文件进行操作(改变编码方式)
|
||||
fileUtils.doActionConvertedFile(outFilePath);
|
||||
}
|
||||
// 加入缓存
|
||||
fileUtils.addConvertedFile(pdfName, fileUtils.getRelativePath(outFilePath));
|
||||
}
|
||||
// 加入缓存
|
||||
fileUtils.addConvertedFile(pdfName, fileUtils.getRelativePath(outFilePath));
|
||||
}
|
||||
}
|
||||
if (!isHtml && originUrl != null && (OFFICE_PREVIEW_TYPE_IMAGE.equals(officePreviewType) || OFFICE_PREVIEW_TYPE_ALLIMAGES.equals(officePreviewType))) {
|
||||
|
|
Loading…
Reference in New Issue