mirror of https://gitee.com/stylefeng/roses
【portal】更新svg的预览
parent
99700a7948
commit
efe81c0824
|
@ -47,7 +47,6 @@ public class PicFileTypeUtil {
|
|||
PIC_TYPES.add("tif");
|
||||
PIC_TYPES.add("gif");
|
||||
PIC_TYPES.add("bmp");
|
||||
PIC_TYPES.add("svg");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
* Guns采用APACHE 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 {
|
||||
|
||||
/**
|
||||
* svg的响应头的content 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-是svg类型,false-不是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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue