2018-01-17 17:51:53 +08:00
|
|
|
|
package cn.keking.service.impl;
|
|
|
|
|
|
2019-06-17 14:21:16 +08:00
|
|
|
|
import cn.keking.model.FileAttribute;
|
2022-12-16 23:58:26 +08:00
|
|
|
|
import cn.keking.service.FileHandlerService;
|
|
|
|
|
import cn.keking.utils.KkFileUtils;
|
2018-01-17 17:51:53 +08:00
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.ui.Model;
|
2020-12-26 01:52:52 +08:00
|
|
|
|
import org.springframework.util.CollectionUtils;
|
2022-12-16 23:58:26 +08:00
|
|
|
|
|
2020-12-26 01:52:52 +08:00
|
|
|
|
import java.util.ArrayList;
|
2018-01-17 17:51:53 +08:00
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Created by kl on 2018/1/17.
|
|
|
|
|
* Content :图片文件处理
|
|
|
|
|
*/
|
|
|
|
|
@Service
|
2023-03-09 21:00:03 +08:00
|
|
|
|
public class PictureFilePreviewImpl extends CommonPreviewImpl {
|
2018-01-17 17:51:53 +08:00
|
|
|
|
|
2020-12-26 19:13:50 +08:00
|
|
|
|
private final FileHandlerService fileHandlerService;
|
2018-01-17 17:51:53 +08:00
|
|
|
|
|
2020-12-27 14:47:28 +08:00
|
|
|
|
public PictureFilePreviewImpl(FileHandlerService fileHandlerService, OtherFilePreviewImpl otherFilePreview) {
|
2023-03-09 21:00:03 +08:00
|
|
|
|
super(fileHandlerService, otherFilePreview);
|
2020-12-26 19:13:50 +08:00
|
|
|
|
this.fileHandlerService = fileHandlerService;
|
2020-05-18 09:46:52 +08:00
|
|
|
|
}
|
2020-05-14 16:22:48 +08:00
|
|
|
|
|
2018-01-17 17:51:53 +08:00
|
|
|
|
@Override
|
2019-06-17 14:21:16 +08:00
|
|
|
|
public String filePreviewHandle(String url, Model model, FileAttribute fileAttribute) {
|
2022-12-16 23:58:26 +08:00
|
|
|
|
url= KkFileUtils.htmlEscape(url);
|
2020-12-26 01:52:52 +08:00
|
|
|
|
List<String> imgUrls = new ArrayList<>();
|
|
|
|
|
imgUrls.add(url);
|
2023-12-21 11:19:29 +08:00
|
|
|
|
String compressFileKey = fileAttribute.getCompressFileKey();
|
|
|
|
|
List<String> zipImgUrls = fileHandlerService.getImgCache(compressFileKey);
|
2020-12-26 01:52:52 +08:00
|
|
|
|
if (!CollectionUtils.isEmpty(zipImgUrls)) {
|
|
|
|
|
imgUrls.addAll(zipImgUrls);
|
2018-01-17 17:51:53 +08:00
|
|
|
|
}
|
2020-05-14 16:22:48 +08:00
|
|
|
|
// 不是http开头,浏览器不能直接访问,需下载到本地
|
2023-03-09 21:00:03 +08:00
|
|
|
|
super.filePreviewHandle(url, model, fileAttribute);
|
|
|
|
|
model.addAttribute("imgUrls", imgUrls);
|
2020-12-27 15:14:32 +08:00
|
|
|
|
return PICTURE_FILE_PREVIEW_PAGE;
|
2018-01-17 17:51:53 +08:00
|
|
|
|
}
|
|
|
|
|
}
|