ソースを参照

新增配置项office.preview.switch.disabled,控制offic文件预览切换开关

kl 4 年 前
コミット
d787813bc6

+ 3 - 0
jodconverter-web/src/main/config/application.properties

@@ -53,6 +53,9 @@ simText = ${KK_SIMTEXT:txt,html,htm,asp,jsp,xml,json,properties,md,gitignore,log
 media = ${KK_MEDIA:mp3,wav,mp4,flv}
 #office类型文档(word ppt)样式,默认为图片(image),可配置为pdf(预览时也有按钮切换)
 office.preview.type = ${KK_OFFICE_PREVIEW_TYPE:image}
+#是否关闭office预览切换开关,默认为false,可配置为true关闭
+office.preview.switch.disabled = ${KK_OFFICE_PREVIEW_SWITCH_DISABLED:false}
+
 #是否禁止下载转换生成的pdf文件
 pdf.download.disable = ${KK_PDF_DOWNLOAD_DISABLE:true}
 

+ 1 - 0
jodconverter-web/src/main/config/freemarker_implicit.ftl

@@ -1,5 +1,6 @@
 [#ftl]
 [#-- @implicitly included --]
+[#-- @ftlvariable name="switchDisabled" type="String" --]
 [#-- @ftlvariable name="imgurls" type="String" --]
 [#-- @ftlvariable name="watermarkAngle" type="String" --]
 [#-- @ftlvariable name="watermarkHeight" type="String" --]

+ 10 - 0
jodconverter-web/src/main/java/cn/keking/config/ConfigConstants.java

@@ -20,6 +20,7 @@ public class ConfigConstants {
     private static String[] SIM_TEXT = {};
     private static String[] MEDIA = {};
     private static String OFFICE_PREVIEW_TYPE;
+    private static String OFFICE_PREVIEW_SWITCH_DISABLED;
     private static String FTP_USERNAME;
     private static String FTP_PASSWORD;
     private static String FTP_CONTROL_ENCODING;
@@ -32,6 +33,7 @@ public class ConfigConstants {
     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_MEDIA_TYPE = "mp3,wav,mp4,flv";
     public static final String DEFAULT_OFFICE_PREVIEW_TYPE = "image";
+    public static final String DEFAULT_OFFICE_PREVIEW_SWITCH_DISABLED = "false";
     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";
@@ -202,4 +204,12 @@ public class ConfigConstants {
         PDF_DOWNLOAD_DISABLE = pdfDownloadDisable;
     }
 
+    public static String getOfficePreviewSwitchDisabled() {
+        return OFFICE_PREVIEW_SWITCH_DISABLED;
+    }
+
+    @Value("${office.preview.switch.disabled:true}")
+    public static void setOfficePreviewSwitchDisabled(String officePreviewSwitchDisabled) {
+        OFFICE_PREVIEW_SWITCH_DISABLED = officePreviewSwitchDisabled;
+    }
 }

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

@@ -38,6 +38,7 @@ public class ConfigRefreshComponent {
                 String[] textArray;
                 String[] mediaArray;
                 String officePreviewType;
+                String officePreviewSwitchDisabled;
                 String ftpUsername;
                 String ftpPassword;
                 String ftpControlEncoding;
@@ -54,6 +55,7 @@ public class ConfigRefreshComponent {
                     text = properties.getProperty("simText", ConfigConstants.DEFAULT_TXT_TYPE);
                     media = properties.getProperty("media", ConfigConstants.DEFAULT_MEDIA_TYPE);
                     officePreviewType = properties.getProperty("office.preview.type", ConfigConstants.DEFAULT_OFFICE_PREVIEW_TYPE);
+                    officePreviewSwitchDisabled = properties.getProperty("office.preview.switch.disabled", ConfigConstants.DEFAULT_OFFICE_PREVIEW_TYPE);
                     ftpUsername = properties.getProperty("ftp.username", ConfigConstants.DEFAULT_FTP_USERNAME);
                     ftpPassword = properties.getProperty("ftp.password", ConfigConstants.DEFAULT_FTP_PASSWORD);
                     ftpControlEncoding = properties.getProperty("ftp.control.encoding", ConfigConstants.DEFAULT_FTP_CONTROL_ENCODING);
@@ -71,6 +73,7 @@ public class ConfigRefreshComponent {
                     ConfigConstants.setFtpControlEncodingValue(ftpControlEncoding);
                     ConfigConstants.setBaseUrlValue(baseUrl);
                     ConfigConstants.setTrustHostValue(trustHost);
+                    ConfigConstants.setOfficePreviewSwitchDisabled(officePreviewSwitchDisabled);
                     ConfigConstants.setPdfDownloadDisableValue(pdfDownloadDisable);
                     setWatermarkConfig(properties);
                     bufferedReader.close();

+ 1 - 0
jodconverter-web/src/main/java/cn/keking/service/impl/OfficeFilePreviewImpl.java

@@ -54,6 +54,7 @@ public class OfficeFilePreviewImpl implements FilePreview {
         boolean isHtml = suffix.equalsIgnoreCase("xls") || suffix.equalsIgnoreCase("xlsx");
         String pdfName = fileName.substring(0, fileName.lastIndexOf(".") + 1) + (isHtml ? "html" : "pdf");
         String outFilePath = FILE_DIR + pdfName;
+        model.addAttribute("switchDisabled", ConfigConstants.getOfficePreviewSwitchDisabled());
         // 判断之前是否已转换过,如果转换过,直接返回,否则执行转换
         if (!fileUtils.listConvertedFiles().containsKey(pdfName) || !ConfigConstants.isCacheEnabled()) {
             String filePath;

+ 1 - 0
jodconverter-web/src/main/java/cn/keking/service/impl/PdfFilePreviewImpl.java

@@ -44,6 +44,7 @@ public class PdfFilePreviewImpl implements FilePreview {
         String baseUrl = BaseUrlFilter.getBaseUrl();
         String pdfName = fileName.substring(0, fileName.lastIndexOf(".") + 1) + "pdf";
         String outFilePath = FILE_DIR + pdfName;
+        model.addAttribute("switchDisabled", ConfigConstants.getOfficePreviewSwitchDisabled());
         if (OfficeFilePreviewImpl.OFFICE_PREVIEW_TYPE_IMAGE.equals(officePreviewType) || OfficeFilePreviewImpl.OFFICE_PREVIEW_TYPE_ALL_IMAGES.equals(officePreviewType)) {
             //当文件不存在时,就去下载
             if (!fileUtils.listConvertedFiles().containsKey(pdfName) || !ConfigConstants.isCacheEnabled()) {

+ 2 - 0
jodconverter-web/src/main/java/cn/keking/service/impl/PictureFilePreviewImpl.java

@@ -1,5 +1,6 @@
 package cn.keking.service.impl;
 
+import cn.keking.config.ConfigConstants;
 import cn.keking.model.FileAttribute;
 import cn.keking.model.ReturnResponse;
 import cn.keking.service.FilePreview;
@@ -33,6 +34,7 @@ public class PictureFilePreviewImpl implements FilePreview {
     public String filePreviewHandle(String url, Model model, FileAttribute fileAttribute) {
         String fileKey = (String) RequestContextHolder.currentRequestAttributes().getAttribute("fileKey",0);
         List<String> imgUrls = Lists.newArrayList(url);
+        model.addAttribute("switchDisabled", ConfigConstants.getOfficePreviewSwitchDisabled());
         try {
             imgUrls.clear();
             imgUrls.addAll(fileUtils.getImgCache(fileKey));

+ 3 - 1
jodconverter-web/src/main/resources/web/officePicture.ftl

@@ -34,7 +34,9 @@
         </div>
     </#list>
 </div>
-<img src="images/pdf.svg" width="63" height="63" style="position: fixed; cursor: pointer; top: 40%; right: 48px; z-index: 999;" alt="使用PDF预览" title="使用PDF预览" onclick="changePreviewType('pdf')"/>
+<#if "false" == switchDisabled>
+    <img src="images/pdf.svg" width="63" height="63" style="position: fixed; cursor: pointer; top: 40%; right: 48px; z-index: 999;" alt="使用PDF预览" title="使用PDF预览" onclick="changePreviewType('pdf')"/>
+</#if>
 <script src="js/watermark.js" type="text/javascript"></script>
 <script>
     window.onload = function () {

+ 3 - 3
jodconverter-web/src/main/resources/web/pdf.ftl

@@ -23,9 +23,9 @@
         <#assign finalUrl="${baseUrl}${pdfUrl}">
     </#if>
     <iframe src="" width="100%" frameborder="0"></iframe>
-
-    <img src="images/jpg.svg" width="63" height="63" style="position: fixed; cursor: pointer; top: 40%; right: 48px; z-index: 999;" alt="使用图片预览" title="使用图片预览" onclick="goForImage()"/>
-
+    <#if "false" == switchDisabled>
+       <img src="images/jpg.svg" width="63" height="63" style="position: fixed; cursor: pointer; top: 40%; right: 48px; z-index: 999;" alt="使用图片预览" title="使用图片预览" onclick="goForImage()"/>
+    </#if>
 </body>
 <script src="js/watermark.js" type="text/javascript"></script>
 <script type="text/javascript">