From efe81c08244d42507319f70d288f6aeede12dda9 Mon Sep 17 00:00:00 2001 From: fengshuonan Date: Mon, 10 Jul 2023 13:19:37 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90portal=E3=80=91=E6=9B=B4=E6=96=B0svg?= =?UTF-8?q?=E7=9A=84=E9=A2=84=E8=A7=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kernel/file/api/util/PicFileTypeUtil.java | 1 - .../kernel/file/api/util/SvgFileTypeUtil.java | 74 +++++++++++++++++++ .../service/impl/SysFileInfoServiceImpl.java | 15 +++- 3 files changed, 85 insertions(+), 5 deletions(-) create mode 100644 kernel-d-file/file-api/src/main/java/cn/stylefeng/roses/kernel/file/api/util/SvgFileTypeUtil.java diff --git a/kernel-d-file/file-api/src/main/java/cn/stylefeng/roses/kernel/file/api/util/PicFileTypeUtil.java b/kernel-d-file/file-api/src/main/java/cn/stylefeng/roses/kernel/file/api/util/PicFileTypeUtil.java index 418887a6f..bf50739a3 100644 --- a/kernel-d-file/file-api/src/main/java/cn/stylefeng/roses/kernel/file/api/util/PicFileTypeUtil.java +++ b/kernel-d-file/file-api/src/main/java/cn/stylefeng/roses/kernel/file/api/util/PicFileTypeUtil.java @@ -47,7 +47,6 @@ public class PicFileTypeUtil { PIC_TYPES.add("tif"); PIC_TYPES.add("gif"); PIC_TYPES.add("bmp"); - PIC_TYPES.add("svg"); } /** diff --git a/kernel-d-file/file-api/src/main/java/cn/stylefeng/roses/kernel/file/api/util/SvgFileTypeUtil.java b/kernel-d-file/file-api/src/main/java/cn/stylefeng/roses/kernel/file/api/util/SvgFileTypeUtil.java new file mode 100644 index 000000000..5a766ae9a --- /dev/null +++ b/kernel-d-file/file-api/src/main/java/cn/stylefeng/roses/kernel/file/api/util/SvgFileTypeUtil.java @@ -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 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; + } + +} diff --git a/kernel-d-file/file-business/src/main/java/cn/stylefeng/roses/kernel/file/modular/service/impl/SysFileInfoServiceImpl.java b/kernel-d-file/file-business/src/main/java/cn/stylefeng/roses/kernel/file/modular/service/impl/SysFileInfoServiceImpl.java index ba94826a9..e69c86e46 100644 --- a/kernel-d-file/file-business/src/main/java/cn/stylefeng/roses/kernel/file/modular/service/impl/SysFileInfoServiceImpl.java +++ b/kernel-d-file/file-business/src/main/java/cn/stylefeng/roses/kernel/file/modular/service/impl/SysFileInfoServiceImpl.java @@ -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 list = this.baseMapper.fileInfoList(page, sysFileInfoRequest); // 排除defaultAvatar.png这个图片,这个是默认头像 - List newList = list.stream().filter(i -> !i.getFileOriginName().equals(FileConstants.DEFAULT_AVATAR_FILE_OBJ_NAME)).collect(Collectors.toList()); + List 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