diff --git a/server/src/main/java/cn/keking/model/FileType.java b/server/src/main/java/cn/keking/model/FileType.java index 9b9e3f65..62636e40 100644 --- a/server/src/main/java/cn/keking/model/FileType.java +++ b/server/src/main/java/cn/keking/model/FileType.java @@ -24,18 +24,20 @@ public enum FileType { FLV("flvFilePreviewImpl"), CAD("cadFilePreviewImpl"), TIFF("tiffFilePreviewImpl"), + PPT("pptFilePreviewImpl"), OFD("ofdFilePreviewImpl"); - private static final String[] OFFICE_TYPES = {"docx", "wps", "doc", "xls", "xlsx", "ppt", "pptx"}; + private static final String[] OFFICE_TYPES = {"docx", "wps", "doc", "xls", "xlsx"}; + private static final String[] PPT_TYPES = {"ppt", "pptx"}; private static final String[] PICTURE_TYPES = {"jpg", "jpeg", "png", "gif", "bmp", "ico", "raw"}; private static final String[] ARCHIVE_TYPES = {"rar", "zip", "jar", "7-zip", "tar", "gzip", "7z"}; private static final String[] TIFF_TYPES = {"tif", "tiff"}; private static final String[] OFD_TYPES = {"ofd"}; private static final String[] SSIM_TEXT_TYPES = ConfigConstants.getSimText(); - private static final String[] CODES = {"java", "c", "php", "go", "python", "py", "js", "html", "ftl", "css", "lua", "sh", "rb", "yml", "json", "h", "cpp", "cs", "aspx", "jsp"}; + private static final String[] CODES = {"java", "c", "php", "go", "python", "py", "js", "html", "ftl", "css", "lua", "sh", "rb", "yaml", "yml", "json", "h", "cpp", "cs", "aspx", "jsp"}; private static final String[] MEDIA_TYPES = ConfigConstants.getMedia(); - public static final String[] MEDIA_TYPES_CONVERT = ConfigConstants.getConvertMedias(); + private static final String[] MEDIA_TYPES_CONVERT = ConfigConstants.getConvertMedias(); private static final Map FILE_TYPE_MAPPER = new HashMap<>(); static { @@ -66,6 +68,9 @@ public enum FileType { for (String ofd : OFD_TYPES) { FILE_TYPE_MAPPER.put(ofd, FileType.OFD); } + for (String ppt : PPT_TYPES) { + FILE_TYPE_MAPPER.put(ppt, FileType.PPT); + } FILE_TYPE_MAPPER.put("md", FileType.MARKDOWN); FILE_TYPE_MAPPER.put("xml", FileType.XML); FILE_TYPE_MAPPER.put("pdf", FileType.PDF); diff --git a/server/src/main/java/cn/keking/service/FileConvertQueueTask.java b/server/src/main/java/cn/keking/service/FileConvertQueueTask.java index c7e08d7a..dac039e2 100644 --- a/server/src/main/java/cn/keking/service/FileConvertQueueTask.java +++ b/server/src/main/java/cn/keking/service/FileConvertQueueTask.java @@ -7,9 +7,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import org.springframework.ui.ExtendedModelMap; + import javax.annotation.PostConstruct; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; /** @@ -31,9 +30,9 @@ public class FileConvertQueueTask { } @PostConstruct - public void startTask(){ - ExecutorService executorService = Executors.newFixedThreadPool(1); - executorService.submit(new ConvertTask(previewFactory, cacheService, fileHandlerService)); + public void startTask() { + new Thread(new ConvertTask(previewFactory, cacheService, fileHandlerService)) + .start(); logger.info("队列处理文件转换任务启动完成 "); } @@ -58,11 +57,11 @@ public class FileConvertQueueTask { String url = null; try { url = cacheService.takeQueueTask(); - if(url != null){ - FileAttribute fileAttribute = fileHandlerService.getFileAttribute(url,null); + if (url != null) { + FileAttribute fileAttribute = fileHandlerService.getFileAttribute(url, null); FileType fileType = fileAttribute.getType(); logger.info("正在处理预览转换任务,url:{},预览类型:{}", url, fileType); - if(fileType.equals(FileType.COMPRESS) || fileType.equals(FileType.OFFICE) || fileType.equals(FileType.CAD)) { + if (isNeedConvert(fileType)) { FilePreview filePreview = previewFactory.get(fileAttribute); filePreview.filePreviewHandle(url, new ExtendedModelMap(), fileAttribute); } else { @@ -72,13 +71,19 @@ public class FileConvertQueueTask { } catch (Exception e) { try { TimeUnit.SECONDS.sleep(10); - } catch (Exception ex){ + } catch (Exception ex) { + Thread.currentThread().interrupt(); ex.printStackTrace(); } logger.info("处理预览转换任务异常,url:{}", url, e); } } } + + public boolean isNeedConvert(FileType fileType) { + return fileType.equals(FileType.COMPRESS) || fileType.equals(FileType.OFFICE) || fileType.equals(FileType.CAD) || fileType.equals(FileType.PPT); + + } } } diff --git a/server/src/main/java/cn/keking/service/FilePreview.java b/server/src/main/java/cn/keking/service/FilePreview.java index 34f7d32a..db1743d8 100644 --- a/server/src/main/java/cn/keking/service/FilePreview.java +++ b/server/src/main/java/cn/keking/service/FilePreview.java @@ -11,6 +11,7 @@ public interface FilePreview { String FLV_FILE_PREVIEW_PAGE = "flv"; String PDF_FILE_PREVIEW_PAGE = "pdf"; + String PPT_FILE_PREVIEW_PAGE = "ppt"; String COMPRESS_FILE_PREVIEW_PAGE = "compress"; String MEDIA_FILE_PREVIEW_PAGE = "media"; String PICTURE_FILE_PREVIEW_PAGE = "picture"; diff --git a/server/src/main/java/cn/keking/service/impl/PptFilePreviewImpl.java b/server/src/main/java/cn/keking/service/impl/PptFilePreviewImpl.java new file mode 100644 index 00000000..c365eee0 --- /dev/null +++ b/server/src/main/java/cn/keking/service/impl/PptFilePreviewImpl.java @@ -0,0 +1,26 @@ +package cn.keking.service.impl; + +import cn.keking.model.FileAttribute; +import cn.keking.service.FilePreview; +import org.springframework.stereotype.Service; +import org.springframework.ui.Model; + +/** + * @author kl (http://kailing.pub) + * @since 2021/6/17 + */ +@Service +public class PptFilePreviewImpl implements FilePreview { + + private final OfficeFilePreviewImpl officeFilePreview; + + public PptFilePreviewImpl(OfficeFilePreviewImpl officeFilePreview) { + this.officeFilePreview = officeFilePreview; + } + + @Override + public String filePreviewHandle(String url, Model model, FileAttribute fileAttribute) { + officeFilePreview.filePreviewHandle(url,model,fileAttribute); + return PPT_FILE_PREVIEW_PAGE; + } +} diff --git a/server/src/main/java/cn/keking/service/impl/SimTextFilePreviewImpl.java b/server/src/main/java/cn/keking/service/impl/SimTextFilePreviewImpl.java index 6a8d2321..aeacc8e3 100644 --- a/server/src/main/java/cn/keking/service/impl/SimTextFilePreviewImpl.java +++ b/server/src/main/java/cn/keking/service/impl/SimTextFilePreviewImpl.java @@ -5,15 +5,13 @@ import cn.keking.model.FileAttribute; import cn.keking.model.ReturnResponse; import cn.keking.service.FilePreview; import cn.keking.utils.DownloadUtils; -import cn.keking.utils.KkFileUtils; -import jodd.io.FileUtil; +import cn.keking.utils.EncodingDetects; import org.apache.commons.codec.binary.Base64; import org.springframework.stereotype.Service; import org.springframework.ui.Model; import org.springframework.web.util.HtmlUtils; import java.io.*; -import java.nio.charset.StandardCharsets; /** * Created by kl on 2018/1/17. @@ -33,7 +31,7 @@ public class SimTextFilePreviewImpl implements FilePreview { String fileName = fileAttribute.getName(); String baseUrll = FILE_DIR + fileName; - // String suffix = fileAttribute.getSuffix(); + // String suffix = fileAttribute.getSuffix(); ReturnResponse response = DownloadUtils.downLoad(fileAttribute, fileName); if (response.isFailure()) { return otherFilePreview.notSupportedFile(model, fileAttribute, response.getMsg()); diff --git a/server/src/main/java/cn/keking/service/impl/EncodingDetects.java b/server/src/main/java/cn/keking/utils/EncodingDetects.java similarity index 99% rename from server/src/main/java/cn/keking/service/impl/EncodingDetects.java rename to server/src/main/java/cn/keking/utils/EncodingDetects.java index 72a64845..10d75e90 100644 --- a/server/src/main/java/cn/keking/service/impl/EncodingDetects.java +++ b/server/src/main/java/cn/keking/utils/EncodingDetects.java @@ -1,4 +1,4 @@ -package cn.keking.service.impl; +package cn.keking.utils; import java.io.BufferedReader; import java.io.File; diff --git a/server/src/main/resources/web/officePicture.ftl b/server/src/main/resources/web/officePicture.ftl index 91e55ef7..a742413c 100644 --- a/server/src/main/resources/web/officePicture.ftl +++ b/server/src/main/resources/web/officePicture.ftl @@ -1,258 +1,55 @@ -<#if RequestParameters['name']??> -{ - "code": 1, - "name": "pptx", - "totalSize": 0, - "curPage": 1, - "totalPage": 1, - "pageSize": 10, - "titles": null, - "data": [ -<#assign index = 0> -<#list imgurls as img> -<#if index != 0>,{ - "uuid": null, - "title": null, - "content": null, - "text": null, - "url": "${img}", - "destFile": null, - "viewCount": 0, - "downloadCount": 0, - "ctime": null, - "thumbUrl": "${img}", - "largeUrl": null, - "ratio": 0.5625, - "note": null - }<#assign index = index + 1> -], - "desc": "Success" -} - -<#else/> -<#if "${file.suffix?html}" == "ppt" || "${file.suffix?html}" == "pptx"> - - - - - pptx - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-
加载中...
-
- -
- - - -
-
-
- - -
-
-
-
-
- -
- -
- -
-
-
-
- -
-
-
- - - - - - - - - - - - -<#else/> - - - 图片预览 - - - + + PDF图片预览 + <#include "*/commonHeader.ftl"> -
-
    <#list imgurls as img>
    -
  • + loading
    -
- - - +<#if "false" == switchDisabled> + 使用PDF预览 + - - - - + \ No newline at end of file diff --git a/server/src/main/resources/web/ppt.ftl b/server/src/main/resources/web/ppt.ftl new file mode 100644 index 00000000..91e55ef7 --- /dev/null +++ b/server/src/main/resources/web/ppt.ftl @@ -0,0 +1,258 @@ +<#if RequestParameters['name']??> +{ + "code": 1, + "name": "pptx", + "totalSize": 0, + "curPage": 1, + "totalPage": 1, + "pageSize": 10, + "titles": null, + "data": [ +<#assign index = 0> +<#list imgurls as img> +<#if index != 0>,{ + "uuid": null, + "title": null, + "content": null, + "text": null, + "url": "${img}", + "destFile": null, + "viewCount": 0, + "downloadCount": 0, + "ctime": null, + "thumbUrl": "${img}", + "largeUrl": null, + "ratio": 0.5625, + "note": null + }<#assign index = index + 1> +], + "desc": "Success" +} + +<#else/> + + + +<#if "${file.suffix?html}" == "ppt" || "${file.suffix?html}" == "pptx"> + + + + + pptx + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
加载中...
+
+ +
+ + + +
+
+
+ + +
+
+
+
+
+ +
+ +
+ +
+
+
+
+ +
+
+
+ + + + + + + + + + + + +<#else/> + + + 图片预览 + + + + <#include "*/commonHeader.ftl"> + + + +
+
    + <#list imgurls as img> +
    +
  • +
    + +
+
+ + + + + + + + +