From c0ab0af5ecde20de42d445958b4c94592d1c92b4 Mon Sep 17 00:00:00 2001 From: weiweiw <14335254+weiweiw22@user.noreply.gitee.com> Date: Fri, 7 Jun 2024 08:41:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/main/config/application.properties | 8 ++------ .../cn/keking/service/impl/OfficeFilePreviewImpl.java | 8 ++++++++ .../java/cn/keking/service/impl/PdfFilePreviewImpl.java | 5 +++++ .../cn/keking/web/controller/OnlinePreviewController.java | 8 ++++---- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/server/src/main/config/application.properties b/server/src/main/config/application.properties index 58aec58..f1eb953 100644 --- a/server/src/main/config/application.properties +++ b/server/src/main/config/application.properties @@ -125,7 +125,7 @@ pdf.bookmark.disable = ${KK_PDF_BOOKMARK_DISABLE:true} pdf.disable.editing = ${KK_PDF_DISABLE_EDITING:false} #office类型文档(word ppt)样式,默认为图片(image),可配置为pdf(预览时也有按钮切换) #image or pdf -office.preview.type = ${KK_OFFICE_PREVIEW_TYPE:image} +office.preview.type = ${KK_OFFICE_PREVIEW_TYPE:pdf} #是否关闭office预览切换开关,默认为false,可配置为true关闭 office.preview.switch.disabled = ${KK_OFFICE_PREVIEW_SWITCH_DISABLED:false} @@ -193,15 +193,11 @@ token.enable=${KK_TOKEN_ENABLE:true} #Unit, unit is minute token.expire.time=${KK_TOKEN_EXPIRE_TIME:10} -#???? +#aes key aes.key.algorithm=${KK_AESKEY_ALGORITHM:AES} -#??????????? aes.cipher.algorithm=${KK_AESKEY_CIPHER_ALGORITHM:AES/CBC/PKCS7Padding} -#????? aes.encryption.provider = ${KK_AESKEY_ENCRYPTION_PROVIDER:BC} -#?? aes.key=${KK_AESKEY_KEY:zhgd@bonus@zhgd@bonus@1234567890} -#??? aes.iv=${KK_AESKEY_IV:1234567812345678} password.error.msg = ${PASSWORD_ERROR_MSG:password} \ No newline at end of file diff --git a/server/src/main/java/cn/keking/service/impl/OfficeFilePreviewImpl.java b/server/src/main/java/cn/keking/service/impl/OfficeFilePreviewImpl.java index 7b62ca9..f851a47 100644 --- a/server/src/main/java/cn/keking/service/impl/OfficeFilePreviewImpl.java +++ b/server/src/main/java/cn/keking/service/impl/OfficeFilePreviewImpl.java @@ -10,10 +10,13 @@ import cn.keking.utils.DownloadUtils; import cn.keking.utils.KkFileUtils; import cn.keking.utils.OfficeUtils; import cn.keking.utils.WebUtils; +import cn.keking.web.controller.OnlinePreviewController; import cn.keking.web.filter.BaseUrlFilter; import org.apache.commons.lang3.exception.ExceptionUtils; import org.apache.poi.EncryptedDocumentException; import org.jodconverter.core.office.OfficeException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import org.springframework.ui.Model; import org.springframework.util.StringUtils; @@ -32,6 +35,7 @@ public class OfficeFilePreviewImpl implements FilePreview { public static final String OFFICE_PREVIEW_TYPE_ALL_IMAGES = "allImages"; private static final String OFFICE_PASSWORD_MSG = ConfigConstants.getPasswordErrorMsg(); + private final Logger logger = LoggerFactory.getLogger(OfficeFilePreviewImpl.class); private final FileHandlerService fileHandlerService; private final OfficeToPdfService officeToPdfService; private final OtherFilePreviewImpl otherFilePreview; @@ -87,7 +91,9 @@ public class OfficeFilePreviewImpl implements FilePreview { } else { if (StringUtils.hasText(outFilePath)) { try { + logger.info("start to officeToPdfService.openOfficeToPDF"); officeToPdfService.openOfficeToPDF(filePath, outFilePath, fileAttribute); + logger.info("end to officeToPdfService.openOfficeToPDF"); } catch (OfficeException e) { if (isPwdProtectedOffice && !OfficeUtils.isCompatible(filePath, filePassword)) { // 加密文件密码错误,提示重新输入 @@ -137,7 +143,9 @@ public class OfficeFilePreviewImpl implements FilePreview { List imageUrls = null; // long startime = System.currentTimeMillis(); try { + System.out.println("start to fileHandlerService.pdf2jpg"); imageUrls = fileHandlerService.pdf2jpg(outFilePath,outFilePath, pdfName, fileAttribute); + System.out.println("end to fileHandlerService.pdf2jpg"); //System.out.println("fileHandlerService.pdf2jpg 结果:" +imageUrls + ",outFilePath:" + outFilePath + ",pdfName:" + pdfName ); } catch (Exception e) { Throwable[] throwableArray = ExceptionUtils.getThrowables(e); diff --git a/server/src/main/java/cn/keking/service/impl/PdfFilePreviewImpl.java b/server/src/main/java/cn/keking/service/impl/PdfFilePreviewImpl.java index f1a38ea..933a48c 100644 --- a/server/src/main/java/cn/keking/service/impl/PdfFilePreviewImpl.java +++ b/server/src/main/java/cn/keking/service/impl/PdfFilePreviewImpl.java @@ -9,6 +9,8 @@ import cn.keking.utils.DownloadUtils; import cn.keking.utils.WebUtils; import org.apache.commons.lang3.exception.ExceptionUtils; import org.apache.poi.EncryptedDocumentException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import org.springframework.ui.Model; @@ -25,6 +27,7 @@ public class PdfFilePreviewImpl implements FilePreview { private final FileHandlerService fileHandlerService; private final OtherFilePreviewImpl otherFilePreview; private final String pdfPwdErrorMsg = ConfigConstants.getPasswordErrorMsg(); + private final Logger logger = LoggerFactory.getLogger(PdfFilePreviewImpl.class); public PdfFilePreviewImpl(FileHandlerService fileHandlerService, OtherFilePreviewImpl otherFilePreview) { this.fileHandlerService = fileHandlerService; this.otherFilePreview = otherFilePreview; @@ -51,7 +54,9 @@ public class PdfFilePreviewImpl implements FilePreview { } List imageUrls; try { + logger.info("start to fileHandlerService.pdf2jpg"); imageUrls = fileHandlerService.pdf2jpg(originFilePath,outFilePath, pdfName, fileAttribute); + logger.info("end to fileHandlerService.pdf2jpg"); } catch (Exception e) { Throwable[] throwableArray = ExceptionUtils.getThrowables(e); for (Throwable throwable : throwableArray) { diff --git a/server/src/main/java/cn/keking/web/controller/OnlinePreviewController.java b/server/src/main/java/cn/keking/web/controller/OnlinePreviewController.java index 63cefeb..6b50713 100644 --- a/server/src/main/java/cn/keking/web/controller/OnlinePreviewController.java +++ b/server/src/main/java/cn/keking/web/controller/OnlinePreviewController.java @@ -65,11 +65,11 @@ public class OnlinePreviewController { } @GetMapping( "/onlinePreview") - public String onlinePreview(String url, Model model, HttpServletRequest req, @RequestHeader("Token") String headerValue) { + public String onlinePreview(String url, Model model, HttpServletRequest req, String token) { String fileUrl; try { - if (!WebUtils.checkToken(headerValue)) { + if (!WebUtils.checkToken(token)) { return otherFilePreview.notSupportedFile(model, "token 错误"); } fileUrl = WebUtils.decodeUrl(url); @@ -90,11 +90,11 @@ public class OnlinePreviewController { @GetMapping( "/onConvert") @ResponseBody - public String onConvert(String url, Model model, HttpServletRequest req, @RequestHeader("Token") String headerValue) { + public String onConvert(String url, Model model, HttpServletRequest req, String token) { String fileUrl; try { - if (!WebUtils.checkToken(headerValue)) { + if (!WebUtils.checkToken(token)) { return otherFilePreview.notSupportedFile(model, "token 错误"); } fileUrl = WebUtils.decodeUrl(url);