添加上传配置模板命令管理

新命令:
/profile list - 查看上传配置模板
/profile add <名称> <存储桶> [路径] - 添加上传配置
/profile remove <名称> - 删除上传配置

使用示例:
/profile add IPA 上传 default /ipa/
/profile add 备份 default /backup/
/profile list
/profile remove 备份

配置存储在 config/qiniu-config.json 的 uploadProfiles 字段
This commit is contained in:
饭团
2026-03-06 10:37:54 +08:00
parent 00824c8433
commit 4d2001865d

View File

@@ -101,6 +101,8 @@ async function handleMessage(event) {
await handleConfigCommandV2(messageData, messageContent, feishu, uploader);
} else if (text.startsWith('/path')) {
await handlePathCommandV2(messageData, messageContent, feishu);
} else if (text.startsWith('/profile')) {
await handleProfileCommandV2(messageData, messageContent, feishu);
} else if (text.startsWith('/help') || text.startsWith('/qh')) {
await handleHelpCommandV2(chatId, feishu);
} else if (messageType === 'file' || messageContent.file_key) {
@@ -537,6 +539,81 @@ async function handlePathCommandV2(message, content, feishu) {
}
}
async function handleProfileCommandV2(message, content, feishu) {
const chatId = message.chat_id;
const text = content.text || '';
const args = text.replace(/^\/profile\s*/i, '').trim().split(/\s+/);
const subCommand = args[0];
const configPath = path.join(process.cwd(), 'config', 'qiniu-config.json');
try {
const fullConfig = loadFullConfig();
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 }
});
} else if (subCommand === 'add') {
// /profile add <名称> <存储桶> [路径]
if (args.length < 3) {
throw new Error('用法:/profile add <名称> <存储桶> [路径]\n示例/profile add IPA 上传 default /ipa/');
}
const name = args[1];
const bucket = args[2];
const pathValue = args[3] || '';
// 验证存储桶是否存在
if (!fullConfig.buckets[bucket]) {
throw new Error(`存储桶 "${bucket}" 不存在,可用:${Object.keys(fullConfig.buckets).join(', ')}`);
}
fullConfig.uploadProfiles = fullConfig.uploadProfiles || {};
fullConfig.uploadProfiles[name] = {
bucket: bucket,
path: pathValue
};
fs.writeFileSync(configPath, JSON.stringify(fullConfig, null, 2));
await feishu.sendMessage(chatId, {
msg_type: 'text',
content: { text: `✅ 已添加上传配置:**${name}**\n存储桶:${bucket}\n路径:${pathValue || '(原文件名)'}` }
});
} else if (subCommand === 'remove' || subCommand === 'del') {
if (args.length < 2) {
throw new Error('用法:/profile remove <名称>');
}
const name = args[1];
if (!fullConfig.uploadProfiles || !fullConfig.uploadProfiles[name]) {
throw new Error(`上传配置 "${name}" 不存在`);
}
delete fullConfig.uploadProfiles[name];
fs.writeFileSync(configPath, JSON.stringify(fullConfig, null, 2));
await feishu.sendMessage(chatId, {
msg_type: 'text',
content: { text: `✅ 已删除上传配置:**${name}**` }
});
} else {
throw new Error(`未知命令:${subCommand}\n可用命令list, add, remove`);
}
} catch (error) {
await feishu.sendMessage(chatId, {
msg_type: 'text',
content: { text: `❌ 配置管理失败:${error.message}` }
});
}
}
async function handleHelpCommandV2(chatId, feishu) {
await feishu.sendMessage(chatId, {
msg_type: 'text',
@@ -557,13 +634,22 @@ async function handleHelpCommandV2(chatId, feishu) {
3. 确认上传
⚙️ 配置管理:
/config list - 查看配置
/path list - 查看预设路径
/path add <名称> <路径> - 添加路径
/config list - 查看七牛云配置
/profile list - 查看上传配置模板
/profile add <名称> <存储桶> [路径] - 添加上传配置
/profile remove <名称> - 删除上传配置
💡 提示:
- 上传配置在 config/qiniu-config.json 中配置
- 支持多存储桶
📁 路径管理:
/path list - 查看预设路径
/path add <名称> <路径> - 添加预设路径
💡 示例:
/profile add IPA 上传 default /ipa/
/profile add 备份 default /backup/
/profile list
/profile remove 备份
**提示:**
- 上传同名文件会自动覆盖
` }
});