mirror of
https://gitee.com/kekingcn/file-online-preview.git
synced 2025-10-24 09:49:08 +08:00
office plugin 转换进程、任务超时可配置
This commit is contained in:
@@ -16,6 +16,12 @@ spring.freemarker.expose-session-attributes = true
|
|||||||
spring.freemarker.request-context-attribute = request
|
spring.freemarker.request-context-attribute = request
|
||||||
spring.freemarker.suffix = .ftl
|
spring.freemarker.suffix = .ftl
|
||||||
|
|
||||||
|
# office-plugin
|
||||||
|
## office转换服务的进程数,默认开启两个进程
|
||||||
|
office.plugin.server.ports = 2001,2002
|
||||||
|
## office 转换服务 task 超时时间,默认五分钟
|
||||||
|
office.plugin.task.timeout = 5m
|
||||||
|
|
||||||
#文件资源路径(默认为打包根路径下的file目录下)
|
#文件资源路径(默认为打包根路径下的file目录下)
|
||||||
#file.dir = D:\\kkFileview\\
|
#file.dir = D:\\kkFileview\\
|
||||||
file.dir = ${KK_FILE_DIR:default}
|
file.dir = ${KK_FILE_DIR:default}
|
||||||
|
|||||||
@@ -21,18 +21,18 @@ public class ConfigConstants {
|
|||||||
System.setProperty("sun.java2d.cmm", "sun.java2d.cmm.kcms.KcmsServiceProvider");
|
System.setProperty("sun.java2d.cmm", "sun.java2d.cmm.kcms.KcmsServiceProvider");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Boolean CACHE_ENABLED;
|
private static Boolean cacheEnabled;
|
||||||
private static String[] SIM_TEXT = {};
|
private static String[] simTexts = {};
|
||||||
private static String[] MEDIA = {};
|
private static String[] medias = {};
|
||||||
private static String OFFICE_PREVIEW_TYPE;
|
private static String officePreviewType;
|
||||||
private static String OFFICE_PREVIEW_SWITCH_DISABLED;
|
private static String officePreviewSwitchDisabled;
|
||||||
private static String FTP_USERNAME;
|
private static String ftpUsername;
|
||||||
private static String FTP_PASSWORD;
|
private static String ftpPassword;
|
||||||
private static String FTP_CONTROL_ENCODING;
|
private static String ftpControlEncoding;
|
||||||
private static String BASE_URL;
|
private static String baseUrl;
|
||||||
private static String FILE_DIR = ConfigUtils.getHomePath() + File.separator + "file" + File.separator;
|
private static String fileDir = ConfigUtils.getHomePath() + File.separator + "file" + File.separator;
|
||||||
private static CopyOnWriteArraySet<String> TRUST_HOST_SET;
|
private static CopyOnWriteArraySet<String> trustHostSet;
|
||||||
private static String PDF_DOWNLOAD_DISABLE;
|
private static String pdfDownloadDisable;
|
||||||
|
|
||||||
public static final String DEFAULT_CACHE_ENABLED = "true";
|
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";
|
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";
|
||||||
@@ -47,8 +47,9 @@ public class ConfigConstants {
|
|||||||
public static final String DEFAULT_TRUST_HOST = "default";
|
public static final String DEFAULT_TRUST_HOST = "default";
|
||||||
public static final String DEFAULT_PDF_DOWNLOAD_DISABLE = "true";
|
public static final String DEFAULT_PDF_DOWNLOAD_DISABLE = "true";
|
||||||
|
|
||||||
|
|
||||||
public static Boolean isCacheEnabled() {
|
public static Boolean isCacheEnabled() {
|
||||||
return CACHE_ENABLED;
|
return cacheEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Value("${cache.enabled:true}")
|
@Value("${cache.enabled:true}")
|
||||||
@@ -57,11 +58,11 @@ public class ConfigConstants {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void setCacheEnabledValueValue(Boolean cacheEnabled) {
|
public static void setCacheEnabledValueValue(Boolean cacheEnabled) {
|
||||||
CACHE_ENABLED = cacheEnabled;
|
ConfigConstants.cacheEnabled = cacheEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String[] getSimText() {
|
public static String[] getSimText() {
|
||||||
return SIM_TEXT;
|
return simTexts;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Value("${simText:txt,html,htm,asp,jsp,xml,json,properties,md,gitignore,log,java,py,c,cpp,sql,sh,bat,m,bas,prg,cmd}")
|
@Value("${simText:txt,html,htm,asp,jsp,xml,json,properties,md,gitignore,log,java,py,c,cpp,sql,sh,bat,m,bas,prg,cmd}")
|
||||||
@@ -71,11 +72,11 @@ public class ConfigConstants {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void setSimTextValue(String[] simText) {
|
public static void setSimTextValue(String[] simText) {
|
||||||
SIM_TEXT = simText;
|
ConfigConstants.simTexts = simText;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String[] getMedia() {
|
public static String[] getMedia() {
|
||||||
return MEDIA;
|
return medias;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Value("${media:mp3,wav,mp4,flv}")
|
@Value("${media:mp3,wav,mp4,flv}")
|
||||||
@@ -85,11 +86,11 @@ public class ConfigConstants {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void setMediaValue(String[] Media) {
|
public static void setMediaValue(String[] Media) {
|
||||||
MEDIA = Media;
|
ConfigConstants.medias = Media;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getOfficePreviewType() {
|
public static String getOfficePreviewType() {
|
||||||
return OFFICE_PREVIEW_TYPE;
|
return officePreviewType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Value("${office.preview.type:image}")
|
@Value("${office.preview.type:image}")
|
||||||
@@ -98,11 +99,11 @@ public class ConfigConstants {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void setOfficePreviewTypeValue(String officePreviewType) {
|
public static void setOfficePreviewTypeValue(String officePreviewType) {
|
||||||
OFFICE_PREVIEW_TYPE = officePreviewType;
|
ConfigConstants.officePreviewType = officePreviewType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getFtpUsername() {
|
public static String getFtpUsername() {
|
||||||
return FTP_USERNAME;
|
return ftpUsername;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Value("${ftp.username:}")
|
@Value("${ftp.username:}")
|
||||||
@@ -111,11 +112,11 @@ public class ConfigConstants {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void setFtpUsernameValue(String ftpUsername) {
|
public static void setFtpUsernameValue(String ftpUsername) {
|
||||||
FTP_USERNAME = ftpUsername;
|
ConfigConstants.ftpUsername = ftpUsername;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getFtpPassword() {
|
public static String getFtpPassword() {
|
||||||
return FTP_PASSWORD;
|
return ftpPassword;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Value("${ftp.password:}")
|
@Value("${ftp.password:}")
|
||||||
@@ -124,11 +125,11 @@ public class ConfigConstants {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void setFtpPasswordValue(String ftpPassword) {
|
public static void setFtpPasswordValue(String ftpPassword) {
|
||||||
FTP_PASSWORD = ftpPassword;
|
ConfigConstants.ftpPassword = ftpPassword;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getFtpControlEncoding() {
|
public static String getFtpControlEncoding() {
|
||||||
return FTP_CONTROL_ENCODING;
|
return ftpControlEncoding;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Value("${ftp.control.encoding:UTF-8}")
|
@Value("${ftp.control.encoding:UTF-8}")
|
||||||
@@ -137,11 +138,11 @@ public class ConfigConstants {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void setFtpControlEncodingValue(String ftpControlEncoding) {
|
public static void setFtpControlEncodingValue(String ftpControlEncoding) {
|
||||||
FTP_CONTROL_ENCODING = ftpControlEncoding;
|
ConfigConstants.ftpControlEncoding = ftpControlEncoding;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getBaseUrl() {
|
public static String getBaseUrl() {
|
||||||
return BASE_URL;
|
return baseUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Value("${base.url:default}")
|
@Value("${base.url:default}")
|
||||||
@@ -150,11 +151,11 @@ public class ConfigConstants {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void setBaseUrlValue(String baseUrl) {
|
public static void setBaseUrlValue(String baseUrl) {
|
||||||
BASE_URL = baseUrl;
|
ConfigConstants.baseUrl = baseUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getFileDir() {
|
public static String getFileDir() {
|
||||||
return FILE_DIR;
|
return fileDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Value("${file.dir:default}")
|
@Value("${file.dir:default}")
|
||||||
@@ -167,7 +168,7 @@ public class ConfigConstants {
|
|||||||
if (!fileDir.endsWith(File.separator)) {
|
if (!fileDir.endsWith(File.separator)) {
|
||||||
fileDir = fileDir + File.separator;
|
fileDir = fileDir + File.separator;
|
||||||
}
|
}
|
||||||
FILE_DIR = fileDir;
|
ConfigConstants.fileDir = fileDir;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,15 +190,15 @@ public class ConfigConstants {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Set<String> getTrustHostSet() {
|
public static Set<String> getTrustHostSet() {
|
||||||
return TRUST_HOST_SET;
|
return trustHostSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setTrustHostSet(CopyOnWriteArraySet<String> trustHostSet) {
|
private static void setTrustHostSet(CopyOnWriteArraySet<String> trustHostSet) {
|
||||||
ConfigConstants.TRUST_HOST_SET = trustHostSet;
|
ConfigConstants.trustHostSet = trustHostSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getPdfDownloadDisable() {
|
public static String getPdfDownloadDisable() {
|
||||||
return PDF_DOWNLOAD_DISABLE;
|
return pdfDownloadDisable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -206,17 +207,18 @@ public class ConfigConstants {
|
|||||||
setPdfDownloadDisableValue(pdfDownloadDisable);
|
setPdfDownloadDisableValue(pdfDownloadDisable);
|
||||||
}
|
}
|
||||||
public static void setPdfDownloadDisableValue(String pdfDownloadDisable) {
|
public static void setPdfDownloadDisableValue(String pdfDownloadDisable) {
|
||||||
PDF_DOWNLOAD_DISABLE = pdfDownloadDisable;
|
ConfigConstants.pdfDownloadDisable = pdfDownloadDisable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getOfficePreviewSwitchDisabled() {
|
public static String getOfficePreviewSwitchDisabled() {
|
||||||
return OFFICE_PREVIEW_SWITCH_DISABLED;
|
return officePreviewSwitchDisabled;
|
||||||
}
|
}
|
||||||
@Value("${office.preview.switch.disabled:true}")
|
@Value("${office.preview.switch.disabled:true}")
|
||||||
public void setOfficePreviewSwitchDisabled(String officePreviewSwitchDisabled) {
|
public void setOfficePreviewSwitchDisabled(String officePreviewSwitchDisabled) {
|
||||||
OFFICE_PREVIEW_SWITCH_DISABLED = officePreviewSwitchDisabled;
|
ConfigConstants.officePreviewSwitchDisabled = officePreviewSwitchDisabled;
|
||||||
}
|
}
|
||||||
public static void setOfficePreviewSwitchDisabledValue(String officePreviewSwitchDisabled) {
|
public static void setOfficePreviewSwitchDisabledValue(String officePreviewSwitchDisabled) {
|
||||||
OFFICE_PREVIEW_SWITCH_DISABLED = officePreviewSwitchDisabled;
|
ConfigConstants.officePreviewSwitchDisabled = officePreviewSwitchDisabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import org.artofsolving.jodconverter.office.OfficeManager;
|
|||||||
import org.artofsolving.jodconverter.office.OfficeUtils;
|
import org.artofsolving.jodconverter.office.OfficeUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.boot.convert.DurationStyle;
|
||||||
import org.springframework.core.Ordered;
|
import org.springframework.core.Ordered;
|
||||||
import org.springframework.core.annotation.Order;
|
import org.springframework.core.annotation.Order;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@@ -19,7 +21,11 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
@@ -37,6 +43,12 @@ public class OfficePluginManager {
|
|||||||
|
|
||||||
private OfficeManager officeManager;
|
private OfficeManager officeManager;
|
||||||
|
|
||||||
|
@Value("${office.plugin.server.ports:2001,2002}")
|
||||||
|
private String serverPorts;
|
||||||
|
|
||||||
|
@Value("${office.plugin.task.timeout:5m}")
|
||||||
|
private String timeOut;
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void initOfficeManager() {
|
public void initOfficeManager() {
|
||||||
new Thread(this::startOfficeManager).start();
|
new Thread(this::startOfficeManager).start();
|
||||||
@@ -57,9 +69,14 @@ public class OfficePluginManager {
|
|||||||
try {
|
try {
|
||||||
DefaultOfficeManagerConfiguration configuration = new DefaultOfficeManagerConfiguration();
|
DefaultOfficeManagerConfiguration configuration = new DefaultOfficeManagerConfiguration();
|
||||||
configuration.setOfficeHome(officeHome);
|
configuration.setOfficeHome(officeHome);
|
||||||
configuration.setPortNumber(8100);
|
String []portsString = serverPorts.split(",");
|
||||||
|
|
||||||
|
int[] ports = Arrays.stream(portsString).mapToInt(Integer::parseInt).toArray();
|
||||||
|
|
||||||
|
configuration.setPortNumbers(ports);
|
||||||
|
long timeout = DurationStyle.detectAndParse(timeOut).toMillis();
|
||||||
// 设置任务执行超时为5分钟
|
// 设置任务执行超时为5分钟
|
||||||
configuration.setTaskExecutionTimeout(1000 * 60 * 5L);
|
configuration.setTaskExecutionTimeout(timeout);
|
||||||
// 设置任务队列超时为24小时
|
// 设置任务队列超时为24小时
|
||||||
//configuration.setTaskQueueTimeout(1000 * 60 * 60 * 24L);
|
//configuration.setTaskQueueTimeout(1000 * 60 * 60 * 24L);
|
||||||
officeManager = configuration.buildOfficeManager();
|
officeManager = configuration.buildOfficeManager();
|
||||||
|
|||||||
Reference in New Issue
Block a user