优化列表显示为表格形式
修改: - /config list - 使用表格展示存储桶配置 - /path list - 使用表格展示预设路径 - /profile list - 使用表格展示上传配置模板 表格格式: | 名称 | 存储桶 | 区域 | CDN 域名 | |------|--------|------|----------| | default | daoqires | z2 | https://...
This commit is contained in:
145
src/index.js
145
src/index.js
@@ -483,7 +483,7 @@ async function handleConfigCommandV2(message, content, feishu, uploader) {
|
|||||||
try {
|
try {
|
||||||
if (subCommand === 'list' || !subCommand) {
|
if (subCommand === 'list' || !subCommand) {
|
||||||
const configData = await uploader.listConfig();
|
const configData = await uploader.listConfig();
|
||||||
await feishu.sendCard(chatId, createConfigCard(configData));
|
await feishu.sendCard(chatId, createBucketsListCard(configData));
|
||||||
} else if (subCommand === 'set') {
|
} else if (subCommand === 'set') {
|
||||||
const [keyPath, value] = args.slice(1);
|
const [keyPath, value] = args.slice(1);
|
||||||
await uploader.setConfigValue(keyPath, value);
|
await uploader.setConfigValue(keyPath, value);
|
||||||
@@ -513,14 +513,7 @@ async function handlePathCommandV2(message, content, feishu) {
|
|||||||
|
|
||||||
if (subCommand === 'list') {
|
if (subCommand === 'list') {
|
||||||
const paths = fullConfig.uploadPaths || {};
|
const paths = fullConfig.uploadPaths || {};
|
||||||
let pathText = '**预设路径列表:**\n\n';
|
await feishu.sendCard(chatId, createPathsListCard(paths));
|
||||||
for (const [name, pathValue] of Object.entries(paths)) {
|
|
||||||
pathText += `• **${name}**: ${pathValue || '(原文件名)'}\n`;
|
|
||||||
}
|
|
||||||
await feishu.sendMessage(chatId, {
|
|
||||||
msg_type: 'text',
|
|
||||||
content: { text: pathText }
|
|
||||||
});
|
|
||||||
} else if (subCommand === 'add') {
|
} else if (subCommand === 'add') {
|
||||||
const name = args[1];
|
const name = args[1];
|
||||||
const pathValue = args[2];
|
const pathValue = args[2];
|
||||||
@@ -552,16 +545,7 @@ async function handleProfileCommandV2(message, content, feishu) {
|
|||||||
|
|
||||||
if (subCommand === 'list' || !subCommand) {
|
if (subCommand === 'list' || !subCommand) {
|
||||||
const profiles = fullConfig.uploadProfiles || {};
|
const profiles = fullConfig.uploadProfiles || {};
|
||||||
let profileText = '**上传配置模板列表:**\n\n';
|
await feishu.sendCard(chatId, createProfilesListCard(profiles));
|
||||||
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 }
|
|
||||||
});
|
|
||||||
} else if (subCommand === 'add') {
|
} else if (subCommand === 'add') {
|
||||||
// /profile add <名称> <存储桶> [路径]
|
// /profile add <名称> <存储桶> [路径]
|
||||||
if (args.length < 3) {
|
if (args.length < 3) {
|
||||||
@@ -692,21 +676,132 @@ async function sendWelcomeCard(chatId, feishu) {
|
|||||||
await feishu.sendCard(chatId, card);
|
await feishu.sendCard(chatId, card);
|
||||||
}
|
}
|
||||||
|
|
||||||
function createConfigCard(configData) {
|
// 存储桶列表卡片(表格形式)
|
||||||
let configText = '';
|
function createBucketsListCard(configData) {
|
||||||
for (const [name, bucket] of Object.entries(configData.buckets)) {
|
const buckets = configData.buckets || {};
|
||||||
configText += `**[${name}]**\nBucket: ${bucket.bucket}\nRegion: ${bucket.region}\nDomain: ${bucket.domain}\n\n`;
|
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 {
|
return {
|
||||||
config: { wide_screen_mode: true },
|
config: { wide_screen_mode: true },
|
||||||
header: {
|
header: {
|
||||||
template: 'green',
|
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.post('/feishu/event', handleFeishuEvent);
|
||||||
app.get('/health', (req, res) => {
|
app.get('/health', (req, res) => {
|
||||||
res.json({ status: 'ok', timestamp: new Date().toISOString(), port: PORT });
|
res.json({ status: 'ok', timestamp: new Date().toISOString(), port: PORT });
|
||||||
|
|||||||
Reference in New Issue
Block a user