mirror of
https://gitee.com/kekingcn/file-online-preview.git
synced 2025-09-18 09:44:37 +08:00
新功能点:支持base url配置(主要用于nginx反向代理等)
This commit is contained in:
@@ -23,6 +23,7 @@ public class ConfigConstants {
|
||||
private static String ftpPassword;
|
||||
private static String ftpControlEncoding;
|
||||
private static String fileDir = OfficeUtils.getHomePath() + File.separator + "file" + File.separator;
|
||||
private static String baseUrl;
|
||||
|
||||
public static Boolean isCacheEnabled() {
|
||||
return cacheEnabled;
|
||||
@@ -92,6 +93,15 @@ public class ConfigConstants {
|
||||
return fileDir;
|
||||
}
|
||||
|
||||
public static String getBaseUrl() {
|
||||
return baseUrl;
|
||||
}
|
||||
|
||||
public static void setBaseUrl(String baseUrl) {
|
||||
// 不以'/'结尾的,加上'/'
|
||||
ConfigConstants.baseUrl = baseUrl.concat("/");
|
||||
}
|
||||
|
||||
@Value("${file.dir:default}")
|
||||
public void setFileDir(String fileDir) {
|
||||
if (!"default".equals(fileDir)) {
|
||||
|
@@ -5,6 +5,7 @@ import org.artofsolving.jodconverter.office.OfficeUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.io.BufferedReader;
|
||||
@@ -29,6 +30,7 @@ public class ConfigRefreshComponent {
|
||||
public static final String DEFAULT_FTP_USERNAME = null;
|
||||
public static final String DEFAULT_FTP_PASSWORD = null;
|
||||
public static final String DEFAULT_FTP_CONTROL_ENCODING = "UTF-8";
|
||||
public static final String BASE_URL = null;
|
||||
|
||||
|
||||
@PostConstruct
|
||||
@@ -53,6 +55,7 @@ public class ConfigRefreshComponent {
|
||||
String ftpPassword;
|
||||
String ftpControlEncoding;
|
||||
String configFilePath = OfficeUtils.getCustomizedConfigPath();
|
||||
String baseUlr;
|
||||
while (true) {
|
||||
FileReader fileReader = new FileReader(configFilePath);
|
||||
BufferedReader bufferedReader = new BufferedReader(fileReader);
|
||||
@@ -67,6 +70,7 @@ public class ConfigRefreshComponent {
|
||||
ftpControlEncoding = properties.getProperty("ftp.control.encoding", DEFAULT_FTP_CONTROL_ENCODING);
|
||||
textArray = text.split(",");
|
||||
mediaArray = media.split(",");
|
||||
baseUlr = properties.getProperty("base.url", null);
|
||||
ConfigConstants.setCacheEnabled(cacheEnabled);
|
||||
ConfigConstants.setSimText(textArray);
|
||||
ConfigConstants.setMedia(mediaArray);
|
||||
@@ -75,6 +79,9 @@ public class ConfigRefreshComponent {
|
||||
ConfigConstants.setFtpUsername(ftpUsername);
|
||||
ConfigConstants.setFtpPassword(ftpPassword);
|
||||
ConfigConstants.setFtpControlEncoding(ftpControlEncoding);
|
||||
if (baseUlr != null && !StringUtils.isEmpty(baseUlr)) {
|
||||
ConfigConstants.setBaseUrl(baseUlr);
|
||||
}
|
||||
bufferedReader.close();
|
||||
fileReader.close();
|
||||
Thread.sleep(1000L);
|
||||
|
@@ -1,5 +1,8 @@
|
||||
package cn.keking.filters;
|
||||
|
||||
import cn.keking.config.ConfigConstants;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
@@ -19,10 +22,16 @@ public class ChinesePathFilter implements Filter {
|
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
|
||||
request.setCharacterEncoding("UTF-8");
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
StringBuilder pathBuilder = new StringBuilder();
|
||||
pathBuilder.append(request.getScheme()).append("://").append(request.getServerName()).append(":")
|
||||
.append(request.getServerPort()).append(((HttpServletRequest)request).getContextPath()).append("/");
|
||||
request.setAttribute("baseUrl", pathBuilder.toString());
|
||||
String baseUrl;
|
||||
if (ConfigConstants.getBaseUrl() != null) {
|
||||
baseUrl = ConfigConstants.getBaseUrl();
|
||||
} else {
|
||||
StringBuilder pathBuilder = new StringBuilder();
|
||||
pathBuilder.append(request.getScheme()).append("://").append(request.getServerName()).append(":")
|
||||
.append(request.getServerPort()).append(((HttpServletRequest) request).getContextPath()).append("/");
|
||||
baseUrl = pathBuilder.toString();
|
||||
}
|
||||
request.setAttribute("baseUrl", baseUrl);
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user