From 9bad70436a463eade90296fd502273939d9ba56a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A5=AD=E5=9B=A2?= Date: Fri, 6 Mar 2026 10:47:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=88=97=E8=A1=A8=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E4=B8=BA=E8=A1=A8=E6=A0=BC=E5=BD=A2=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改: - /config list - 使用表格展示存储桶配置 - /path list - 使用表格展示预设路径 - /profile list - 使用表格展示上传配置模板 表格格式: | 名称 | 存储桶 | 区域 | CDN 域名 | |------|--------|------|----------| | default | daoqires | z2 | https://... --- src/index.js | 145 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 120 insertions(+), 25 deletions(-) diff --git a/src/index.js b/src/index.js index d7ef03e..b86d302 100644 --- a/src/index.js +++ b/src/index.js @@ -483,7 +483,7 @@ async function handleConfigCommandV2(message, content, feishu, uploader) { try { if (subCommand === 'list' || !subCommand) { const configData = await uploader.listConfig(); - await feishu.sendCard(chatId, createConfigCard(configData)); + await feishu.sendCard(chatId, createBucketsListCard(configData)); } else if (subCommand === 'set') { const [keyPath, value] = args.slice(1); await uploader.setConfigValue(keyPath, value); @@ -513,14 +513,7 @@ async function handlePathCommandV2(message, content, feishu) { if (subCommand === 'list') { const paths = fullConfig.uploadPaths || {}; - let pathText = '**预设路径列表:**\n\n'; - for (const [name, pathValue] of Object.entries(paths)) { - pathText += `• **${name}**: ${pathValue || '(原文件名)'}\n`; - } - await feishu.sendMessage(chatId, { - msg_type: 'text', - content: { text: pathText } - }); + await feishu.sendCard(chatId, createPathsListCard(paths)); } else if (subCommand === 'add') { const name = args[1]; const pathValue = args[2]; @@ -552,16 +545,7 @@ async function handleProfileCommandV2(message, content, feishu) { if (subCommand === 'list' || !subCommand) { const profiles = fullConfig.uploadProfiles || {}; - let profileText = '**上传配置模板列表:**\n\n'; - for (const [name, config] of Object.entries(profiles)) { - profileText += `• **${name}**\n`; - profileText += ` 存储桶:${config.bucket}\n`; - profileText += ` 路径:${config.path || '(原文件名)'}\n\n`; - } - await feishu.sendMessage(chatId, { - msg_type: 'text', - content: { text: profileText } - }); + await feishu.sendCard(chatId, createProfilesListCard(profiles)); } else if (subCommand === 'add') { // /profile add <名称> <存储桶> [路径] if (args.length < 3) { @@ -692,21 +676,132 @@ async function sendWelcomeCard(chatId, feishu) { await feishu.sendCard(chatId, card); } -function createConfigCard(configData) { - let configText = ''; - for (const [name, bucket] of Object.entries(configData.buckets)) { - configText += `**[${name}]**\nBucket: ${bucket.bucket}\nRegion: ${bucket.region}\nDomain: ${bucket.domain}\n\n`; +// 存储桶列表卡片(表格形式) +function createBucketsListCard(configData) { + const buckets = configData.buckets || {}; + const entries = Object.entries(buckets); + + if (entries.length === 0) { + return { + config: { wide_screen_mode: true }, + header: { + template: 'grey', + title: { content: '⚙️ 七牛云存储桶配置', tag: 'plain_text' } + }, + elements: [{ tag: 'div', text: { tag: 'lark_md', content: '暂无配置' } }] + }; } + + // 构建表格内容 + let tableContent = '| 名称 | 存储桶 | 区域 | CDN 域名 |\n|------|--------|------|----------|\n'; + for (const [name, bucket] of entries) { + const domain = bucket.domain.length > 30 ? bucket.domain.substring(0, 27) + '...' : bucket.domain; + tableContent += `| ${name} | ${bucket.bucket} | ${bucket.region} | ${domain} |\n`; + } + return { config: { wide_screen_mode: true }, header: { template: 'green', - title: { content: '⚙️ 七牛云配置', tag: 'plain_text' } + title: { content: '⚙️ 七牛云存储桶配置', tag: 'plain_text' } }, - elements: [{ tag: 'div', text: { tag: 'lark_md', content: configText || '暂无配置' } }] + elements: [ + { + tag: 'div', + text: { + tag: 'lark_md', + content: tableContent + } + } + ] }; } +// 预设路径列表卡片(表格形式) +function createPathsListCard(paths) { + const entries = Object.entries(paths); + + if (entries.length === 0) { + return { + config: { wide_screen_mode: true }, + header: { + template: 'grey', + title: { content: '📁 预设路径列表', tag: 'plain_text' } + }, + elements: [{ tag: 'div', text: { tag: 'lark_md', content: '暂无预设路径' } }] + }; + } + + // 构建表格内容 + let tableContent = '| 名称 | 路径 |\n|------|------|\n'; + for (const [name, pathValue] of entries) { + const pathDisplay = pathValue || '(原文件名)'; + tableContent += `| **${name}** | ${pathDisplay} |\n`; + } + + return { + config: { wide_screen_mode: true }, + header: { + template: 'blue', + title: { content: '📁 预设路径列表', tag: 'plain_text' } + }, + elements: [ + { + tag: 'div', + text: { + tag: 'lark_md', + content: tableContent + } + } + ] + }; +} + +// 上传配置模板列表卡片(表格形式) +function createProfilesListCard(profiles) { + const entries = Object.entries(profiles); + + if (entries.length === 0) { + return { + config: { wide_screen_mode: true }, + header: { + template: 'grey', + title: { content: '📤 上传配置模板', tag: 'plain_text' } + }, + elements: [{ tag: 'div', text: { tag: 'lark_md', content: '暂无上传配置模板' } }] + }; + } + + // 构建表格内容 + let tableContent = '| 名称 | 存储桶 | 路径 |\n|------|--------|------|\n'; + for (const [name, config] of entries) { + const pathDisplay = config.path || '(原文件名)'; + tableContent += `| **${name}** | ${config.bucket} | ${pathDisplay} |\n`; + } + + return { + config: { wide_screen_mode: true }, + header: { + template: 'blue', + title: { content: '📤 上传配置模板', tag: 'plain_text' } + }, + elements: [ + { + tag: 'div', + text: { + tag: 'lark_md', + content: tableContent + } + } + ] + }; +} + +// 旧的配置卡片(保留兼容) +function createConfigCard(configData) { + return createBucketsListCard(configData); +} + app.post('/feishu/event', handleFeishuEvent); app.get('/health', (req, res) => { res.json({ status: 'ok', timestamp: new Date().toISOString(), port: PORT });