添加路径管理命令

功能:
1. 简化预设路径配置(原文件名 + ipa)
2. 添加/path 命令管理预设路径
   - /path list - 查看预设路径
   - /path add <名称> <路径> - 添加预设路径
   - /path remove <名称> - 删除预设路径

配置示例:
{
  "uploadPaths": {
    "原文件名": "",
    "ipa": "/ipa/gamehall_jinxianv2.ipa"
  }
}

使用示例:
/path add backup /backup/files/
/path list
/path remove backup
This commit is contained in:
饭团
2026-03-06 08:57:18 +08:00
parent 0bb34a774d
commit bf5b79c62b

View File

@@ -94,6 +94,8 @@ async function handleMessage(event) {
});
} else if (text.startsWith('/config') || text.startsWith('/qc ')) {
await handleConfigCommandV2(messageData, messageContent, feishu, uploader);
} else if (text.startsWith('/path')) {
await handlePathCommandV2(messageData, messageContent, feishu);
} else if (text.startsWith('/help') || text.startsWith('/qh')) {
await handleHelpCommandV2(chatId, feishu);
} else if (messageType === 'file' || messageContent.file_key) {
@@ -399,6 +401,72 @@ async function handleConfigCommandV2(message, content, feishu, uploader) {
}
}
async function handlePathCommandV2(message, content, feishu) {
const chatId = message.chat_id;
const text = content.text || '';
const args = text.replace(/^\/path\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 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 }
});
} else if (subCommand === 'add') {
// 添加预设路径:/path add <名称> <路径>
if (args.length < 3) {
throw new Error('用法:/path add <名称> <路径>\n示例/path add ipa /ipa/gamehall.ipa');
}
const name = args[1];
const pathValue = args[2];
fullConfig.uploadPaths = fullConfig.uploadPaths || {};
fullConfig.uploadPaths[name] = pathValue;
fs.writeFileSync(configPath, JSON.stringify(fullConfig, null, 2));
await feishu.sendMessage(chatId, {
msg_type: 'text',
content: { text: `✅ 已添加预设路径:**${name}** → ${pathValue}` }
});
} else if (subCommand === 'remove' || subCommand === 'del') {
// 删除预设路径:/path remove <名称>
if (args.length < 2) {
throw new Error('用法:/path remove <名称>');
}
const name = args[1];
if (!fullConfig.uploadPaths || !fullConfig.uploadPaths[name]) {
throw new Error(`预设路径 "${name}" 不存在`);
}
delete fullConfig.uploadPaths[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',
@@ -414,10 +482,19 @@ async function handleHelpCommandV2(chatId, feishu) {
/config list - 查看配置
/config set <key> <value> - 修改配置
📁 路径管理:
/path list - 查看预设路径
/path add <名称> <路径> - 添加预设路径
/path remove <名称> - 删除预设路径
💡 提示:
- 支持多存储桶配置
- 支持预设路径
- 上传同名文件会自动覆盖
示例:
/path add backup /backup/
/path remove backup
` }
});
}