优化:图片模式下图片url使用baseUrl
parent
b1fdbd26a3
commit
7ea70bf422
|
@ -52,7 +52,7 @@ public class ConfigRefreshComponent {
|
|||
String ftpPassword;
|
||||
String ftpControlEncoding;
|
||||
String configFilePath = OfficeUtils.getCustomizedConfigPath();
|
||||
String baseUlr;
|
||||
String baseUrl;
|
||||
while (true) {
|
||||
FileReader fileReader = new FileReader(configFilePath);
|
||||
BufferedReader bufferedReader = new BufferedReader(fileReader);
|
||||
|
@ -67,7 +67,7 @@ public class ConfigRefreshComponent {
|
|||
ftpControlEncoding = properties.getProperty("ftp.control.encoding", DEFAULT_FTP_CONTROL_ENCODING);
|
||||
textArray = text.split(",");
|
||||
mediaArray = media.split(",");
|
||||
baseUlr = properties.getProperty("base.url", DEFAULT_BASE_URL);
|
||||
baseUrl = properties.getProperty("base.url", DEFAULT_BASE_URL);
|
||||
ConfigConstants.setCacheEnabled(cacheEnabled);
|
||||
ConfigConstants.setSimText(textArray);
|
||||
ConfigConstants.setMedia(mediaArray);
|
||||
|
@ -75,7 +75,7 @@ public class ConfigRefreshComponent {
|
|||
ConfigConstants.setFtpUsername(ftpUsername);
|
||||
ConfigConstants.setFtpPassword(ftpPassword);
|
||||
ConfigConstants.setFtpControlEncoding(ftpControlEncoding);
|
||||
ConfigConstants.setBaseUrl(baseUlr);
|
||||
ConfigConstants.setBaseUrl(baseUrl);
|
||||
bufferedReader.close();
|
||||
fileReader.close();
|
||||
Thread.sleep(1000L);
|
||||
|
|
|
@ -12,8 +12,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -45,7 +45,7 @@ public class OfficeFilePreviewImpl implements FilePreview {
|
|||
public String filePreviewHandle(String url, Model model, FileAttribute fileAttribute) {
|
||||
// 预览Type,参数传了就取参数的,没传取系统默认
|
||||
String officePreviewType = model.asMap().get("officePreviewType") == null ? ConfigConstants.getOfficePreviewType() : model.asMap().get("officePreviewType").toString();
|
||||
String originUrl = (String) model.asMap().get("originUrl");
|
||||
String baseUrl = (String) RequestContextHolder.currentRequestAttributes().getAttribute("baseUrl",0);
|
||||
String suffix=fileAttribute.getSuffix();
|
||||
String fileName=fileAttribute.getName();
|
||||
boolean isHtml = suffix.equalsIgnoreCase("xls") || suffix.equalsIgnoreCase("xlsx");
|
||||
|
@ -73,8 +73,8 @@ public class OfficeFilePreviewImpl implements FilePreview {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (!isHtml && originUrl != null && (OFFICE_PREVIEW_TYPE_IMAGE.equals(officePreviewType) || OFFICE_PREVIEW_TYPE_ALLIMAGES.equals(officePreviewType))) {
|
||||
List<String> imageUrls = pdfUtils.pdf2jpg(outFilePath, pdfName, originUrl);
|
||||
if (!isHtml && baseUrl != null && (OFFICE_PREVIEW_TYPE_IMAGE.equals(officePreviewType) || OFFICE_PREVIEW_TYPE_ALLIMAGES.equals(officePreviewType))) {
|
||||
List<String> imageUrls = pdfUtils.pdf2jpg(outFilePath, pdfName, baseUrl);
|
||||
if (imageUrls == null || imageUrls.size() < 1) {
|
||||
model.addAttribute("msg", "office转图片异常,请联系管理员");
|
||||
model.addAttribute("fileType",fileAttribute.getSuffix());
|
||||
|
|
|
@ -10,8 +10,8 @@ import cn.keking.utils.PdfUtils;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -38,7 +38,7 @@ public class PdfFilePreviewImpl implements FilePreview{
|
|||
String suffix=fileAttribute.getSuffix();
|
||||
String fileName=fileAttribute.getName();
|
||||
String officePreviewType = model.asMap().get("officePreviewType") == null ? ConfigConstants.getOfficePreviewType() : model.asMap().get("officePreviewType").toString();
|
||||
String originUrl = model.asMap().get("originUrl").toString();
|
||||
String baseUrl = (String) RequestContextHolder.currentRequestAttributes().getAttribute("baseUrl",0);
|
||||
model.addAttribute("pdfUrl", url);
|
||||
String pdfName = fileName.substring(0, fileName.lastIndexOf(".") + 1) + "pdf";
|
||||
String outFilePath = fileDir + pdfName;
|
||||
|
@ -51,7 +51,7 @@ public class PdfFilePreviewImpl implements FilePreview{
|
|||
return "fileNotSupported";
|
||||
}
|
||||
outFilePath = response.getContent();
|
||||
List<String> imageUrls = pdfUtils.pdf2jpg(outFilePath, pdfName, originUrl);
|
||||
List<String> imageUrls = pdfUtils.pdf2jpg(outFilePath, pdfName, baseUrl);
|
||||
if (imageUrls == null || imageUrls.size() < 1) {
|
||||
model.addAttribute("msg", "pdf转图片异常,请联系管理员");
|
||||
model.addAttribute("fileType",fileAttribute.getSuffix());
|
||||
|
|
|
@ -23,14 +23,12 @@ public class PdfUtils {
|
|||
@Autowired
|
||||
FileUtils fileUtils;
|
||||
|
||||
public List<String> pdf2jpg(String pdfFilePath, String pdfName, String url) {
|
||||
public List<String> pdf2jpg(String pdfFilePath, String pdfName, String baseUrl) {
|
||||
List<String> imageUrls = new ArrayList<>();
|
||||
Integer imageCount = fileUtils.getConvertedPdfImage(pdfFilePath);
|
||||
String imageFileSuffix = ".jpg";
|
||||
// https://8个字符 http://7个字符 从这后面开始出现的第一个/就是当前file.Dir下的根目录
|
||||
int index1 = url.indexOf("/", 8);
|
||||
String pdfFolder = pdfName.substring(0, pdfName.length() - 4);
|
||||
String urlPrefix = url.substring(0, index1 + 1) + pdfFolder;
|
||||
String urlPrefix = baseUrl + pdfFolder;
|
||||
if (imageCount != null && imageCount.intValue() > 0) {
|
||||
for (int i = 0; i < imageCount ; i++)
|
||||
imageUrls.add(urlPrefix + "/" + i + imageFileSuffix);
|
||||
|
|
|
@ -49,38 +49,17 @@ public class OnlinePreviewController {
|
|||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "onlinePreview", method = RequestMethod.GET)
|
||||
@RequestMapping(value = "/onlinePreview", method = RequestMethod.GET)
|
||||
public String onlinePreview(String url, Model model, HttpServletRequest req) {
|
||||
FileAttribute fileAttribute = fileUtils.getFileAttribute(url);
|
||||
req.setAttribute("fileKey", req.getParameter("fileKey"));
|
||||
model.addAttribute("officePreviewType", req.getParameter("officePreviewType"));
|
||||
model.addAttribute("originUrl", req.getRequestURL().toString());
|
||||
FilePreview filePreview = previewFactory.get(fileAttribute);
|
||||
return filePreview.filePreviewHandle(url, model, fileAttribute);
|
||||
}
|
||||
|
||||
/**
|
||||
* 多图片切换预览
|
||||
*
|
||||
* @param model
|
||||
* @param req
|
||||
* @return
|
||||
* @throws UnsupportedEncodingException
|
||||
*/
|
||||
@RequestMapping(value = "picturesPreview", method = RequestMethod.GET)
|
||||
public String picturesPreview(String urls, String currentUrl, Model model, HttpServletRequest req) throws UnsupportedEncodingException {
|
||||
// 路径转码
|
||||
String decodedUrl = URLDecoder.decode(urls, "utf-8");
|
||||
String decodedCurrentUrl = URLDecoder.decode(currentUrl, "utf-8");
|
||||
// 抽取文件并返回文件列表
|
||||
String[] imgs = decodedUrl.split("\\|");
|
||||
List imgurls = Arrays.asList(imgs);
|
||||
model.addAttribute("imgurls", imgurls);
|
||||
model.addAttribute("currentUrl",decodedCurrentUrl);
|
||||
return "picture";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "picturesPreview", method = RequestMethod.POST)
|
||||
@RequestMapping(value = "/picturesPreview")
|
||||
public String picturesPreview(Model model, HttpServletRequest req) throws UnsupportedEncodingException {
|
||||
String urls = req.getParameter("urls");
|
||||
String currentUrl = req.getParameter("currentUrl");
|
||||
|
|
Loading…
Reference in New Issue