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