1、抽象整理FileType的获取逻辑

2、合理设置预览消费队列的线程数
encoding
chenkailing 4 years ago committed by kl
parent 37c37868a3
commit 0f4f1d580b

@ -1,5 +1,6 @@
[#ftl] [#ftl]
[#-- @implicitly included --] [#-- @implicitly included --]
[#-- @ftlvariable name="imgUrls" type="String" --]
[#-- @ftlvariable name="textData" type="java.lang.String" --] [#-- @ftlvariable name="textData" type="java.lang.String" --]
[#-- @ftlvariable name="xmlContent" type="java.lang.String" --] [#-- @ftlvariable name="xmlContent" type="java.lang.String" --]
[#-- @ftlvariable name="textContent" type="java.lang.String" --] [#-- @ftlvariable name="textContent" type="java.lang.String" --]

@ -1,5 +1,10 @@
package cn.keking.model; package cn.keking.model;
import cn.keking.config.ConfigConstants;
import java.util.HashMap;
import java.util.Map;
/** /**
* Created by kl on 2018/1/17. * Created by kl on 2018/1/17.
* Content :office * Content :office
@ -16,11 +21,43 @@ public enum FileType {
xml("xmlFilePreviewImpl"), xml("xmlFilePreviewImpl"),
cad("cadFilePreviewImpl"); cad("cadFilePreviewImpl");
private static final String[] OFFICE_TYPES = {"docx", "doc", "xls", "xlsx", "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[] SIMTEXT_TYPES = ConfigConstants.getSimText();
private static final String[] MEDIA_TYPES = ConfigConstants.getMedia();
private static final Map<String, FileType> FILE_TYPE_MAPPER = new HashMap<>();
static {
for (String office : OFFICE_TYPES) {
FILE_TYPE_MAPPER.put(office, FileType.office);
}
for (String picture : PICTURE_TYPES) {
FILE_TYPE_MAPPER.put(picture, FileType.picture);
}
for (String archive : ARCHIVE_TYPES) {
FILE_TYPE_MAPPER.put(archive, FileType.compress);
}
for (String text : SIMTEXT_TYPES) {
FILE_TYPE_MAPPER.put(text, FileType.simText);
}
for (String media : MEDIA_TYPES) {
FILE_TYPE_MAPPER.put(media, FileType.media);
}
FILE_TYPE_MAPPER.put("md", FileType.markdown);
FILE_TYPE_MAPPER.put("xml", FileType.xml);
FILE_TYPE_MAPPER.put("pdf", FileType.pdf);
FILE_TYPE_MAPPER.put("dwg", FileType.cad);
}
public static FileType to(String fileType){
return FILE_TYPE_MAPPER.getOrDefault(fileType,other);
}
private final String instanceName; private final String instanceName;
FileType(String instanceName){ FileType(String instanceName) {
this.instanceName=instanceName; this.instanceName = instanceName;
} }
public String getInstanceName() { public String getInstanceName() {

@ -3,7 +3,6 @@ package cn.keking.service;
import cn.keking.model.FileAttribute; import cn.keking.model.FileAttribute;
import cn.keking.model.FileType; import cn.keking.model.FileType;
import cn.keking.service.cache.CacheService; import cn.keking.service.cache.CacheService;
import cn.keking.utils.FileUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -20,44 +19,36 @@ import java.util.concurrent.Executors;
public class FileConvertQueueTask { public class FileConvertQueueTask {
private final Logger logger = LoggerFactory.getLogger(getClass()); private final Logger logger = LoggerFactory.getLogger(getClass());
private final FilePreviewFactory previewFactory; private final FilePreviewFactory previewFactory;
private final CacheService cacheService; private final CacheService cacheService;
private final FilePreviewCommonService filePreviewCommonService;
private final FileUtils fileUtils; public FileConvertQueueTask(FilePreviewFactory previewFactory, CacheService cacheService, FilePreviewCommonService filePreviewCommonService) {
public FileConvertQueueTask(FilePreviewFactory previewFactory,
CacheService cacheService,
FileUtils fileUtils) {
this.previewFactory = previewFactory; this.previewFactory = previewFactory;
this.cacheService = cacheService; this.cacheService = cacheService;
this.fileUtils=fileUtils; this.filePreviewCommonService = filePreviewCommonService;
} }
@PostConstruct @PostConstruct
public void startTask(){ public void startTask(){
ExecutorService executorService = Executors.newFixedThreadPool(3); ExecutorService executorService = Executors.newFixedThreadPool(1);
executorService.submit(new ConvertTask(previewFactory, cacheService, fileUtils)); executorService.submit(new ConvertTask(previewFactory, cacheService, filePreviewCommonService));
logger.info("队列处理文件转换任务启动完成 "); logger.info("队列处理文件转换任务启动完成 ");
} }
static class ConvertTask implements Runnable { static class ConvertTask implements Runnable {
private final Logger logger = LoggerFactory.getLogger(ConvertTask.class); private final Logger logger = LoggerFactory.getLogger(ConvertTask.class);
private final FilePreviewFactory previewFactory; private final FilePreviewFactory previewFactory;
private final CacheService cacheService; private final CacheService cacheService;
private final FilePreviewCommonService filePreviewCommonService;
private final FileUtils fileUtils;
public ConvertTask(FilePreviewFactory previewFactory, public ConvertTask(FilePreviewFactory previewFactory,
CacheService cacheService, CacheService cacheService,
FileUtils fileUtils) { FilePreviewCommonService filePreviewCommonService) {
this.previewFactory = previewFactory; this.previewFactory = previewFactory;
this.cacheService = cacheService; this.cacheService = cacheService;
this.fileUtils=fileUtils; this.filePreviewCommonService = filePreviewCommonService;
} }
@Override @Override
@ -67,7 +58,7 @@ public class FileConvertQueueTask {
try { try {
url = cacheService.takeQueueTask(); url = cacheService.takeQueueTask();
if(url != null){ if(url != null){
FileAttribute fileAttribute = fileUtils.getFileAttribute(url,null); FileAttribute fileAttribute = filePreviewCommonService.getFileAttribute(url,null);
FileType fileType = fileAttribute.getType(); FileType fileType = fileAttribute.getType();
logger.info("正在处理预览转换任务url{},预览类型:{}", url, fileType); logger.info("正在处理预览转换任务url{},预览类型:{}", url, fileType);
if(fileType.equals(FileType.compress) || fileType.equals(FileType.office) || fileType.equals(FileType.cad)) { if(fileType.equals(FileType.compress) || fileType.equals(FileType.office) || fileType.equals(FileType.cad)) {

@ -1,4 +1,4 @@
package cn.keking.utils; package cn.keking.service;
import cn.keking.config.ConfigConstants; import cn.keking.config.ConfigConstants;
import cn.keking.model.FileAttribute; import cn.keking.model.FileAttribute;
@ -18,14 +18,14 @@ import java.util.*;
* @date 2017/11/13 * @date 2017/11/13
*/ */
@Component @Component
public class FileUtils { public class FilePreviewCommonService {
private static final String DEFAULT_CONVERTER_CHARSET = System.getProperty("sun.jnu.encoding"); private static final String DEFAULT_CONVERTER_CHARSET = System.getProperty("sun.jnu.encoding");
private final String fileDir = ConfigConstants.getFileDir(); private final String fileDir = ConfigConstants.getFileDir();
private final CacheService cacheService; private final CacheService cacheService;
public FileUtils(CacheService cacheService) { public FilePreviewCommonService(CacheService cacheService) {
this.cacheService = cacheService; this.cacheService = cacheService;
} }
@ -60,41 +60,12 @@ public class FileUtils {
public FileType typeFromUrl(String url) { public FileType typeFromUrl(String url) {
String nonPramStr = url.substring(0, url.contains("?") ? url.indexOf("?") : url.length()); String nonPramStr = url.substring(0, url.contains("?") ? url.indexOf("?") : url.length());
String fileName = nonPramStr.substring(nonPramStr.lastIndexOf("/") + 1); String fileName = nonPramStr.substring(nonPramStr.lastIndexOf("/") + 1);
return typeFromFileName(fileName); return this.typeFromFileName(fileName);
} }
private FileType typeFromFileName(String fileName) { private FileType typeFromFileName(String fileName) {
String[] simText = ConfigConstants.getSimText();
String[] media = ConfigConstants.getMedia();
String fileType = fileName.substring(fileName.lastIndexOf(".") + 1); String fileType = fileName.substring(fileName.lastIndexOf(".") + 1);
if (listPictureTypes().contains(fileType.toLowerCase())) { return FileType.to(fileType);
return FileType.picture;
}
if (listArchiveTypes().contains(fileType.toLowerCase())) {
return FileType.compress;
}
if (listOfficeTypes().contains(fileType.toLowerCase())) {
return FileType.office;
}
if ("md".equalsIgnoreCase(fileType)) {
return FileType.markdown;
}
if ("xml".equalsIgnoreCase(fileType)) {
return FileType.xml;
}
if (Arrays.asList(simText).contains(fileType.toLowerCase())) {
return FileType.simText;
}
if (Arrays.asList(media).contains(fileType.toLowerCase())) {
return FileType.media;
}
if ("pdf".equalsIgnoreCase(fileType)) {
return FileType.pdf;
}
if ("dwg".equalsIgnoreCase(fileType)) {
return FileType.cad;
}
return FileType.other;
} }
/** /**
@ -120,41 +91,6 @@ public class FileUtils {
return path.substring(path.lastIndexOf(File.separator) + 1); return path.substring(path.lastIndexOf(File.separator) + 1);
} }
public List<String> listPictureTypes() {
List<String> list = new LinkedList<>();
list.add("jpg");
list.add("jpeg");
list.add("png");
list.add("gif");
list.add("bmp");
list.add("ico");
list.add("RAW");
return list;
}
public List<String> listArchiveTypes() {
List<String> list = new LinkedList<>();
list.add("rar");
list.add("zip");
list.add("jar");
list.add("7-zip");
list.add("tar");
list.add("gzip");
list.add("7z");
return list;
}
public List<String> listOfficeTypes() {
List<String> list = new LinkedList<>();
list.add("docx");
list.add("doc");
list.add("xls");
list.add("xlsx");
list.add("ppt");
list.add("pptx");
return list;
}
/** /**
* *
* *
@ -341,7 +277,7 @@ public class FileUtils {
String fullFileName = this.getUrlParameterReg(url, "fullfilename"); String fullFileName = this.getUrlParameterReg(url, "fullfilename");
if (StringUtils.hasText(fullFileName)) { if (StringUtils.hasText(fullFileName)) {
fileName = fullFileName; fileName = fullFileName;
type = typeFromFileName(fullFileName); type = this.typeFromFileName(fullFileName);
suffix = suffixFromFileName(fullFileName); suffix = suffixFromFileName(fullFileName);
} else { } else {
fileName = getFileNameFromURL(url); fileName = getFileNameFromURL(url);

@ -6,7 +6,7 @@ import cn.keking.model.ReturnResponse;
import cn.keking.service.FilePreview; import cn.keking.service.FilePreview;
import cn.keking.utils.CadUtils; import cn.keking.utils.CadUtils;
import cn.keking.utils.DownloadUtils; import cn.keking.utils.DownloadUtils;
import cn.keking.utils.FileUtils; import cn.keking.service.FilePreviewCommonService;
import cn.keking.utils.PdfUtils; import cn.keking.utils.PdfUtils;
import cn.keking.web.filter.BaseUrlFilter; import cn.keking.web.filter.BaseUrlFilter;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -22,7 +22,7 @@ import static cn.keking.service.impl.OfficeFilePreviewImpl.getPreviewType;
@Service @Service
public class CadFilePreviewImpl implements FilePreview { public class CadFilePreviewImpl implements FilePreview {
private final FileUtils fileUtils; private final FilePreviewCommonService filePreviewCommonService;
private final DownloadUtils downloadUtils; private final DownloadUtils downloadUtils;
@ -30,11 +30,11 @@ public class CadFilePreviewImpl implements FilePreview {
private final PdfUtils pdfUtils; private final PdfUtils pdfUtils;
public CadFilePreviewImpl(FileUtils fileUtils, public CadFilePreviewImpl(FilePreviewCommonService filePreviewCommonService,
DownloadUtils downloadUtils, DownloadUtils downloadUtils,
CadUtils cadUtils, CadUtils cadUtils,
PdfUtils pdfUtils) { PdfUtils pdfUtils) {
this.fileUtils = fileUtils; this.filePreviewCommonService = filePreviewCommonService;
this.downloadUtils = downloadUtils; this.downloadUtils = downloadUtils;
this.cadUtils = cadUtils; this.cadUtils = cadUtils;
this.pdfUtils = pdfUtils; this.pdfUtils = pdfUtils;
@ -56,7 +56,7 @@ public class CadFilePreviewImpl implements FilePreview {
String pdfName = fileName.substring(0, fileName.lastIndexOf(".") + 1) + "pdf"; String pdfName = fileName.substring(0, fileName.lastIndexOf(".") + 1) + "pdf";
String outFilePath = FILE_DIR + pdfName; String outFilePath = FILE_DIR + pdfName;
// 判断之前是否已转换过,如果转换过,直接返回,否则执行转换 // 判断之前是否已转换过,如果转换过,直接返回,否则执行转换
if (!fileUtils.listConvertedFiles().containsKey(pdfName) || !ConfigConstants.isCacheEnabled()) { if (!filePreviewCommonService.listConvertedFiles().containsKey(pdfName) || !ConfigConstants.isCacheEnabled()) {
String filePath; String filePath;
ReturnResponse<String> response = downloadUtils.downLoad(fileAttribute, null); ReturnResponse<String> response = downloadUtils.downLoad(fileAttribute, null);
if (0 != response.getCode()) { if (0 != response.getCode()) {
@ -74,7 +74,7 @@ public class CadFilePreviewImpl implements FilePreview {
} }
if (ConfigConstants.isCacheEnabled()) { if (ConfigConstants.isCacheEnabled()) {
// 加入缓存 // 加入缓存
fileUtils.addConvertedFile(pdfName, fileUtils.getRelativePath(outFilePath)); filePreviewCommonService.addConvertedFile(pdfName, filePreviewCommonService.getRelativePath(outFilePath));
} }
} }
} }

@ -5,7 +5,7 @@ import cn.keking.model.FileAttribute;
import cn.keking.model.ReturnResponse; import cn.keking.model.ReturnResponse;
import cn.keking.service.FilePreview; import cn.keking.service.FilePreview;
import cn.keking.utils.DownloadUtils; import cn.keking.utils.DownloadUtils;
import cn.keking.utils.FileUtils; import cn.keking.service.FilePreviewCommonService;
import cn.keking.utils.ZipReader; import cn.keking.utils.ZipReader;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.ui.Model; import org.springframework.ui.Model;
@ -18,16 +18,16 @@ import org.springframework.util.StringUtils;
@Service @Service
public class CompressFilePreviewImpl implements FilePreview { public class CompressFilePreviewImpl implements FilePreview {
private final FileUtils fileUtils; private final FilePreviewCommonService filePreviewCommonService;
private final DownloadUtils downloadUtils; private final DownloadUtils downloadUtils;
private final ZipReader zipReader; private final ZipReader zipReader;
public CompressFilePreviewImpl(FileUtils fileUtils, public CompressFilePreviewImpl(FilePreviewCommonService filePreviewCommonService,
DownloadUtils downloadUtils, DownloadUtils downloadUtils,
ZipReader zipReader) { ZipReader zipReader) {
this.fileUtils = fileUtils; this.filePreviewCommonService = filePreviewCommonService;
this.downloadUtils = downloadUtils; this.downloadUtils = downloadUtils;
this.zipReader = zipReader; this.zipReader = zipReader;
} }
@ -38,7 +38,7 @@ public class CompressFilePreviewImpl implements FilePreview {
String suffix=fileAttribute.getSuffix(); String suffix=fileAttribute.getSuffix();
String fileTree = null; String fileTree = null;
// 判断文件名是否存在(redis缓存读取) // 判断文件名是否存在(redis缓存读取)
if (!StringUtils.hasText(fileUtils.getConvertedFile(fileName)) || !ConfigConstants.isCacheEnabled()) { if (!StringUtils.hasText(filePreviewCommonService.getConvertedFile(fileName)) || !ConfigConstants.isCacheEnabled()) {
ReturnResponse<String> response = downloadUtils.downLoad(fileAttribute, fileName); ReturnResponse<String> response = downloadUtils.downLoad(fileAttribute, fileName);
if (0 != response.getCode()) { if (0 != response.getCode()) {
model.addAttribute("fileType", suffix); model.addAttribute("fileType", suffix);
@ -54,10 +54,10 @@ public class CompressFilePreviewImpl implements FilePreview {
fileTree = zipReader.read7zFile(filePath, fileName); fileTree = zipReader.read7zFile(filePath, fileName);
} }
if (fileTree != null && !"null".equals(fileTree) && ConfigConstants.isCacheEnabled()) { if (fileTree != null && !"null".equals(fileTree) && ConfigConstants.isCacheEnabled()) {
fileUtils.addConvertedFile(fileName, fileTree); filePreviewCommonService.addConvertedFile(fileName, fileTree);
} }
} else { } else {
fileTree = fileUtils.getConvertedFile(fileName); fileTree = filePreviewCommonService.getConvertedFile(fileName);
} }
if (fileTree != null && !"null".equals(fileTree)) { if (fileTree != null && !"null".equals(fileTree)) {
model.addAttribute("fileTree", fileTree); model.addAttribute("fileTree", fileTree);

@ -4,7 +4,7 @@ import cn.keking.model.FileAttribute;
import cn.keking.model.ReturnResponse; import cn.keking.model.ReturnResponse;
import cn.keking.service.FilePreview; import cn.keking.service.FilePreview;
import cn.keking.utils.DownloadUtils; import cn.keking.utils.DownloadUtils;
import cn.keking.utils.FileUtils; import cn.keking.service.FilePreviewCommonService;
import cn.keking.web.filter.BaseUrlFilter; import cn.keking.web.filter.BaseUrlFilter;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.ui.Model; import org.springframework.ui.Model;
@ -19,12 +19,12 @@ public class MediaFilePreviewImpl implements FilePreview {
private final DownloadUtils downloadUtils; private final DownloadUtils downloadUtils;
private final FileUtils fileUtils; private final FilePreviewCommonService filePreviewCommonService;
public MediaFilePreviewImpl(DownloadUtils downloadUtils, public MediaFilePreviewImpl(DownloadUtils downloadUtils,
FileUtils fileUtils) { FilePreviewCommonService filePreviewCommonService) {
this.downloadUtils = downloadUtils; this.downloadUtils = downloadUtils;
this.fileUtils = fileUtils; this.filePreviewCommonService = filePreviewCommonService;
} }
@Override @Override
@ -37,7 +37,7 @@ public class MediaFilePreviewImpl implements FilePreview {
model.addAttribute("msg", response.getMsg()); model.addAttribute("msg", response.getMsg());
return "fileNotSupported"; return "fileNotSupported";
} else { } else {
model.addAttribute("mediaUrl", BaseUrlFilter.getBaseUrl() + fileUtils.getRelativePath(response.getContent())); model.addAttribute("mediaUrl", BaseUrlFilter.getBaseUrl() + filePreviewCommonService.getRelativePath(response.getContent()));
} }
} else { } else {
model.addAttribute("mediaUrl", url); model.addAttribute("mediaUrl", url);

@ -5,7 +5,7 @@ import cn.keking.model.FileAttribute;
import cn.keking.model.ReturnResponse; import cn.keking.model.ReturnResponse;
import cn.keking.service.FilePreview; import cn.keking.service.FilePreview;
import cn.keking.utils.DownloadUtils; import cn.keking.utils.DownloadUtils;
import cn.keking.utils.FileUtils; import cn.keking.service.FilePreviewCommonService;
import cn.keking.service.OfficeToPdfService; import cn.keking.service.OfficeToPdfService;
import cn.keking.utils.PdfUtils; import cn.keking.utils.PdfUtils;
import cn.keking.web.filter.BaseUrlFilter; import cn.keking.web.filter.BaseUrlFilter;
@ -22,13 +22,13 @@ import java.util.List;
@Service @Service
public class OfficeFilePreviewImpl implements FilePreview { public class OfficeFilePreviewImpl implements FilePreview {
private final FileUtils fileUtils; private final FilePreviewCommonService filePreviewCommonService;
private final PdfUtils pdfUtils; private final PdfUtils pdfUtils;
private final DownloadUtils downloadUtils; private final DownloadUtils downloadUtils;
private final OfficeToPdfService officeToPdfService; private final OfficeToPdfService officeToPdfService;
public OfficeFilePreviewImpl(FileUtils fileUtils, PdfUtils pdfUtils, DownloadUtils downloadUtils, OfficeToPdfService officeToPdfService) { public OfficeFilePreviewImpl(FilePreviewCommonService filePreviewCommonService, PdfUtils pdfUtils, DownloadUtils downloadUtils, OfficeToPdfService officeToPdfService) {
this.fileUtils = fileUtils; this.filePreviewCommonService = filePreviewCommonService;
this.pdfUtils = pdfUtils; this.pdfUtils = pdfUtils;
this.downloadUtils = downloadUtils; this.downloadUtils = downloadUtils;
this.officeToPdfService = officeToPdfService; this.officeToPdfService = officeToPdfService;
@ -49,7 +49,7 @@ public class OfficeFilePreviewImpl implements FilePreview {
String pdfName = fileName.substring(0, fileName.lastIndexOf(".") + 1) + (isHtml ? "html" : "pdf"); String pdfName = fileName.substring(0, fileName.lastIndexOf(".") + 1) + (isHtml ? "html" : "pdf");
String outFilePath = FILE_DIR + pdfName; String outFilePath = FILE_DIR + pdfName;
// 判断之前是否已转换过,如果转换过,直接返回,否则执行转换 // 判断之前是否已转换过,如果转换过,直接返回,否则执行转换
if (!fileUtils.listConvertedFiles().containsKey(pdfName) || !ConfigConstants.isCacheEnabled()) { if (!filePreviewCommonService.listConvertedFiles().containsKey(pdfName) || !ConfigConstants.isCacheEnabled()) {
String filePath; String filePath;
ReturnResponse<String> response = downloadUtils.downLoad(fileAttribute, null); ReturnResponse<String> response = downloadUtils.downLoad(fileAttribute, null);
if (0 != response.getCode()) { if (0 != response.getCode()) {
@ -62,11 +62,11 @@ public class OfficeFilePreviewImpl implements FilePreview {
officeToPdfService.openOfficeToPDF(filePath, outFilePath); officeToPdfService.openOfficeToPDF(filePath, outFilePath);
if (isHtml) { if (isHtml) {
// 对转换后的文件进行操作(改变编码方式) // 对转换后的文件进行操作(改变编码方式)
fileUtils.doActionConvertedFile(outFilePath); filePreviewCommonService.doActionConvertedFile(outFilePath);
} }
if (ConfigConstants.isCacheEnabled()) { if (ConfigConstants.isCacheEnabled()) {
// 加入缓存 // 加入缓存
fileUtils.addConvertedFile(pdfName, fileUtils.getRelativePath(outFilePath)); filePreviewCommonService.addConvertedFile(pdfName, filePreviewCommonService.getRelativePath(outFilePath));
} }
} }
} }

@ -5,7 +5,7 @@ import cn.keking.model.FileAttribute;
import cn.keking.model.ReturnResponse; import cn.keking.model.ReturnResponse;
import cn.keking.service.FilePreview; import cn.keking.service.FilePreview;
import cn.keking.utils.DownloadUtils; import cn.keking.utils.DownloadUtils;
import cn.keking.utils.FileUtils; import cn.keking.service.FilePreviewCommonService;
import cn.keking.utils.PdfUtils; import cn.keking.utils.PdfUtils;
import cn.keking.web.filter.BaseUrlFilter; import cn.keking.web.filter.BaseUrlFilter;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -20,7 +20,7 @@ import java.util.List;
@Service @Service
public class PdfFilePreviewImpl implements FilePreview { public class PdfFilePreviewImpl implements FilePreview {
private final FileUtils fileUtils; private final FilePreviewCommonService filePreviewCommonService;
private final PdfUtils pdfUtils; private final PdfUtils pdfUtils;
@ -28,10 +28,10 @@ public class PdfFilePreviewImpl implements FilePreview {
private static final String FILE_DIR = ConfigConstants.getFileDir(); private static final String FILE_DIR = ConfigConstants.getFileDir();
public PdfFilePreviewImpl(FileUtils fileUtils, public PdfFilePreviewImpl(FilePreviewCommonService filePreviewCommonService,
PdfUtils pdfUtils, PdfUtils pdfUtils,
DownloadUtils downloadUtils) { DownloadUtils downloadUtils) {
this.fileUtils = fileUtils; this.filePreviewCommonService = filePreviewCommonService;
this.pdfUtils = pdfUtils; this.pdfUtils = pdfUtils;
this.downloadUtils = downloadUtils; this.downloadUtils = downloadUtils;
} }
@ -46,7 +46,7 @@ public class PdfFilePreviewImpl implements FilePreview {
String outFilePath = FILE_DIR + pdfName; String outFilePath = FILE_DIR + pdfName;
if (OfficeFilePreviewImpl.OFFICE_PREVIEW_TYPE_IMAGE.equals(officePreviewType) || OfficeFilePreviewImpl.OFFICE_PREVIEW_TYPE_ALL_IMAGES.equals(officePreviewType)) { if (OfficeFilePreviewImpl.OFFICE_PREVIEW_TYPE_IMAGE.equals(officePreviewType) || OfficeFilePreviewImpl.OFFICE_PREVIEW_TYPE_ALL_IMAGES.equals(officePreviewType)) {
//当文件不存在时,就去下载 //当文件不存在时,就去下载
if (!fileUtils.listConvertedFiles().containsKey(pdfName) || !ConfigConstants.isCacheEnabled()) { if (!filePreviewCommonService.listConvertedFiles().containsKey(pdfName) || !ConfigConstants.isCacheEnabled()) {
ReturnResponse<String> response = downloadUtils.downLoad(fileAttribute, fileName); ReturnResponse<String> response = downloadUtils.downLoad(fileAttribute, fileName);
if (0 != response.getCode()) { if (0 != response.getCode()) {
model.addAttribute("fileType", suffix); model.addAttribute("fileType", suffix);
@ -56,7 +56,7 @@ public class PdfFilePreviewImpl implements FilePreview {
outFilePath = response.getContent(); outFilePath = response.getContent();
if (ConfigConstants.isCacheEnabled()) { if (ConfigConstants.isCacheEnabled()) {
// 加入缓存 // 加入缓存
fileUtils.addConvertedFile(pdfName, fileUtils.getRelativePath(outFilePath)); filePreviewCommonService.addConvertedFile(pdfName, filePreviewCommonService.getRelativePath(outFilePath));
} }
} }
List<String> imageUrls = pdfUtils.pdf2jpg(outFilePath, pdfName, baseUrl); List<String> imageUrls = pdfUtils.pdf2jpg(outFilePath, pdfName, baseUrl);
@ -75,17 +75,17 @@ public class PdfFilePreviewImpl implements FilePreview {
} else { } else {
// 不是http开头浏览器不能直接访问需下载到本地 // 不是http开头浏览器不能直接访问需下载到本地
if (url != null && !url.toLowerCase().startsWith("http")) { if (url != null && !url.toLowerCase().startsWith("http")) {
if (!fileUtils.listConvertedFiles().containsKey(pdfName) || !ConfigConstants.isCacheEnabled()) { if (!filePreviewCommonService.listConvertedFiles().containsKey(pdfName) || !ConfigConstants.isCacheEnabled()) {
ReturnResponse<String> response = downloadUtils.downLoad(fileAttribute, pdfName); ReturnResponse<String> response = downloadUtils.downLoad(fileAttribute, pdfName);
if (0 != response.getCode()) { if (0 != response.getCode()) {
model.addAttribute("fileType", suffix); model.addAttribute("fileType", suffix);
model.addAttribute("msg", response.getMsg()); model.addAttribute("msg", response.getMsg());
return "fileNotSupported"; return "fileNotSupported";
} }
model.addAttribute("pdfUrl", fileUtils.getRelativePath(response.getContent())); model.addAttribute("pdfUrl", filePreviewCommonService.getRelativePath(response.getContent()));
if (ConfigConstants.isCacheEnabled()) { if (ConfigConstants.isCacheEnabled()) {
// 加入缓存 // 加入缓存
fileUtils.addConvertedFile(pdfName, fileUtils.getRelativePath(outFilePath)); filePreviewCommonService.addConvertedFile(pdfName, filePreviewCommonService.getRelativePath(outFilePath));
} }
} else { } else {
model.addAttribute("pdfUrl", pdfName); model.addAttribute("pdfUrl", pdfName);

@ -4,7 +4,7 @@ import cn.keking.model.FileAttribute;
import cn.keking.model.ReturnResponse; import cn.keking.model.ReturnResponse;
import cn.keking.service.FilePreview; import cn.keking.service.FilePreview;
import cn.keking.utils.DownloadUtils; import cn.keking.utils.DownloadUtils;
import cn.keking.utils.FileUtils; import cn.keking.service.FilePreviewCommonService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
@ -18,13 +18,13 @@ import java.util.List;
@Service @Service
public class PictureFilePreviewImpl implements FilePreview { public class PictureFilePreviewImpl implements FilePreview {
private final FileUtils fileUtils; private final FilePreviewCommonService filePreviewCommonService;
private final DownloadUtils downloadUtils; private final DownloadUtils downloadUtils;
public PictureFilePreviewImpl(FileUtils fileUtils, public PictureFilePreviewImpl(FilePreviewCommonService filePreviewCommonService,
DownloadUtils downloadUtils) { DownloadUtils downloadUtils) {
this.fileUtils = fileUtils; this.filePreviewCommonService = filePreviewCommonService;
this.downloadUtils = downloadUtils; this.downloadUtils = downloadUtils;
} }
@ -33,7 +33,7 @@ public class PictureFilePreviewImpl implements FilePreview {
List<String> imgUrls = new ArrayList<>(); List<String> imgUrls = new ArrayList<>();
imgUrls.add(url); imgUrls.add(url);
String fileKey = fileAttribute.getFileKey(); String fileKey = fileAttribute.getFileKey();
List<String> zipImgUrls = fileUtils.getImgCache(fileKey); List<String> zipImgUrls = filePreviewCommonService.getImgCache(fileKey);
if (!CollectionUtils.isEmpty(zipImgUrls)) { if (!CollectionUtils.isEmpty(zipImgUrls)) {
imgUrls.addAll(zipImgUrls); imgUrls.addAll(zipImgUrls);
} }
@ -45,7 +45,7 @@ public class PictureFilePreviewImpl implements FilePreview {
model.addAttribute("msg", response.getMsg()); model.addAttribute("msg", response.getMsg());
return "fileNotSupported"; return "fileNotSupported";
} else { } else {
String file = fileUtils.getRelativePath(response.getContent()); String file = filePreviewCommonService.getRelativePath(response.getContent());
imgUrls.clear(); imgUrls.clear();
imgUrls.add(file); imgUrls.add(file);
model.addAttribute("imgurls", imgUrls); model.addAttribute("imgurls", imgUrls);

@ -5,6 +5,7 @@ import cn.keking.hutool.URLUtil;
import cn.keking.model.FileAttribute; import cn.keking.model.FileAttribute;
import cn.keking.model.FileType; import cn.keking.model.FileType;
import cn.keking.model.ReturnResponse; import cn.keking.model.ReturnResponse;
import cn.keking.service.FilePreviewCommonService;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -24,10 +25,10 @@ public class DownloadUtils {
private final String fileDir = ConfigConstants.getFileDir(); private final String fileDir = ConfigConstants.getFileDir();
private final FileUtils fileUtils; private final FilePreviewCommonService filePreviewCommonService;
public DownloadUtils(FileUtils fileUtils) { public DownloadUtils(FilePreviewCommonService filePreviewCommonService) {
this.fileUtils = fileUtils; this.filePreviewCommonService = filePreviewCommonService;
} }
private static final String URL_PARAM_FTP_USERNAME = "ftp.username"; private static final String URL_PARAM_FTP_USERNAME = "ftp.username";
@ -61,9 +62,9 @@ public class DownloadUtils {
OutputStream os = new FileOutputStream(realPath); OutputStream os = new FileOutputStream(realPath);
saveBytesToOutStream(bytes, os); saveBytesToOutStream(bytes, os);
} else if (url.getProtocol() != null && "ftp".equalsIgnoreCase(url.getProtocol())) { } else if (url.getProtocol() != null && "ftp".equalsIgnoreCase(url.getProtocol())) {
String ftpUsername = fileUtils.getUrlParameterReg(fileAttribute.getUrl(), URL_PARAM_FTP_USERNAME); String ftpUsername = filePreviewCommonService.getUrlParameterReg(fileAttribute.getUrl(), URL_PARAM_FTP_USERNAME);
String ftpPassword = fileUtils.getUrlParameterReg(fileAttribute.getUrl(), URL_PARAM_FTP_PASSWORD); String ftpPassword = filePreviewCommonService.getUrlParameterReg(fileAttribute.getUrl(), URL_PARAM_FTP_PASSWORD);
String ftpControlEncoding = fileUtils.getUrlParameterReg(fileAttribute.getUrl(), URL_PARAM_FTP_CONTROL_ENCODING); String ftpControlEncoding = filePreviewCommonService.getUrlParameterReg(fileAttribute.getUrl(), URL_PARAM_FTP_CONTROL_ENCODING);
FtpUtils.download(fileAttribute.getUrl(), realPath, ftpUsername, ftpPassword, ftpControlEncoding); FtpUtils.download(fileAttribute.getUrl(), realPath, ftpUsername, ftpPassword, ftpControlEncoding);
} else { } else {
response.setCode(1); response.setCode(1);

@ -1,5 +1,6 @@
package cn.keking.utils; package cn.keking.utils;
import cn.keking.service.FilePreviewCommonService;
import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.rendering.ImageType; import org.apache.pdfbox.rendering.ImageType;
import org.apache.pdfbox.rendering.PDFRenderer; import org.apache.pdfbox.rendering.PDFRenderer;
@ -22,18 +23,18 @@ public class PdfUtils {
private final Logger logger = LoggerFactory.getLogger(PdfUtils.class); private final Logger logger = LoggerFactory.getLogger(PdfUtils.class);
private final FileUtils fileUtils; private final FilePreviewCommonService filePreviewCommonService;
@Value("${server.tomcat.uri-encoding:UTF-8}") @Value("${server.tomcat.uri-encoding:UTF-8}")
private String uriEncoding; private String uriEncoding;
public PdfUtils(FileUtils fileUtils) { public PdfUtils(FilePreviewCommonService filePreviewCommonService) {
this.fileUtils = fileUtils; this.filePreviewCommonService = filePreviewCommonService;
} }
public List<String> pdf2jpg(String pdfFilePath, String pdfName, String baseUrl) { public List<String> pdf2jpg(String pdfFilePath, String pdfName, String baseUrl) {
List<String> imageUrls = new ArrayList<>(); List<String> imageUrls = new ArrayList<>();
Integer imageCount = fileUtils.getConvertedPdfImage(pdfFilePath); Integer imageCount = filePreviewCommonService.getConvertedPdfImage(pdfFilePath);
String imageFileSuffix = ".jpg"; String imageFileSuffix = ".jpg";
String pdfFolder = pdfName.substring(0, pdfName.length() - 4); String pdfFolder = pdfName.substring(0, pdfName.length() - 4);
String urlPrefix = null; String urlPrefix = null;
@ -69,7 +70,7 @@ public class PdfUtils {
imageUrls.add(urlPrefix + "/" + pageIndex + imageFileSuffix); imageUrls.add(urlPrefix + "/" + pageIndex + imageFileSuffix);
} }
doc.close(); doc.close();
fileUtils.addConvertedPdfImage(pdfFilePath, pageCount); filePreviewCommonService.addConvertedPdfImage(pdfFilePath, pageCount);
} catch (IOException e) { } catch (IOException e) {
logger.error("Convert pdf to jpg exception, pdfFilePath{}", pdfFilePath, e); logger.error("Convert pdf to jpg exception, pdfFilePath{}", pdfFilePath, e);
} }

@ -2,6 +2,7 @@ package cn.keking.utils;
import cn.keking.config.ConfigConstants; import cn.keking.config.ConfigConstants;
import cn.keking.model.FileType; import cn.keking.model.FileType;
import cn.keking.service.FilePreviewCommonService;
import cn.keking.web.filter.BaseUrlFilter; import cn.keking.web.filter.BaseUrlFilter;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
@ -33,14 +34,14 @@ import java.util.regex.Pattern;
public class ZipReader { public class ZipReader {
static Pattern pattern = Pattern.compile("^\\d+"); static Pattern pattern = Pattern.compile("^\\d+");
private final FileUtils fileUtils; private final FilePreviewCommonService filePreviewCommonService;
private final String fileDir = ConfigConstants.getFileDir(); private final String fileDir = ConfigConstants.getFileDir();
private final ExecutorService executors = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); private final ExecutorService executors = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
public ZipReader(FileUtils fileUtils) { public ZipReader(FilePreviewCommonService filePreviewCommonService) {
this.fileUtils = fileUtils; this.filePreviewCommonService = filePreviewCommonService;
} }
public String readZipFile(String filePath,String fileKey) { public String readZipFile(String filePath,String fileKey) {
@ -48,9 +49,9 @@ public class ZipReader {
Map<String, FileNode> appender = new HashMap<>(); Map<String, FileNode> appender = new HashMap<>();
List<String> imgUrls = new LinkedList<>(); List<String> imgUrls = new LinkedList<>();
String baseUrl = BaseUrlFilter.getBaseUrl(); String baseUrl = BaseUrlFilter.getBaseUrl();
String archiveFileName = fileUtils.getFileNameFromPath(filePath); String archiveFileName = filePreviewCommonService.getFileNameFromPath(filePath);
try { try {
ZipFile zipFile = new ZipFile(filePath, fileUtils.getFileEncodeUTFGBK(filePath)); ZipFile zipFile = new ZipFile(filePath, filePreviewCommonService.getFileEncodeUTFGBK(filePath));
Enumeration<ZipArchiveEntry> entries = zipFile.getEntries(); Enumeration<ZipArchiveEntry> entries = zipFile.getEntries();
// 排序 // 排序
entries = sortZipEntries(entries); entries = sortZipEntries(entries);
@ -69,7 +70,7 @@ public class ZipReader {
} }
String parentName = getLast2FileName(fullName, archiveSeparator, archiveFileName); String parentName = getLast2FileName(fullName, archiveSeparator, archiveFileName);
parentName = (level-1) + "_" + parentName; parentName = (level-1) + "_" + parentName;
FileType type=fileUtils.typeFromUrl(childName); FileType type= filePreviewCommonService.typeFromUrl(childName);
if (type.equals(FileType.picture)){//添加图片文件到图片列表 if (type.equals(FileType.picture)){//添加图片文件到图片列表
imgUrls.add(baseUrl+childName); imgUrls.add(baseUrl+childName);
} }
@ -79,7 +80,7 @@ public class ZipReader {
} }
// 开启新的线程处理文件解压 // 开启新的线程处理文件解压
executors.submit(new ZipExtractorWorker(entriesToBeExtracted, zipFile, filePath)); executors.submit(new ZipExtractorWorker(entriesToBeExtracted, zipFile, filePath));
fileUtils.putImgCache(fileKey,imgUrls); filePreviewCommonService.putImgCache(fileKey,imgUrls);
return new ObjectMapper().writeValueAsString(appender.get("")); return new ObjectMapper().writeValueAsString(appender.get(""));
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
@ -104,7 +105,7 @@ public class ZipReader {
Archive archive = new Archive(new FileInputStream(new File(filePath))); Archive archive = new Archive(new FileInputStream(new File(filePath)));
List<FileHeader> headers = archive.getFileHeaders(); List<FileHeader> headers = archive.getFileHeaders();
headers = sortedHeaders(headers); headers = sortedHeaders(headers);
String archiveFileName = fileUtils.getFileNameFromPath(filePath); String archiveFileName = filePreviewCommonService.getFileNameFromPath(filePath);
List<Map<String, FileHeader>> headersToBeExtracted =new ArrayList<>(); List<Map<String, FileHeader>> headersToBeExtracted =new ArrayList<>();
for (FileHeader header : headers) { for (FileHeader header : headers) {
String fullName; String fullName;
@ -122,7 +123,7 @@ public class ZipReader {
headersToBeExtracted.add(Collections.singletonMap(childName, header)); headersToBeExtracted.add(Collections.singletonMap(childName, header));
} }
String parentName = getLast2FileName(fullName, "\\", archiveFileName); String parentName = getLast2FileName(fullName, "\\", archiveFileName);
FileType type = fileUtils.typeFromUrl(childName); FileType type = filePreviewCommonService.typeFromUrl(childName);
if (type.equals(FileType.picture)){//添加图片文件到图片列表 if (type.equals(FileType.picture)){//添加图片文件到图片列表
imgUrls.add(baseUrl+childName); imgUrls.add(baseUrl+childName);
} }
@ -131,7 +132,7 @@ public class ZipReader {
appender.put(childName, node); appender.put(childName, node);
} }
executors.submit(new RarExtractorWorker(headersToBeExtracted, archive, filePath)); executors.submit(new RarExtractorWorker(headersToBeExtracted, archive, filePath));
fileUtils.putImgCache(fileKey,imgUrls); filePreviewCommonService.putImgCache(fileKey,imgUrls);
return new ObjectMapper().writeValueAsString(appender.get("")); return new ObjectMapper().writeValueAsString(appender.get(""));
} catch (RarException | IOException e) { } catch (RarException | IOException e) {
e.printStackTrace(); e.printStackTrace();
@ -144,7 +145,7 @@ public class ZipReader {
Map<String, FileNode> appender = new HashMap<>(); Map<String, FileNode> appender = new HashMap<>();
List<String> imgUrls = new ArrayList<>(); List<String> imgUrls = new ArrayList<>();
String baseUrl= BaseUrlFilter.getBaseUrl(); String baseUrl= BaseUrlFilter.getBaseUrl();
String archiveFileName = fileUtils.getFileNameFromPath(filePath); String archiveFileName = filePreviewCommonService.getFileNameFromPath(filePath);
try { try {
SevenZFile zipFile = new SevenZFile(new File(filePath)); SevenZFile zipFile = new SevenZFile(new File(filePath));
Iterable<SevenZArchiveEntry> entries = zipFile.getEntries(); Iterable<SevenZArchiveEntry> entries = zipFile.getEntries();
@ -165,7 +166,7 @@ public class ZipReader {
} }
String parentName = getLast2FileName(fullName, archiveSeparator, archiveFileName); String parentName = getLast2FileName(fullName, archiveSeparator, archiveFileName);
parentName = (level-1) + "_" + parentName; parentName = (level-1) + "_" + parentName;
FileType type=fileUtils.typeFromUrl(childName); FileType type= filePreviewCommonService.typeFromUrl(childName);
if (type.equals(FileType.picture)){//添加图片文件到图片列表 if (type.equals(FileType.picture)){//添加图片文件到图片列表
imgUrls.add(baseUrl+childName); imgUrls.add(baseUrl+childName);
} }
@ -175,7 +176,7 @@ public class ZipReader {
} }
// 开启新的线程处理文件解压 // 开启新的线程处理文件解压
executors.submit(new SevenZExtractorWorker(entriesToBeExtracted, filePath)); executors.submit(new SevenZExtractorWorker(entriesToBeExtracted, filePath));
fileUtils.putImgCache(fileKey,imgUrls); filePreviewCommonService.putImgCache(fileKey,imgUrls);
return new ObjectMapper().writeValueAsString(appender.get("")); return new ObjectMapper().writeValueAsString(appender.get(""));
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();

@ -6,7 +6,7 @@ import cn.keking.service.FilePreviewFactory;
import cn.keking.service.cache.CacheService; import cn.keking.service.cache.CacheService;
import cn.keking.utils.DownloadUtils; import cn.keking.utils.DownloadUtils;
import cn.keking.utils.FileUtils; import cn.keking.service.FilePreviewCommonService;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
@ -32,15 +32,12 @@ public class OnlinePreviewController {
private final FilePreviewFactory previewFactory; private final FilePreviewFactory previewFactory;
private final CacheService cacheService; private final CacheService cacheService;
private final FileUtils fileUtils; private final FilePreviewCommonService filePreviewCommonService;
private final DownloadUtils downloadUtils; private final DownloadUtils downloadUtils;
public OnlinePreviewController(FilePreviewFactory filePreviewFactory, public OnlinePreviewController(FilePreviewFactory filePreviewFactory, FilePreviewCommonService filePreviewCommonService, CacheService cacheService, DownloadUtils downloadUtils) {
FileUtils fileUtils,
CacheService cacheService,
DownloadUtils downloadUtils) {
this.previewFactory = filePreviewFactory; this.previewFactory = filePreviewFactory;
this.fileUtils = fileUtils; this.filePreviewCommonService = filePreviewCommonService;
this.cacheService = cacheService; this.cacheService = cacheService;
this.downloadUtils = downloadUtils; this.downloadUtils = downloadUtils;
} }
@ -48,13 +45,13 @@ public class OnlinePreviewController {
@RequestMapping(value = "/onlinePreview") @RequestMapping(value = "/onlinePreview")
public String onlinePreview(String url, Model model, HttpServletRequest req) { public String onlinePreview(String url, Model model, HttpServletRequest req) {
FileAttribute fileAttribute = fileUtils.getFileAttribute(url,req); FileAttribute fileAttribute = filePreviewCommonService.getFileAttribute(url,req);
FilePreview filePreview = previewFactory.get(fileAttribute); FilePreview filePreview = previewFactory.get(fileAttribute);
logger.info("预览文件url{}previewType{}", url, fileAttribute.getType()); logger.info("预览文件url{}previewType{}", url, fileAttribute.getType());
return filePreview.filePreviewHandle(url, model, fileAttribute); return filePreview.filePreviewHandle(url, model, fileAttribute);
} }
@RequestMapping(value = "picturesPreview") @RequestMapping(value = "/picturesPreview")
public String picturesPreview(Model model, HttpServletRequest req) throws UnsupportedEncodingException { public String picturesPreview(Model model, HttpServletRequest req) throws UnsupportedEncodingException {
String urls = req.getParameter("urls"); String urls = req.getParameter("urls");
String currentUrl = req.getParameter("currentUrl"); String currentUrl = req.getParameter("currentUrl");
@ -64,8 +61,8 @@ public class OnlinePreviewController {
String decodedCurrentUrl = URLDecoder.decode(currentUrl, "utf-8"); String decodedCurrentUrl = URLDecoder.decode(currentUrl, "utf-8");
// 抽取文件并返回文件列表 // 抽取文件并返回文件列表
String[] imgs = decodedUrl.split("\\|"); String[] imgs = decodedUrl.split("\\|");
List imgurls = Arrays.asList(imgs); List<String> imgUrls = Arrays.asList(imgs);
model.addAttribute("imgurls", imgurls); model.addAttribute("imgUrls", imgUrls);
model.addAttribute("currentUrl",decodedCurrentUrl); model.addAttribute("currentUrl",decodedCurrentUrl);
return "picture"; return "picture";
} }

@ -23,7 +23,7 @@
</head> </head>
<body> <body>
<ul id="dowebok"> <ul id="dowebok">
<#list imgurls as img> <#list imgUrls as img>
<#if img?contains("http://") || img?contains("https://")> <#if img?contains("http://") || img?contains("https://")>
<#assign img="${img}"> <#assign img="${img}">
<#else> <#else>

@ -6,8 +6,8 @@
<title></title> <title></title>
</head> </head>
<body> <body>
<input hidden id="textType" value="${textType}"> <input hidden id="textType" value="${textType}"/>
<input hidden id="textData" value="${textData}"> <input hidden id="textData" value="${textData}"/>
<div class="container"> <div class="container">
<#if textType?? && textType == "markdown"> <#if textType?? && textType == "markdown">

Loading…
Cancel
Save