From 45831ad586e0a0b6cdd85da1f82e484648b76c43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E4=B8=93=E5=AE=B6?= Date: Wed, 25 Mar 2026 11:12:52 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=87=AA=E5=8A=A8=E6=B8=85=E7=90=86=20d?= =?UTF-8?q?omain=20=E9=85=8D=E7=BD=AE=E4=B8=AD=E7=9A=84=20Markdown=20?= =?UTF-8?q?=E9=93=BE=E6=8E=A5=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - setConfigValue: 添加 URL 清理逻辑,移除 Markdown 链接格式和末尾斜杠 - handleConfigCommandV2: /config add 命令自动清理 domain 参数 - 防止用户从飞书卡片复制 URL 时带入 Markdown 格式 修复场景: - 用户从卡片复制域名 [https://example.com](https://example.com/) - 使用 /config set 命令设置 domain - 自动清理为纯 URL: https://example.com --- src/index.js | 13 ++++++++++++- src/qiniu-uploader.js | 14 ++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 7e27e23..bd6cbc6 100644 --- a/src/index.js +++ b/src/index.js @@ -568,13 +568,24 @@ async function handleConfigCommandV2(message, content, feishu, uploader) { throw new Error('用法:/config add <名称> \n示例:/config add mybucket xxxxxx yyyyyy my-bucket z0 https://cdn.example.com'); } // 名称支持空格:从后往前解析,最后 5 个参数是固定的,其余是名称 - const domain = args[args.length - 1]; + let domain = args[args.length - 1]; const region = args[args.length - 2]; const bucket = args[args.length - 3]; const secretKey = args[args.length - 4]; const accessKey = args[args.length - 5]; const name = args.slice(0, args.length - 5).join(' '); + // 清理 domain 中的 Markdown 格式(防止用户从卡片复制时带入) + const markdownLinkRegex = /\[([^\]]+)\]\(([^)]+)\)/; + const match = domain.match(markdownLinkRegex); + if (match) { + domain = match[2]; + } + // 移除末尾的斜杠 + if (domain.endsWith('/')) { + domain = domain.slice(0, -1); + } + // 验证区域代码 const validRegions = ['z0', 'z1', 'z2', 'na0', 'as0']; if (!validRegions.includes(region)) { diff --git a/src/qiniu-uploader.js b/src/qiniu-uploader.js index 89403e9..232a61c 100644 --- a/src/qiniu-uploader.js +++ b/src/qiniu-uploader.js @@ -76,6 +76,20 @@ class QiniuUploader { const lastKey = keys[keys.length - 1]; + // 清理 URL 中的 Markdown 格式(防止用户从卡片复制时带入) + if (typeof value === 'string' && (value.includes('http://') || value.includes('https://'))) { + // 移除 Markdown 链接格式:[text](url) → url + const markdownLinkRegex = /\[([^\]]+)\]\(([^)]+)\)/; + const match = value.match(markdownLinkRegex); + if (match) { + value = match[2]; // 提取 URL 部分 + } + // 移除末尾的斜杠 + if (value.endsWith('/')) { + value = value.slice(0, -1); + } + } + // 类型转换 if (value === 'true') value = true; else if (value === 'false') value = false;