mirror of
https://gitee.com/kekingcn/file-online-preview.git
synced 2025-04-05 17:37:49 +08:00
file.Dir变为选配置添加其默认值
This commit is contained in:
parent
b625381de3
commit
4a7ba07df1
@ -12,15 +12,15 @@ 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
|
||||||
|
|
||||||
##资源映射路径
|
|
||||||
file.dir = D:\\kkFileview\\
|
|
||||||
spring.resources.static-locations = classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,file:${file.dir}
|
|
||||||
##openoffice home路径
|
|
||||||
#office.home = C:\\Program Files (x86)\\OpenOffice 4
|
|
||||||
server.tomcat.uri-encoding = UTF-8
|
server.tomcat.uri-encoding = UTF-8
|
||||||
#文件上传限制
|
#文件上传限制
|
||||||
spring.http.multipart.max-file-size=100MB
|
spring.http.multipart.max-file-size=100MB
|
||||||
|
|
||||||
|
#文件资源路径(默认为打包根路径下的file目录下)
|
||||||
|
#file.dir = D:\\kkFileview\\
|
||||||
|
#openoffice home路径
|
||||||
|
#office.home = C:\\Program Files (x86)\\OpenOffice 4
|
||||||
|
|
||||||
#缓存实现类型,不配默认为JDK实现,可配置为redis实现(需要配置spring.redisson.address等参数)
|
#缓存实现类型,不配默认为JDK实现,可配置为redis实现(需要配置spring.redisson.address等参数)
|
||||||
#cache.type = redis
|
#cache.type = redis
|
||||||
#redis连接
|
#redis连接
|
||||||
|
@ -1,15 +1,23 @@
|
|||||||
package cn.keking.config;
|
package cn.keking.config;
|
||||||
|
|
||||||
|
import org.artofsolving.jodconverter.office.OfficeUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @auther: chenjh
|
* @auther: chenjh
|
||||||
* @time: 2019/4/10 17:22
|
* @time: 2019/4/10 17:22
|
||||||
* @description
|
* @description
|
||||||
*/
|
*/
|
||||||
|
@Component
|
||||||
public class ConfigConstants {
|
public class ConfigConstants {
|
||||||
|
|
||||||
private static String[] simText = {};
|
private static String[] simText = {};
|
||||||
private static String[] media = {};
|
private static String[] media = {};
|
||||||
private static String convertedFileCharset;
|
private static String convertedFileCharset;
|
||||||
|
private static String fileDir = OfficeUtils.getHomePath() + File.separator + "file" + File.separator;
|
||||||
|
|
||||||
public static String[] getSimText() {
|
public static String[] getSimText() {
|
||||||
return simText;
|
return simText;
|
||||||
@ -35,4 +43,18 @@ public class ConfigConstants {
|
|||||||
ConfigConstants.convertedFileCharset = convertedFileCharset;
|
ConfigConstants.convertedFileCharset = convertedFileCharset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getFileDir() {
|
||||||
|
return fileDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Value("${file.dir:default}")
|
||||||
|
public void setFileDir(String fileDir) {
|
||||||
|
if (!"default".equals(fileDir)) {
|
||||||
|
if (!fileDir.endsWith(File.separator)) {
|
||||||
|
fileDir = fileDir + File.separator;
|
||||||
|
}
|
||||||
|
ConfigConstants.fileDir = fileDir;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,28 @@
|
|||||||
|
package cn.keking.config;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @auther: chenjh
|
||||||
|
* @time: 2019/4/16 20:04
|
||||||
|
* @description
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class WebConfig extends WebMvcConfigurerAdapter {
|
||||||
|
|
||||||
|
private final static Logger LOGGER = LoggerFactory.getLogger(WebConfig.class);
|
||||||
|
/**
|
||||||
|
* 访问外部文件配置
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||||
|
String filePath = ConfigConstants.getFileDir();
|
||||||
|
LOGGER.info("Add resource locations: {}", filePath);
|
||||||
|
registry.addResourceHandler("/**").addResourceLocations("classpath:/META-INF/resources/","classpath:/resources/","classpath:/static/","classpath:/public/","file:" + filePath);
|
||||||
|
super.addResourceHandlers(registry);
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
@ -25,8 +26,7 @@ public class OfficeFilePreviewImpl implements FilePreview {
|
|||||||
@Autowired
|
@Autowired
|
||||||
FileUtils fileUtils;
|
FileUtils fileUtils;
|
||||||
|
|
||||||
@Value("${file.dir}")
|
String fileDir = ConfigConstants.getFileDir();
|
||||||
String fileDir;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
DownloadUtils downloadUtils;
|
DownloadUtils downloadUtils;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package cn.keking.utils;
|
package cn.keking.utils;
|
||||||
|
|
||||||
|
import cn.keking.config.ConfigConstants;
|
||||||
import cn.keking.model.ReturnResponse;
|
import cn.keking.model.ReturnResponse;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
@ -13,8 +13,7 @@ import java.util.UUID;
|
|||||||
@Component
|
@Component
|
||||||
public class DownloadUtils {
|
public class DownloadUtils {
|
||||||
|
|
||||||
@Value("${file.dir}")
|
String fileDir = ConfigConstants.getFileDir();
|
||||||
String fileDir;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 一开始测试的时候发现有些文件没有下载下来,而有些可以;当时也是郁闷了好一阵,但是最终还是不得解
|
* 一开始测试的时候发现有些文件没有下载下来,而有些可以;当时也是郁闷了好一阵,但是最终还是不得解
|
||||||
|
@ -30,8 +30,7 @@ public class FileUtils {
|
|||||||
@Autowired
|
@Autowired
|
||||||
CacheService cacheService;
|
CacheService cacheService;
|
||||||
|
|
||||||
@Value("${file.dir}")
|
String fileDir = ConfigConstants.getFileDir();
|
||||||
String fileDir;
|
|
||||||
|
|
||||||
@Value("${converted.file.charset}")
|
@Value("${converted.file.charset}")
|
||||||
String charset;
|
String charset;
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
package cn.keking.utils;
|
package cn.keking.utils;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import cn.keking.config.ConfigConstants;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class ShedulerClean {
|
public class ShedulerClean {
|
||||||
@Value("${file.dir}")
|
String fileDir = ConfigConstants.getFileDir();
|
||||||
String fileDir;
|
|
||||||
|
|
||||||
// @Scheduled(cron = "0 0 23 * * ?") //每晚23点执行一次
|
// @Scheduled(cron = "0 0 23 * * ?") //每晚23点执行一次
|
||||||
public void clean(){
|
public void clean(){
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package cn.keking.utils;
|
package cn.keking.utils;
|
||||||
|
|
||||||
|
import cn.keking.config.ConfigConstants;
|
||||||
import cn.keking.model.ReturnResponse;
|
import cn.keking.model.ReturnResponse;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -12,8 +12,7 @@ import org.springframework.stereotype.Component;
|
|||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
public class SimTextUtil {
|
public class SimTextUtil {
|
||||||
@Value("${file.dir}")
|
String fileDir = ConfigConstants.getFileDir();
|
||||||
String fileDir;
|
|
||||||
@Autowired
|
@Autowired
|
||||||
DownloadUtils downloadUtils;
|
DownloadUtils downloadUtils;
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package cn.keking.utils;
|
package cn.keking.utils;
|
||||||
|
|
||||||
|
import cn.keking.config.ConfigConstants;
|
||||||
import cn.keking.model.FileType;
|
import cn.keking.model.FileType;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
@ -11,7 +12,6 @@ import com.google.common.collect.Maps;
|
|||||||
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
|
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
|
||||||
import org.apache.commons.compress.archivers.zip.ZipFile;
|
import org.apache.commons.compress.archivers.zip.ZipFile;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.context.request.RequestContextHolder;
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
|
|
||||||
@ -36,8 +36,7 @@ public class ZipReader {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
FileUtils fileUtils;
|
FileUtils fileUtils;
|
||||||
@Value("${file.dir}")
|
String fileDir = ConfigConstants.getFileDir();
|
||||||
String fileDir;
|
|
||||||
|
|
||||||
ExecutorService executors = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
|
ExecutorService executors = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package cn.keking.web.controller;
|
package cn.keking.web.controller;
|
||||||
|
|
||||||
|
import cn.keking.config.ConfigConstants;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
@ -7,7 +8,6 @@ import com.google.common.collect.Lists;
|
|||||||
import cn.keking.model.ReturnResponse;
|
import cn.keking.model.ReturnResponse;
|
||||||
import cn.keking.utils.FileUtils;
|
import cn.keking.utils.FileUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
@ -28,8 +28,7 @@ import java.util.UUID;
|
|||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
public class FileController {
|
public class FileController {
|
||||||
@Value("${file.dir}")
|
String fileDir = ConfigConstants.getFileDir();
|
||||||
String fileDir;
|
|
||||||
@Autowired
|
@Autowired
|
||||||
FileUtils fileUtils;
|
FileUtils fileUtils;
|
||||||
String demoDir = "demo";
|
String demoDir = "demo";
|
||||||
|
Loading…
Reference in New Issue
Block a user