新功能点:新增配置是否可以下载转换完成的pdf文件

pull/13/head
陈精华 2020-05-14 19:28:21 +08:00 committed by kl
parent 3e80590a82
commit a535ebfe1d
6 changed files with 30 additions and 2 deletions

View File

@ -53,6 +53,8 @@ simText = ${KK_SIMTEXT:txt,html,htm,asp,jsp,xml,json,properties,md,gitignore,,ja
media = ${KK_MEDIA:mp3,wav,mp4,flv}
#office(word ppt)(image)pdf
office.preview.type = ${KK_OFFICE_PREVIEW_TYPE:image}
#pdf
pdf.download.disable = ${KK_PDF_DOWNLOAD_DISABLE:true}
#FTP FTPftp urlftp.username=ftpuser
ftp.username = ${KK_FTP_USERNAME:ftpuser}
@ -82,3 +84,4 @@ watermark.width = ${WATERMARK_WIDTH:180}
watermark.height = ${WATERMARK_HEIGHT:80}
#090
watermark.angle = ${WATERMARK_ANGLE:10}

View File

@ -27,6 +27,7 @@ public class ConfigConstants {
private static String BASE_URL;
private static String FILE_DIR = OfficeUtils.getHomePath() + File.separator + "file" + File.separator;
private static CopyOnWriteArraySet<String> TRUST_HOST_SET;
private static String PDF_DOWNLOAD_DISABLE;
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,,java,py,c,cpp,sql,sh,bat,m,bas,prg,cmd";
@ -38,6 +39,7 @@ public class ConfigConstants {
public static final String DEFAULT_BASE_URL = "default";
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 Boolean isCacheEnabled() {
return CACHE_ENABLED;
@ -141,4 +143,18 @@ public class ConfigConstants {
private static void setTrustHostSet(CopyOnWriteArraySet<String> trustHostSet) {
ConfigConstants.TRUST_HOST_SET = trustHostSet;
}
public static String getPdfDownloadDisable() {
return PDF_DOWNLOAD_DISABLE;
}
public static void setPdfDownloadDisableValue(String pdfDownloadDisable) {
PDF_DOWNLOAD_DISABLE = pdfDownloadDisable;
}
@Value("${pdf.download.disable:true}")
public void setPdfDownloadDisable(String pdfDownloadDisable) {
PDF_DOWNLOAD_DISABLE = pdfDownloadDisable;
}
}

View File

@ -44,6 +44,7 @@ public class ConfigRefreshComponent {
String configFilePath = OfficeUtils.getCustomizedConfigPath();
String baseUrl;
String trustHost;
String pdfDownloadDisable;
while (true) {
FileReader fileReader = new FileReader(configFilePath);
BufferedReader bufferedReader = new BufferedReader(fileReader);
@ -60,6 +61,7 @@ public class ConfigRefreshComponent {
mediaArray = media.split(",");
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);
ConfigConstants.setCacheEnabled(cacheEnabled);
ConfigConstants.setSimText(textArray);
ConfigConstants.setMedia(mediaArray);
@ -69,6 +71,7 @@ public class ConfigRefreshComponent {
ConfigConstants.setFtpControlEncoding(ftpControlEncoding);
ConfigConstants.setBaseUrl(baseUrl);
ConfigConstants.setTrustHost(trustHost);
ConfigConstants.setPdfDownloadDisableValue(pdfDownloadDisable);
setWatermarkConfig(properties);
bufferedReader.close();
fileReader.close();

View File

@ -1,5 +1,6 @@
package cn.keking.web.controller;
import cn.keking.config.ConfigConstants;
import cn.keking.hutool.URLUtil;
import cn.keking.model.FileAttribute;
import cn.keking.service.FilePreview;
@ -51,6 +52,7 @@ public class OnlinePreviewController {
public String onlinePreview(String url, Model model, HttpServletRequest req) {
FileAttribute fileAttribute = fileUtils.getFileAttribute(url);
req.setAttribute("fileKey", req.getParameter("fileKey"));
model.addAttribute("pdfDownloadDisable", ConfigConstants.getPdfDownloadDisable());
model.addAttribute("officePreviewType", req.getParameter("officePreviewType"));
FilePreview filePreview = previewFactory.get(fileAttribute);
logger.info("预览文件url{}previewType{}", url, fileAttribute.getType());

View File

@ -1932,10 +1932,12 @@ function webViewerInitialized() {
var appConfig = PDFViewerApplication.appConfig;
var file = void 0;
var base = void 0;
var disableDownload = void 0;
var queryString = document.location.search.substring(1);
var params = (0, _ui_utils.parseQueryString)(queryString);
file = 'file' in params ? params.file : appConfig.defaultUrl;
base = 'base' in params ? params.base : appConfig.defaultUrl;
disableDownload = 'disabledownload' in params ? params.disabledownload : 'false';
file = validateFileURL(file,base);
var waitForBeforeOpening = [];
var fileInput = document.createElement('input');
@ -2036,6 +2038,9 @@ function webViewerInitialized() {
PDFViewerApplication.error(msg, reason);
});
});
if ('true' === disableDownload) {
document.getElementById("download").style.display='none';
}
}
var webViewerOpenFileViaURL = void 0;
{

View File

@ -26,11 +26,10 @@
<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()"/>
</body>
<script src="js/watermark.js" type="text/javascript"></script>
<script type="text/javascript">
document.getElementsByTagName('iframe')[0].src = "${baseUrl}pdfjs/web/viewer.html?base=${baseUrl}&file="+encodeURIComponent('${finalUrl}');
document.getElementsByTagName('iframe')[0].src = "${baseUrl}pdfjs/web/viewer.html?base=${baseUrl}&file="+encodeURIComponent('${finalUrl}')+"&disabledownload=${pdfDownloadDisable}";
document.getElementsByTagName('iframe')[0].height = document.documentElement.clientHeight-10;
/**
*