fix: 自动清理 domain 配置中的 Markdown 链接格式
- setConfigValue: 添加 URL 清理逻辑,移除 Markdown 链接格式和末尾斜杠 - handleConfigCommandV2: /config add 命令自动清理 domain 参数 - 防止用户从飞书卡片复制 URL 时带入 Markdown 格式 修复场景: - 用户从卡片复制域名 [https://example.com](https://example.com/) - 使用 /config set 命令设置 domain - 自动清理为纯 URL: https://example.com
This commit is contained in:
13
src/index.js
13
src/index.js
@@ -568,13 +568,24 @@ async function handleConfigCommandV2(message, content, feishu, uploader) {
|
||||
throw new Error('用法:/config add <名称> <accessKey> <secretKey> <bucket> <region> <domain>\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)) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user