From ee039c861b93fdc7a9732a10b991ea88a24d93dd Mon Sep 17 00:00:00 2001 From: wangjiahao <1522128093@qq.com> Date: Wed, 12 Jun 2024 14:35:31 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E4=BB=AA=E8=A1=A8=E6=9D=BF=E3=80=81?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=A4=A7=E5=B1=8F):=20=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E8=83=8C=E6=99=AF=E4=B8=8A=E4=BC=A0SVG=E5=8A=A8=E5=9B=BE?= =?UTF-8?q?=E5=B9=B6=E5=81=9A=E5=90=8E=E7=AB=AF=E9=AA=8C=E8=AF=81=20#7169?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/StaticResourceServer.java | 36 ++++++++++++++++++- .../BackgroundOverallCommon.vue | 2 +- .../component-background/CanvasBackground.vue | 2 +- .../src/custom-component/picture/Attr.vue | 2 +- core/core-frontend/src/locales/zh-CN.ts | 2 +- .../dashboard/MobileBackgroundSelector.vue | 2 +- 6 files changed, 40 insertions(+), 6 deletions(-) diff --git a/core/core-backend/src/main/java/io/dataease/visualization/server/StaticResourceServer.java b/core/core-backend/src/main/java/io/dataease/visualization/server/StaticResourceServer.java index d8a4962c7a..5e8b71d3d6 100644 --- a/core/core-backend/src/main/java/io/dataease/visualization/server/StaticResourceServer.java +++ b/core/core-backend/src/main/java/io/dataease/visualization/server/StaticResourceServer.java @@ -16,9 +16,15 @@ import org.springframework.util.FileCopyUtils; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; +import org.w3c.dom.Document; +import org.xml.sax.SAXException; import javax.imageio.ImageIO; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; import java.awt.image.BufferedImage; +import java.io.File; import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; @@ -65,7 +71,12 @@ public class StaticResourceServer implements StaticResourceApi { LogUtil.error(e.getMessage(), e); return false; } - if (image == null || image.getWidth() <= 0 || image.getHeight() <= 0) { + // 判断是否为SVG + if(isValidSVG(file)){ + return true; + } + // 判断其他图片 + if (image == null || image.getWidth() <= 0 || image.getHeight() <= 0 || !isValidSVG(file)) { return false; } return true; @@ -116,4 +127,27 @@ public class StaticResourceServer implements StaticResourceApi { return null; } + private static boolean isValidSVG(MultipartFile file) { + if (file == null || file.isEmpty()) { + return false; + } + + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + + try (InputStream inputStream = file.getInputStream()) { + DocumentBuilder db = dbf.newDocumentBuilder(); + Document doc = db.parse(inputStream); + + // 检查根元素是否是 + if ("svg".equals(doc.getDocumentElement().getNodeName())) { + return true; + } else { + return false; + } + } catch (ParserConfigurationException | SAXException | IOException e) { + // 如果出现任何解析错误,说明该文件不是合法的SVG + return false; + } + } } diff --git a/core/core-frontend/src/components/visualization/component-background/BackgroundOverallCommon.vue b/core/core-frontend/src/components/visualization/component-background/BackgroundOverallCommon.vue index 78392a2547..bc9149a725 100644 --- a/core/core-frontend/src/components/visualization/component-background/BackgroundOverallCommon.vue +++ b/core/core-frontend/src/components/visualization/component-background/BackgroundOverallCommon.vue @@ -187,7 +187,7 @@ class="image-hint" :class="`image-hint_${themes}`" > - 支持JPG、PNG、GIF + 支持JPG、PNG、GIF、SVG - 支持JPG、PNG、GIF + 支持JPG、PNG、GIF、SVG { class="image-hint" :class="`image-hint_${themes}`" > - 支持JPG、PNG、GIF + 支持JPG、PNG、GIF、SVG - 支持JPG、PNG、GIF,大小不超过 1M + 支持JPG、PNG、GIF、SVG,大小不超过 1M