Преглед на файлове

新功能点:首页文件上传功能可通过配置实时开启或禁用

陈精华 преди 3 години
родител
ревизия
fcdefa450c

+ 2 - 0
server/src/main/config/application.properties

@@ -67,6 +67,8 @@ office.preview.switch.disabled = ${KK_OFFICE_PREVIEW_SWITCH_DISABLED:false}
 
 #是否禁止下载转换生成的pdf文件
 pdf.download.disable = ${KK_PDF_DOWNLOAD_DISABLE:true}
+#是否禁用首页文件上传
+file.upload.disable = ${KK_FILE_UPLOAD_ENABLED:false}
 
 #预览源为FTP时 FTP用户名,可在ftp url后面加参数ftp.username=ftpuser指定,不指定默认用配置的
 ftp.username = ${KK_FTP_USERNAME:ftpuser}

+ 14 - 0
server/src/main/java/cn/keking/config/ConfigConstants.java

@@ -35,6 +35,7 @@ public class ConfigConstants {
     private static String fileDir = ConfigUtils.getHomePath() + File.separator + "file" + File.separator;
     private static CopyOnWriteArraySet<String> trustHostSet;
     private static String pdfDownloadDisable;
+    private static Boolean fileUploadDisable;
 
     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";
@@ -48,6 +49,7 @@ public class ConfigConstants {
     public static final String DEFAULT_FILE_DIR_VALUE = "default";
     public static final String DEFAULT_TRUST_HOST = "default";
     public static final String DEFAULT_PDF_DOWNLOAD_DISABLE = "true";
+    public static final String DEFAULT_FILE_UPLOAD_DISABLE = "false";
 
 
     public static Boolean isCacheEnabled() {
@@ -250,4 +252,16 @@ public class ConfigConstants {
         ConfigConstants.officePreviewSwitchDisabled = officePreviewSwitchDisabled;
     }
 
+    public static Boolean getFileUploadDisable() {
+        return fileUploadDisable;
+    }
+
+    @Value("${file.upload.disable:false}")
+    public static void setFileUploadDisable(Boolean fileUploadDisable) {
+        setFileUploadDisableValue(fileUploadDisable);
+    }
+
+    public static void setFileUploadDisableValue(Boolean fileUploadDisable) {
+        ConfigConstants.fileUploadDisable = fileUploadDisable;
+    }
 }

+ 3 - 0
server/src/main/java/cn/keking/config/ConfigRefreshComponent.java

@@ -48,6 +48,7 @@ public class ConfigRefreshComponent {
                 String baseUrl;
                 String trustHost;
                 String pdfDownloadDisable;
+                boolean fileUploadDisable;
                 while (true) {
                     FileReader fileReader = new FileReader(configFilePath);
                     BufferedReader bufferedReader = new BufferedReader(fileReader);
@@ -66,6 +67,7 @@ public class ConfigRefreshComponent {
                     baseUrl = properties.getProperty("base.url", ConfigConstants.DEFAULT_BASE_URL);
                     trustHost = properties.getProperty("trust.host", ConfigConstants.DEFAULT_TRUST_HOST);
                     pdfDownloadDisable = properties.getProperty("pdf.download.disable", ConfigConstants.DEFAULT_PDF_DOWNLOAD_DISABLE);
+                    fileUploadDisable = Boolean.parseBoolean(properties.getProperty("file.upload.disable", ConfigConstants.DEFAULT_FILE_UPLOAD_DISABLE));
                     ConfigConstants.setCacheEnabledValueValue(cacheEnabled);
                     ConfigConstants.setSimTextValue(textArray);
                     ConfigConstants.setMediaValue(mediaArray);
@@ -77,6 +79,7 @@ public class ConfigRefreshComponent {
                     ConfigConstants.setTrustHostValue(trustHost);
                     ConfigConstants.setOfficePreviewSwitchDisabledValue(officePreviewSwitchDisabled);
                     ConfigConstants.setPdfDownloadDisableValue(pdfDownloadDisable);
+                    ConfigConstants.setFileUploadDisableValue(fileUploadDisable);
                     setWatermarkConfig(properties);
                     bufferedReader.close();
                     fileReader.close();

+ 3 - 0
server/src/main/java/cn/keking/web/controller/FileController.java

@@ -35,6 +35,9 @@ public class FileController {
 
     @RequestMapping(value = "fileUpload", method = RequestMethod.POST)
     public String fileUpload(@RequestParam("file") MultipartFile file) throws JsonProcessingException {
+        if (ConfigConstants.getFileUploadDisable()) {
+            return new ObjectMapper().writeValueAsString(ReturnResponse.failure("文件传接口已禁用"));
+        }
         // 获取文件名
         String fileName = file.getOriginalFilename();
         //判断是否为IE浏览器的文件名,IE浏览器下文件名会带有盘符信息

+ 1 - 1
server/src/main/java/cn/keking/web/filter/AttributeSetFilter.java

@@ -34,7 +34,7 @@ public class AttributeSetFilter implements Filter {
         request.setAttribute("pdfDownloadDisable", ConfigConstants.getPdfDownloadDisable());
         request.setAttribute("fileKey", httpRequest.getParameter("fileKey"));
         request.setAttribute("switchDisabled", ConfigConstants.getOfficePreviewSwitchDisabled());
-
+        request.setAttribute("fileUploadDisable", ConfigConstants.getFileUploadDisable());
     }
 
     /**

+ 1 - 0
server/src/main/java/cn/keking/web/filter/FilterConfiguration.java

@@ -53,6 +53,7 @@ public class FilterConfiguration {
     @Bean
     public FilterRegistrationBean getWatermarkConfigFilter() {
         Set<String> filterUri = new HashSet<>();
+        filterUri.add("/index");
         filterUri.add("/onlinePreview");
         filterUri.add("/picturesPreview");
         AttributeSetFilter filter = new AttributeSetFilter();

+ 8 - 7
server/src/main/resources/web/index.ftl

@@ -58,12 +58,14 @@
             </h4>
         </div>
         <div class="panel-body">
-            <div style="padding: 10px">
-                <form enctype="multipart/form-data" id="fileUpload">
-                    <input type="file" name="file"/>
-                    <input type="button" id="btnSubmit" value=" 上 传 "/>
-                </form>
-            </div>
+            <#if fileUploadDisable == false>
+                <div style="padding: 10px">
+                    <form enctype="multipart/form-data" id="fileUpload">
+                        <input type="file" name="file"/>
+                        <input type="button" id="btnSubmit" value=" 上 传 "/>
+                    </form>
+                </div>
+            </#if>
             <div>
                 <table id="table" data-pagination="true"></table>
             </div>
@@ -250,7 +252,6 @@
             var height = window.document.documentElement.clientHeight - 1;
             $(".loading_container").css("height", height).show();
         }
-
         $("#btnSubmit").click(function () {
             showLoadingDiv();
             $("#fileUpload").ajaxSubmit({