From 90af1d199d74d77cd9e241ee9a0e6a5b1976bf2f Mon Sep 17 00:00:00 2001 From: Wonder Date: Mon, 13 Oct 2025 19:49:57 +0800 Subject: [PATCH] =?UTF-8?q?=20=F0=9F=90=9BFix:=20=E6=8E=92=E9=99=A4?= =?UTF-8?q?=E9=83=A8=E5=88=86=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96=E5=BC=82?= =?UTF-8?q?=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hezhaohui/webhook/service/FileService.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/gitea-webhook/src/main/java/cn/hezhaohui/webhook/service/FileService.java b/gitea-webhook/src/main/java/cn/hezhaohui/webhook/service/FileService.java index 75832cf..ec0219d 100644 --- a/gitea-webhook/src/main/java/cn/hezhaohui/webhook/service/FileService.java +++ b/gitea-webhook/src/main/java/cn/hezhaohui/webhook/service/FileService.java @@ -4,9 +4,19 @@ import cn.hutool.http.HttpUtil; import org.springframework.stereotype.Service; import java.util.List; +import java.util.Set; @Service public class FileService { + private static final Set UNSUPPORTED_FILE_TYPES = Set.of( + ".jpg", ".jpeg", ".png", ".gif", ".bmp", ".ico", // 图片 + ".pdf", ".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", // 文档 + ".zip", ".rar", ".7z", ".tar", ".gz", // 压缩文件 + ".exe", ".dll", ".so", ".class", // 可执行文件 + ".jar", ".war", ".ear", // Java归档 + ".gitignore", ".gitattributes", ".gitmodules" // Git配置文件 + ); + // repo: http://47.121.181.112:3000/wonder/lark-webhook-sender // prefix: /raw/branch/main/ // raw: gitea-webhook/src/main/java/cn/hezhaohui/webhook/controller/HookController.java @@ -19,6 +29,13 @@ public class FileService { public String getRawContents(String repo, String raw) { String url = getRawUrl(repo, raw); String fileName = raw.substring(raw.lastIndexOf("/")+1); + + // 检查文件拓展名 + String fileExtension = fileName.substring(fileName.lastIndexOf(".")).toLowerCase(); + if (UNSUPPORTED_FILE_TYPES.contains(fileExtension)) { + return "[FileName]" + fileName + "\n[FileContent]*不支持显示的文件类型,请忽略\n"; + } + String fileContent = HttpUtil.get(url); return "[FileName]" + fileName + "\n" + "[FileContent]" + fileContent + "\n"; }