【portal】更新svg的预览

dev-7.6.0-portal
fengshuonan 2023-07-10 13:19:37 +08:00
parent 99700a7948
commit efe81c0824
3 changed files with 85 additions and 5 deletions

View File

@ -47,7 +47,6 @@ public class PicFileTypeUtil {
PIC_TYPES.add("tif");
PIC_TYPES.add("gif");
PIC_TYPES.add("bmp");
PIC_TYPES.add("svg");
}
/**

View File

@ -0,0 +1,74 @@
/*
* Copyright [2020-2030] [https://www.stylefeng.cn]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* GunsAPACHE LICENSE 2.0使
*
* 1.LICENSE
* 2.Guns
* 3.
* 4. https://gitee.com/stylefeng/guns
* 5. https://gitee.com/stylefeng/guns
* 6.
*/
package cn.stylefeng.roses.kernel.file.api.util;
import cn.hutool.core.util.StrUtil;
import java.util.ArrayList;
import java.util.List;
/**
* svg
*
* @author fengshuonan
* @since 2023/7/10 11:41
*/
public class SvgFileTypeUtil {
/**
* svgcontent type
*/
public static final String SVG_RESPONSE_CONTENT_TYPE = "image/svg+xml";
private static final List<String> SVG_TYPES;
static {
SVG_TYPES = new ArrayList<>();
SVG_TYPES.add("svg");
}
/**
* svg
*
* @param fileName
* @return boolean true-svgfalse-svg
* @author fengshuonan
* @since 2023/7/10 11:41
*/
public static boolean getFileSvgTypeFlag(String fileName) {
if (StrUtil.isEmpty(fileName)) {
return false;
}
for (String picType : SVG_TYPES) {
if (fileName.toLowerCase().endsWith(picType)) {
return true;
}
}
return false;
}
}

View File

@ -49,6 +49,7 @@ import cn.stylefeng.roses.kernel.file.api.pojo.response.SysFileInfoResponse;
import cn.stylefeng.roses.kernel.file.api.util.DownloadUtil;
import cn.stylefeng.roses.kernel.file.api.util.PdfFileTypeUtil;
import cn.stylefeng.roses.kernel.file.api.util.PicFileTypeUtil;
import cn.stylefeng.roses.kernel.file.api.util.SvgFileTypeUtil;
import cn.stylefeng.roses.kernel.file.modular.entity.SysFileInfo;
import cn.stylefeng.roses.kernel.file.modular.entity.SysFileStorage;
import cn.stylefeng.roses.kernel.file.modular.factory.FileInfoFactory;
@ -159,7 +160,8 @@ public class SysFileInfoServiceImpl extends ServiceImpl<SysFileInfoMapper, SysFi
// 拼接文件可直接访问的url
String fileAuthUrl;
if (YesOrNotEnum.Y.getCode().equals(sysFileInfoRequest.getSecretFlag())) {
fileAuthUrl = fileOperatorApi.getFileAuthUrl(sysFileInfo.getFileBucket(), sysFileInfo.getFileObjectName(), FileConfigExpander.getDefaultFileTimeoutSeconds() * 1000);
fileAuthUrl = fileOperatorApi.getFileAuthUrl(sysFileInfo.getFileBucket(), sysFileInfo.getFileObjectName(),
FileConfigExpander.getDefaultFileTimeoutSeconds() * 1000);
} else {
fileAuthUrl = fileOperatorApi.getFileUnAuthUrl(sysFileInfo.getFileBucket(), sysFileInfo.getFileObjectName());
}
@ -254,7 +256,8 @@ public class SysFileInfoServiceImpl extends ServiceImpl<SysFileInfoMapper, SysFi
List<SysFileInfoListResponse> list = this.baseMapper.fileInfoList(page, sysFileInfoRequest);
// 排除defaultAvatar.png这个图片,这个是默认头像
List<SysFileInfoListResponse> newList = list.stream().filter(i -> !i.getFileOriginName().equals(FileConstants.DEFAULT_AVATAR_FILE_OBJ_NAME)).collect(Collectors.toList());
List<SysFileInfoListResponse> newList = list.stream()
.filter(i -> !i.getFileOriginName().equals(FileConstants.DEFAULT_AVATAR_FILE_OBJ_NAME)).collect(Collectors.toList());
// 拼接图片url地址
for (SysFileInfoListResponse sysFileInfoListResponse : newList) {
@ -467,7 +470,8 @@ public class SysFileInfoServiceImpl extends ServiceImpl<SysFileInfoMapper, SysFi
return this.sysFileStorageService.getFileAuthUrl(String.valueOf(fileId));
} else {
// 返回第三方存储文件url
return fileOperatorApi.getFileAuthUrl(sysFileInfo.getFileBucket(), sysFileInfo.getFileObjectName(), FileConfigExpander.getDefaultFileTimeoutSeconds());
return fileOperatorApi.getFileAuthUrl(sysFileInfo.getFileBucket(), sysFileInfo.getFileObjectName(),
FileConfigExpander.getDefaultFileTimeoutSeconds());
}
}
@ -545,13 +549,16 @@ public class SysFileInfoServiceImpl extends ServiceImpl<SysFileInfoMapper, SysFi
private void renderPreviewFile(HttpServletResponse response, String fileSuffix, byte[] fileBytes) {
// 如果文件后缀是图片或者pdf则直接输出流
if (PicFileTypeUtil.getFileImgTypeFlag(fileSuffix) || PdfFileTypeUtil.getFilePdfTypeFlag(fileSuffix)) {
if (PicFileTypeUtil.getFileImgTypeFlag(fileSuffix) || PdfFileTypeUtil.getFilePdfTypeFlag(
fileSuffix) || SvgFileTypeUtil.getFileSvgTypeFlag(fileSuffix)) {
try {
// 设置contentType
if (PicFileTypeUtil.getFileImgTypeFlag(fileSuffix)) {
response.setContentType(MediaType.IMAGE_PNG_VALUE);
} else if (PdfFileTypeUtil.getFilePdfTypeFlag(fileSuffix)) {
response.setContentType(MediaType.APPLICATION_PDF_VALUE);
} else if (SvgFileTypeUtil.getFileSvgTypeFlag(fileSuffix)) {
response.setContentType(SvgFileTypeUtil.SVG_RESPONSE_CONTENT_TYPE);
}
// 获取outputStream