From 0c6ea7248adc798582cb6d458ed1547d7122b1ff Mon Sep 17 00:00:00 2001 From: gaoxiongzaq Date: Tue, 19 Dec 2023 08:55:51 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E7=BB=9F=E4=B8=80=E5=91=BD=E5=90=8D?= =?UTF-8?q?=E8=A7=84=E8=8C=83,=E7=AC=A6=E5=90=88=E9=A9=BC=E5=B3=B0?= =?UTF-8?q?=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/keking/model/FileAttribute.java | 36 +++++++++---------- .../main/java/cn/keking/model/FileType.java | 4 +-- .../cn/keking/service/FileHandlerService.java | 36 +++++++++---------- .../service/impl/CadFilePreviewImpl.java | 4 +-- .../service/impl/MediaFilePreviewImpl.java | 6 ++-- .../service/impl/OfficeFilePreviewImpl.java | 8 ++--- .../service/impl/PdfFilePreviewImpl.java | 10 +++--- .../service/impl/SimTextFilePreviewImpl.java | 2 +- .../service/impl/TiffFilePreviewImpl.java | 4 +-- 9 files changed, 55 insertions(+), 55 deletions(-) diff --git a/server/src/main/java/cn/keking/model/FileAttribute.java b/server/src/main/java/cn/keking/model/FileAttribute.java index def5501d..f10c988e 100644 --- a/server/src/main/java/cn/keking/model/FileAttribute.java +++ b/server/src/main/java/cn/keking/model/FileAttribute.java @@ -14,14 +14,14 @@ public class FileAttribute { private String url; private String fileKey; private String filePassword; - private boolean userToken; + private boolean usePasswordCache; private String officePreviewType = ConfigConstants.getOfficePreviewType(); private String tifPreviewType; private Boolean skipDownLoad = false; private Boolean forceUpdatedCache = false; private String cacheName; private String outFilePath; - private String fileNameFilePath; + private String originFilePath; private String cacheListName; private boolean isHtml; @@ -66,12 +66,12 @@ public class FileAttribute { this.filePassword = filePassword; } - public boolean getUserToken() { - return userToken; + public boolean getUsePasswordCache() { + return usePasswordCache; } - public void setUserToken(boolean userToken) { - this.userToken = userToken; + public void setUsePasswordCache(boolean usePasswordCache) { + this.usePasswordCache = usePasswordCache; } public String getOfficePreviewType() { @@ -101,35 +101,35 @@ public class FileAttribute { public String getName() { return name; } - public String getcacheName() { + public String getCacheName() { return cacheName; } - public String getcacheListName() { + public String getCacheListName() { return cacheListName; } - public String getoutFilePath() { + public String getOutFilePath() { return outFilePath; } - public String getfileNameFilePath() { - return fileNameFilePath; + public String getOriginFilePath() { + return originFilePath; } - public boolean getisHtml() { + public boolean getIsHtml() { return isHtml; } - public void setcacheName(String cacheName) { + public void setCacheName(String cacheName) { this.cacheName = cacheName; } - public void setcacheListName(String cacheListName) { + public void setCacheListName(String cacheListName) { this.cacheListName = cacheListName; } - public void setoutFilePath(String outFilePath) { + public void setOutFilePath(String outFilePath) { this.outFilePath = outFilePath; } - public void setfileNameFilePath(String fileNameFilePath) { - this.fileNameFilePath = fileNameFilePath; + public void setOriginFilePath(String originFilePath) { + this.originFilePath = originFilePath; } - public void setisHtml(boolean isHtml) { + public void setIsHtml(boolean isHtml) { this.isHtml = isHtml; } public void setName(String name) { diff --git a/server/src/main/java/cn/keking/model/FileType.java b/server/src/main/java/cn/keking/model/FileType.java index e5870e2d..22d69979 100644 --- a/server/src/main/java/cn/keking/model/FileType.java +++ b/server/src/main/java/cn/keking/model/FileType.java @@ -51,7 +51,7 @@ public enum FileType { 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", "yaml", "yml", "json", "h", "cpp", "cs", "aspx", "jsp", "sql"}; private static final String[] MEDIA_TYPES = ConfigConstants.getMedia(); - public static final String[] MEDIACONVERT_TYPES_CONVERT = ConfigConstants.getConvertMedias(); + public static final String[] MEDIA_CONVERT_TYPES = ConfigConstants.getConvertMedias(); private static final Map FILE_TYPE_MAPPER = new HashMap<>(); static { @@ -70,7 +70,7 @@ public enum FileType { for (String media : MEDIA_TYPES) { FILE_TYPE_MAPPER.put(media, FileType.MEDIA); } - for (String MEDIACONVERT : MEDIACONVERT_TYPES_CONVERT) { + for (String MEDIACONVERT : MEDIA_CONVERT_TYPES) { FILE_TYPE_MAPPER.put( MEDIACONVERT, FileType. MEDIACONVERT); } for (String tif : TIFF_TYPES) { diff --git a/server/src/main/java/cn/keking/service/FileHandlerService.java b/server/src/main/java/cn/keking/service/FileHandlerService.java index c9156e66..0e345647 100644 --- a/server/src/main/java/cn/keking/service/FileHandlerService.java +++ b/server/src/main/java/cn/keking/service/FileHandlerService.java @@ -241,7 +241,7 @@ public class FileHandlerService implements InitializingBean { */ public List pdf2jpg(String fileNameFilePath,String pdfFilePath, String pdfName, FileAttribute fileAttribute) throws Exception { boolean forceUpdatedCache = fileAttribute.forceUpdatedCache(); - boolean userToken = fileAttribute.getUserToken(); + boolean userToken = fileAttribute.getUsePasswordCache(); String filePassword = fileAttribute.getFilePassword(); String fileKey = fileAttribute.getFileKey(); String pdfPassword = null; @@ -431,10 +431,10 @@ public class FileHandlerService implements InitializingBean { FileType type; String fileName; //原始文件名 String cacheName; //缓存文件名 - String cacheUnifyName; //缓存文件名统一去除文件后缀名 + String cachePrefixName; //缓存文件名统一去除文件后缀名 String cacheListName; //缓存列表文件名称 String outFilePath; //生成文件的路径 - String fileNameFilePath; //原始文件路径 + String originFilePath; //原始文件路径 String fullFileName = WebUtils.getUrlParameterReg(url, "fullfilename"); String fileKey = WebUtils.getUrlParameterReg(url, "kkCompressfileKey"); //压缩包指定特殊符号 if (StringUtils.hasText(fullFileName)) { @@ -472,20 +472,20 @@ public class FileHandlerService implements InitializingBean { } fileName = KkFileUtils.htmlEscape(fileName); //文件名处理 boolean isHtml = suffix.equalsIgnoreCase("xls") || suffix.equalsIgnoreCase("xlsx") || suffix.equalsIgnoreCase("csv") || suffix.equalsIgnoreCase("xlsm") || suffix.equalsIgnoreCase("xlt") || suffix.equalsIgnoreCase("xltm") || suffix.equalsIgnoreCase("et") || suffix.equalsIgnoreCase("ett") || suffix.equalsIgnoreCase("xlam"); - cacheUnifyName = fileName.substring(0, fileName.lastIndexOf(".") ) + suffix+"."; //这里统一文件名处理 下面更具类型 各自添加后缀 + cachePrefixName = fileName.substring(0, fileName.lastIndexOf(".") ) + suffix+"."; //这里统一文件名处理 下面更具类型 各自添加后缀 if(type.equals(FileType.OFFICE)){ - cacheName = cacheUnifyName +(isHtml ? "html" : "pdf"); //生成文件添加类型后缀 防止同名文件 + cacheName = cachePrefixName +(isHtml ? "html" : "pdf"); //生成文件添加类型后缀 防止同名文件 }else if(type.equals(FileType.PDF)){ cacheName = fileName; }else if(type.equals(FileType.MEDIACONVERT)){ - cacheName = cacheUnifyName +"mp4" ; + cacheName = cachePrefixName +"mp4" ; }else if(type.equals(FileType.CAD)){ String cadPreviewType = ConfigConstants.getCadPreviewType(); - cacheName = cacheUnifyName + cadPreviewType ; //生成文件添加类型后缀 防止同名文件 + cacheName = cachePrefixName + cadPreviewType ; //生成文件添加类型后缀 防止同名文件 }else if(type.equals(FileType.COMPRESS)){ cacheName = fileName; }else if(type.equals(FileType.TIFF)){ - cacheName = cacheUnifyName + ConfigConstants.getTifPreviewType(); + cacheName = cachePrefixName + ConfigConstants.getTifPreviewType(); }else { cacheName = fileName; } @@ -493,21 +493,21 @@ public class FileHandlerService implements InitializingBean { cacheName = "_decompression"+ cacheName; } outFilePath = fileDir + cacheName; - fileNameFilePath = fileDir + fileName; - cacheListName = cacheUnifyName+"ListName"; //文件列表缓存文件名 + originFilePath = fileDir + fileName; + cacheListName = cachePrefixName+"ListName"; //文件列表缓存文件名 attribute.setType(type); attribute.setName(fileName); - attribute.setcacheName(cacheName); - attribute.setcacheListName(cacheListName); - attribute.setisHtml(isHtml); - attribute.setoutFilePath(outFilePath); - attribute.setfileNameFilePath(fileNameFilePath); + attribute.setCacheName(cacheName); + attribute.setCacheListName(cacheListName); + attribute.setIsHtml(isHtml); + attribute.setOutFilePath(outFilePath); + attribute.setOriginFilePath(originFilePath); attribute.setSuffix(suffix); attribute.setUrl(url); if (req != null) { String officePreviewType = req.getParameter("officePreviewType"); String forceUpdatedCache = req.getParameter("forceUpdatedCache"); - String userToken =req.getParameter("userToken"); + String usePasswordCache =req.getParameter("usePasswordCache"); if (StringUtils.hasText(officePreviewType)) { attribute.setOfficePreviewType(officePreviewType); } @@ -527,8 +527,8 @@ public class FileHandlerService implements InitializingBean { if (StringUtils.hasText(filePassword)) { attribute.setFilePassword(filePassword); } - if ("true".equalsIgnoreCase(userToken)) { - attribute.setUserToken(true); + if ("true".equalsIgnoreCase(usePasswordCache)) { + attribute.setUsePasswordCache(true); } String kkProxyAuthorization = req.getHeader( "kk-proxy-authorization"); attribute.setKkProxyAuthorization(kkProxyAuthorization); diff --git a/server/src/main/java/cn/keking/service/impl/CadFilePreviewImpl.java b/server/src/main/java/cn/keking/service/impl/CadFilePreviewImpl.java index 17c39ec4..1dc90ed3 100644 --- a/server/src/main/java/cn/keking/service/impl/CadFilePreviewImpl.java +++ b/server/src/main/java/cn/keking/service/impl/CadFilePreviewImpl.java @@ -41,8 +41,8 @@ public class CadFilePreviewImpl implements FilePreview { boolean forceUpdatedCache=fileAttribute.forceUpdatedCache(); String fileName = fileAttribute.getName(); String cadPreviewType = ConfigConstants.getCadPreviewType(); - String cacheName = fileAttribute.getcacheName(); - String outFilePath = fileAttribute.getoutFilePath(); + String cacheName = fileAttribute.getCacheName(); + String outFilePath = fileAttribute.getOutFilePath(); String fileKey = fileAttribute.getFileKey(); //判断是否压缩包 // 判断之前是否已转换过,如果转换过,直接返回,否则执行转换 if (forceUpdatedCache || !fileHandlerService.listConvertedFiles().containsKey(cacheName) || !ConfigConstants.isCacheEnabled()) { diff --git a/server/src/main/java/cn/keking/service/impl/MediaFilePreviewImpl.java b/server/src/main/java/cn/keking/service/impl/MediaFilePreviewImpl.java index 1842b8a6..71fc2e1a 100644 --- a/server/src/main/java/cn/keking/service/impl/MediaFilePreviewImpl.java +++ b/server/src/main/java/cn/keking/service/impl/MediaFilePreviewImpl.java @@ -36,12 +36,12 @@ public class MediaFilePreviewImpl implements FilePreview { public String filePreviewHandle(String url, Model model, FileAttribute fileAttribute) { String fileName = fileAttribute.getName(); String suffix = fileAttribute.getSuffix(); - String cacheName = fileAttribute.getcacheName(); - String outFilePath = fileAttribute.getoutFilePath(); + String cacheName = fileAttribute.getCacheName(); + String outFilePath = fileAttribute.getOutFilePath(); boolean forceUpdatedCache=fileAttribute.forceUpdatedCache(); String fileKey = fileAttribute.getFileKey(); FileType type = fileAttribute.getType(); - String[] mediaTypesConvert = FileType.MEDIACONVERT_TYPES_CONVERT; //获取支持的转换格式 + String[] mediaTypesConvert = FileType.MEDIA_CONVERT_TYPES; //获取支持的转换格式 boolean mediaTypes = false; for(String temp : mediaTypesConvert){ if (suffix.equals(temp)) { 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 ae1a7a13..000a8e5a 100644 --- a/server/src/main/java/cn/keking/service/impl/OfficeFilePreviewImpl.java +++ b/server/src/main/java/cn/keking/service/impl/OfficeFilePreviewImpl.java @@ -46,15 +46,15 @@ public class OfficeFilePreviewImpl implements FilePreview { public String filePreviewHandle(String url, Model model, FileAttribute fileAttribute) { // 预览Type,参数传了就取参数的,没传取系统默认 String officePreviewType = fileAttribute.getOfficePreviewType(); - boolean userToken = fileAttribute.getUserToken(); + boolean userToken = fileAttribute.getUsePasswordCache(); String baseUrl = BaseUrlFilter.getBaseUrl(); String suffix = fileAttribute.getSuffix(); //获取文件后缀 String fileName = fileAttribute.getName(); //获取文件原始名称 String filePassword = fileAttribute.getFilePassword(); //获取密码 boolean forceUpdatedCache=fileAttribute.forceUpdatedCache(); //是否启用强制更新命令 - boolean isHtml =fileAttribute.getisHtml(); //xlsx 转换成html - String cacheName = fileAttribute.getcacheName(); //转换后的文件名 - String outFilePath = fileAttribute.getoutFilePath(); //转换后生成文件的路径 + boolean isHtml =fileAttribute.getIsHtml(); //xlsx 转换成html + String cacheName = fileAttribute.getCacheName(); //转换后的文件名 + String outFilePath = fileAttribute.getOutFilePath(); //转换后生成文件的路径 String fileKey = fileAttribute.getFileKey(); //判断是否压缩包 if (!officePreviewType.equalsIgnoreCase("html")) { if (ConfigConstants.getOfficeTypeWeb() .equalsIgnoreCase("web")) { 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 7d91f640..925820cb 100644 --- a/server/src/main/java/cn/keking/service/impl/PdfFilePreviewImpl.java +++ b/server/src/main/java/cn/keking/service/impl/PdfFilePreviewImpl.java @@ -34,8 +34,8 @@ public class PdfFilePreviewImpl implements FilePreview { String pdfName = fileAttribute.getName(); //获取原始文件名 String officePreviewType = fileAttribute.getOfficePreviewType(); //转换类型 boolean forceUpdatedCache=fileAttribute.forceUpdatedCache(); //是否启用强制更新命令 - String outFilePath = fileAttribute.getoutFilePath(); //生成的文件路径 - String fileNameFilePath = fileAttribute.getfileNameFilePath(); //原始文件路径 + String outFilePath = fileAttribute.getOutFilePath(); //生成的文件路径 + String originFilePath = fileAttribute.getOriginFilePath(); //原始文件路径 if (OfficeFilePreviewImpl.OFFICE_PREVIEW_TYPE_IMAGE.equals(officePreviewType) || OfficeFilePreviewImpl.OFFICE_PREVIEW_TYPE_ALL_IMAGES.equals(officePreviewType)) { //当文件不存在时,就去下载 if (forceUpdatedCache || !fileHandlerService.listConvertedFiles().containsKey(pdfName) || !ConfigConstants.isCacheEnabled()) { @@ -43,15 +43,15 @@ public class PdfFilePreviewImpl implements FilePreview { if (response.isFailure()) { return otherFilePreview.notSupportedFile(model, fileAttribute, response.getMsg()); } - fileNameFilePath = response.getContent(); + originFilePath = response.getContent(); if (ConfigConstants.isCacheEnabled()) { // 加入缓存 - fileHandlerService.addConvertedFile(pdfName, fileHandlerService.getRelativePath(fileNameFilePath)); + fileHandlerService.addConvertedFile(pdfName, fileHandlerService.getRelativePath(originFilePath)); } } List imageUrls; try { - imageUrls = fileHandlerService.pdf2jpg(fileNameFilePath,outFilePath, pdfName, fileAttribute); + imageUrls = fileHandlerService.pdf2jpg(originFilePath,outFilePath, pdfName, fileAttribute); } catch (Exception e) { Throwable[] throwableArray = ExceptionUtils.getThrowables(e); for (Throwable throwable : throwableArray) { 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 8df5ffdc..9543abb5 100644 --- a/server/src/main/java/cn/keking/service/impl/SimTextFilePreviewImpl.java +++ b/server/src/main/java/cn/keking/service/impl/SimTextFilePreviewImpl.java @@ -35,7 +35,7 @@ public class SimTextFilePreviewImpl implements FilePreview { public String filePreviewHandle(String url, Model model, FileAttribute fileAttribute) { String fileName = fileAttribute.getName(); boolean forceUpdatedCache=fileAttribute.forceUpdatedCache(); - String filePath = fileAttribute.getfileNameFilePath(); + String filePath = fileAttribute.getOriginFilePath(); if (forceUpdatedCache || !fileHandlerService.listConvertedFiles().containsKey(fileName) || !ConfigConstants.isCacheEnabled()) { ReturnResponse response = DownloadUtils.downLoad(fileAttribute, fileName); if (response.isFailure()) { diff --git a/server/src/main/java/cn/keking/service/impl/TiffFilePreviewImpl.java b/server/src/main/java/cn/keking/service/impl/TiffFilePreviewImpl.java index 0eea6a3c..6e08e159 100644 --- a/server/src/main/java/cn/keking/service/impl/TiffFilePreviewImpl.java +++ b/server/src/main/java/cn/keking/service/impl/TiffFilePreviewImpl.java @@ -34,8 +34,8 @@ public class TiffFilePreviewImpl implements FilePreview { public String filePreviewHandle(String url, Model model, FileAttribute fileAttribute) { String fileName = fileAttribute.getName(); String tifPreviewType = ConfigConstants.getTifPreviewType(); - String cacheName = fileAttribute.getcacheName(); - String outFilePath = fileAttribute.getoutFilePath(); + String cacheName = fileAttribute.getCacheName(); + String outFilePath = fileAttribute.getOutFilePath(); String fileKey = fileAttribute.getFileKey(); //判断是否压缩包 boolean forceUpdatedCache=fileAttribute.forceUpdatedCache(); if ("jpg".equalsIgnoreCase(tifPreviewType) || "pdf".equalsIgnoreCase(tifPreviewType)) { From 218f9f001514a7eafa97b7f9c50d073dac37c92b Mon Sep 17 00:00:00 2001 From: gaoxiongzaq Date: Tue, 19 Dec 2023 09:06:22 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E7=BB=9F=E4=B8=80=E5=91=BD=E5=90=8D?= =?UTF-8?q?=E8=A7=84=E8=8C=83,=E7=AC=A6=E5=90=88=E9=A9=BC=E5=B3=B0?= =?UTF-8?q?=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/cn/keking/service/FileHandlerService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/cn/keking/service/FileHandlerService.java b/server/src/main/java/cn/keking/service/FileHandlerService.java index 0e345647..5517b49e 100644 --- a/server/src/main/java/cn/keking/service/FileHandlerService.java +++ b/server/src/main/java/cn/keking/service/FileHandlerService.java @@ -241,7 +241,7 @@ public class FileHandlerService implements InitializingBean { */ public List pdf2jpg(String fileNameFilePath,String pdfFilePath, String pdfName, FileAttribute fileAttribute) throws Exception { boolean forceUpdatedCache = fileAttribute.forceUpdatedCache(); - boolean userToken = fileAttribute.getUsePasswordCache(); + boolean UsePasswordCache = fileAttribute.getUsePasswordCache(); String filePassword = fileAttribute.getFilePassword(); String fileKey = fileAttribute.getFileKey(); String pdfPassword = null; @@ -300,7 +300,7 @@ public class FileHandlerService implements InitializingBean { } } - if (userToken || !PDF_PASSWORD_MSG.equals(pdfPassword)) { //加密文件 判断是否启用缓存命令 + if (UsePasswordCache || !PDF_PASSWORD_MSG.equals(pdfPassword)) { //加密文件 判断是否启用缓存命令 this.addPdf2jpgCache(pdfFilePath, pageCount); } } catch (IOException e) { From 9de1ae8c11674a1bb0dde519070647d1d65e4f4c Mon Sep 17 00:00:00 2001 From: gaoxiongzaq Date: Tue, 19 Dec 2023 10:00:29 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E7=BB=9F=E4=B8=80=E5=91=BD=E5=90=8D?= =?UTF-8?q?=E8=A7=84=E8=8C=83,=E7=AC=A6=E5=90=88=E9=A9=BC=E5=B3=B0?= =?UTF-8?q?=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/cn/keking/service/FileHandlerService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/cn/keking/service/FileHandlerService.java b/server/src/main/java/cn/keking/service/FileHandlerService.java index 5517b49e..87acb5d1 100644 --- a/server/src/main/java/cn/keking/service/FileHandlerService.java +++ b/server/src/main/java/cn/keking/service/FileHandlerService.java @@ -241,7 +241,7 @@ public class FileHandlerService implements InitializingBean { */ public List pdf2jpg(String fileNameFilePath,String pdfFilePath, String pdfName, FileAttribute fileAttribute) throws Exception { boolean forceUpdatedCache = fileAttribute.forceUpdatedCache(); - boolean UsePasswordCache = fileAttribute.getUsePasswordCache(); + boolean usePasswordCache = fileAttribute.getUsePasswordCache(); String filePassword = fileAttribute.getFilePassword(); String fileKey = fileAttribute.getFileKey(); String pdfPassword = null; @@ -300,7 +300,7 @@ public class FileHandlerService implements InitializingBean { } } - if (UsePasswordCache || !PDF_PASSWORD_MSG.equals(pdfPassword)) { //加密文件 判断是否启用缓存命令 + if (usePasswordCache || !PDF_PASSWORD_MSG.equals(pdfPassword)) { //加密文件 判断是否启用缓存命令 this.addPdf2jpgCache(pdfFilePath, pageCount); } } catch (IOException e) {