profile 路径改为引用 path 的键名
修改:
- profile 配置中的 path 字段现在存储路径键名,而不是直接路径值
- /profile add 命令现在使用路径键名:/profile add IPA 上传 default ipa
- 上传时根据路径键名从 uploadPaths 中获取实际路径
- 列表卡片显示路径键名和对应的值
配置示例:
{
"uploadPaths": {
"ipa": "/ipa/gamehall.ipa"
},
"uploadProfiles": {
"IPA 上传": {
"bucket": "default",
"path": "ipa" // 引用 uploadPaths 中的键名
}
}
}
This commit is contained in:
130
src/index.js
130
src/index.js
@@ -138,25 +138,26 @@ async function handleCardInteraction(event) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'select_profile': {
|
case 'select_profile': {
|
||||||
const { profile_name, bucket, path: upload_path } = actionData.value;
|
const { profile_name, bucket, path_key } = actionData.value;
|
||||||
log('📋 选择上传配置:', profile_name);
|
log('📋 选择上传配置:', profile_name);
|
||||||
|
|
||||||
|
// path_key 是预设路径的名称,需要从配置中获取实际路径
|
||||||
setUserState(chatId, {
|
setUserState(chatId, {
|
||||||
profile_name,
|
profile_name,
|
||||||
bucket,
|
bucket,
|
||||||
upload_path
|
path_key
|
||||||
});
|
});
|
||||||
|
|
||||||
await feishu.sendMessage(chatId, {
|
await feishu.sendMessage(chatId, {
|
||||||
msg_type: 'text',
|
msg_type: 'text',
|
||||||
content: { text: `✅ 已选择配置:**${profile_name}**\n\n📤 请发送文件,或点击"📎 选择文件上传"` }
|
content: { text: `✅ 已选择配置:**${profile_name}**\n\n📤 请发送文件` }
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'upload_with_profile': {
|
case 'upload_with_profile': {
|
||||||
// 从配置卡片直接上传(需要先发送文件)
|
// 从配置卡片直接上传(需要先发送文件)
|
||||||
const { profile_name, bucket, path: upload_path } = actionData.value;
|
const { profile_name, bucket, path_key } = actionData.value;
|
||||||
const state = getUserState(chatId);
|
const state = getUserState(chatId);
|
||||||
|
|
||||||
if (!state.file_key) {
|
if (!state.file_key) {
|
||||||
@@ -167,22 +168,34 @@ async function handleCardInteraction(event) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 从预设路径配置中获取实际路径
|
||||||
|
const fullConfig = loadFullConfig();
|
||||||
|
const uploadPaths = fullConfig.uploadPaths || {};
|
||||||
|
const upload_path = uploadPaths[path_key] || '';
|
||||||
|
|
||||||
await doUpload(chatId, feishu, uploader, {
|
await doUpload(chatId, feishu, uploader, {
|
||||||
file_key: state.file_key,
|
file_key: state.file_key,
|
||||||
file_name: state.file_name,
|
file_name: state.file_name,
|
||||||
message_id: state.message_id,
|
message_id: state.message_id,
|
||||||
bucket,
|
bucket,
|
||||||
upload_path,
|
upload_path,
|
||||||
path_label: profile_name
|
path_label: profile_name,
|
||||||
|
path_key
|
||||||
});
|
});
|
||||||
clearUserState(chatId);
|
clearUserState(chatId);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'confirm_upload': {
|
case 'confirm_upload': {
|
||||||
const { file_key, file_name, message_id, bucket, upload_path, path_label } = actionData.value;
|
const { file_key, file_name, message_id, bucket, path_key, path_label } = actionData.value;
|
||||||
|
|
||||||
|
// 从预设路径配置中获取实际路径
|
||||||
|
const fullConfig = loadFullConfig();
|
||||||
|
const uploadPaths = fullConfig.uploadPaths || {};
|
||||||
|
const upload_path = uploadPaths[path_key] || '';
|
||||||
|
|
||||||
await doUpload(chatId, feishu, uploader, {
|
await doUpload(chatId, feishu, uploader, {
|
||||||
file_key, file_name, message_id, bucket, upload_path, path_label
|
file_key, file_name, message_id, bucket, upload_path, path_label, path_key
|
||||||
});
|
});
|
||||||
clearUserState(chatId);
|
clearUserState(chatId);
|
||||||
break;
|
break;
|
||||||
@@ -213,17 +226,25 @@ async function showProfileCard(chatId, feishu, uploader) {
|
|||||||
const fullConfig = loadFullConfig();
|
const fullConfig = loadFullConfig();
|
||||||
const profiles = fullConfig.uploadProfiles || {};
|
const profiles = fullConfig.uploadProfiles || {};
|
||||||
|
|
||||||
const profileButtons = Object.entries(profiles).map(([name, config]) => ({
|
const profileButtons = Object.entries(profiles).map(([name, config]) => {
|
||||||
tag: 'button',
|
// config.path 是预设路径的名称(键)
|
||||||
text: { tag: 'plain_text', content: name },
|
const pathKey = config.path || '';
|
||||||
type: 'primary',
|
const uploadPaths = fullConfig.uploadPaths || {};
|
||||||
value: {
|
const pathValue = uploadPaths[pathKey] || '';
|
||||||
action: 'select_profile',
|
const pathDisplay = pathValue || '(原文件名)';
|
||||||
profile_name: name,
|
|
||||||
bucket: config.bucket,
|
return {
|
||||||
path: config.path || ''
|
tag: 'button',
|
||||||
}
|
text: { tag: 'plain_text', content: `${name}` },
|
||||||
}));
|
type: 'primary',
|
||||||
|
value: {
|
||||||
|
action: 'select_profile',
|
||||||
|
profile_name: name,
|
||||||
|
bucket: config.bucket,
|
||||||
|
path_key: pathKey
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
const card = {
|
const card = {
|
||||||
config: { wide_screen_mode: true },
|
config: { wide_screen_mode: true },
|
||||||
@@ -310,22 +331,28 @@ async function handleFileReceived(messageData, feishu, uploader) {
|
|||||||
// 未选择配置,显示配置选择卡片
|
// 未选择配置,显示配置选择卡片
|
||||||
const fullConfig = loadFullConfig();
|
const fullConfig = loadFullConfig();
|
||||||
const profiles = fullConfig.uploadProfiles || {};
|
const profiles = fullConfig.uploadProfiles || {};
|
||||||
|
const uploadPaths = fullConfig.uploadPaths || {};
|
||||||
|
|
||||||
const profileButtons = Object.entries(profiles).map(([name, config]) => ({
|
const profileButtons = Object.entries(profiles).map(([name, config]) => {
|
||||||
tag: 'button',
|
// config.path 是预设路径的名称(键)
|
||||||
text: { tag: 'plain_text', content: `${name}` },
|
const pathKey = config.path || '';
|
||||||
type: 'primary',
|
|
||||||
value: {
|
return {
|
||||||
action: 'confirm_upload',
|
tag: 'button',
|
||||||
file_key: fileKey,
|
text: { tag: 'plain_text', content: `${name}` },
|
||||||
file_name: fileName,
|
type: 'primary',
|
||||||
message_id: messageId,
|
value: {
|
||||||
chat_id: chatId,
|
action: 'confirm_upload',
|
||||||
bucket: config.bucket,
|
file_key: fileKey,
|
||||||
upload_path: config.path || '',
|
file_name: fileName,
|
||||||
path_label: name
|
message_id: messageId,
|
||||||
}
|
chat_id: chatId,
|
||||||
}));
|
bucket: config.bucket,
|
||||||
|
path_key: pathKey,
|
||||||
|
path_label: name
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
const card = {
|
const card = {
|
||||||
config: { wide_screen_mode: true },
|
config: { wide_screen_mode: true },
|
||||||
@@ -375,7 +402,13 @@ async function handleFileReceived(messageData, feishu, uploader) {
|
|||||||
|
|
||||||
// 显示确认卡片
|
// 显示确认卡片
|
||||||
async function showConfirmCard(chatId, feishu, info) {
|
async function showConfirmCard(chatId, feishu, info) {
|
||||||
const { file_name, bucket, upload_path, path_label } = info;
|
const { file_name, bucket, path_key, path_label } = info;
|
||||||
|
|
||||||
|
// 从预设路径配置中获取实际路径
|
||||||
|
const fullConfig = loadFullConfig();
|
||||||
|
const uploadPaths = fullConfig.uploadPaths || {};
|
||||||
|
const upload_path = uploadPaths[path_key] || '';
|
||||||
|
|
||||||
let targetKey = upload_path || file_name;
|
let targetKey = upload_path || file_name;
|
||||||
if (targetKey.startsWith('/')) targetKey = targetKey.substring(1);
|
if (targetKey.startsWith('/')) targetKey = targetKey.substring(1);
|
||||||
|
|
||||||
@@ -407,7 +440,7 @@ async function showConfirmCard(chatId, feishu, info) {
|
|||||||
message_id: info.message_id,
|
message_id: info.message_id,
|
||||||
chat_id: chatId,
|
chat_id: chatId,
|
||||||
bucket,
|
bucket,
|
||||||
upload_path,
|
path_key,
|
||||||
path_label
|
path_label
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -545,31 +578,40 @@ async function handleProfileCommandV2(message, content, feishu) {
|
|||||||
|
|
||||||
if (subCommand === 'list' || !subCommand) {
|
if (subCommand === 'list' || !subCommand) {
|
||||||
const profiles = fullConfig.uploadProfiles || {};
|
const profiles = fullConfig.uploadProfiles || {};
|
||||||
await feishu.sendCard(chatId, createProfilesListCard(profiles));
|
const uploadPaths = fullConfig.uploadPaths || {};
|
||||||
|
await feishu.sendCard(chatId, createProfilesListCard(profiles, uploadPaths));
|
||||||
} else if (subCommand === 'add') {
|
} else if (subCommand === 'add') {
|
||||||
// /profile add <名称> <存储桶> [路径]
|
// /profile add <名称> <存储桶> [路径键名]
|
||||||
if (args.length < 3) {
|
if (args.length < 3) {
|
||||||
throw new Error('用法:/profile add <名称> <存储桶> [路径]\n示例:/profile add IPA 上传 default /ipa/');
|
throw new Error('用法:/profile add <名称> <存储桶> [路径键名]\n示例:/profile add IPA 上传 default ipa');
|
||||||
}
|
}
|
||||||
const name = args[1];
|
const name = args[1];
|
||||||
const bucket = args[2];
|
const bucket = args[2];
|
||||||
const pathValue = args[3] || '';
|
const pathKey = args[3] || '';
|
||||||
|
|
||||||
// 验证存储桶是否存在
|
// 验证存储桶是否存在
|
||||||
if (!fullConfig.buckets[bucket]) {
|
if (!fullConfig.buckets[bucket]) {
|
||||||
throw new Error(`存储桶 "${bucket}" 不存在,可用:${Object.keys(fullConfig.buckets).join(', ')}`);
|
throw new Error(`存储桶 "${bucket}" 不存在,可用:${Object.keys(fullConfig.buckets).join(', ')}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 验证路径键名是否存在(如果有提供)
|
||||||
|
if (pathKey && (!fullConfig.uploadPaths || !fullConfig.uploadPaths[pathKey])) {
|
||||||
|
const availablePaths = Object.keys(fullConfig.uploadPaths || {}).join(', ');
|
||||||
|
throw new Error(`路径 "${pathKey}" 不存在,可用:${availablePaths || '无'}`);
|
||||||
|
}
|
||||||
|
|
||||||
fullConfig.uploadProfiles = fullConfig.uploadProfiles || {};
|
fullConfig.uploadProfiles = fullConfig.uploadProfiles || {};
|
||||||
fullConfig.uploadProfiles[name] = {
|
fullConfig.uploadProfiles[name] = {
|
||||||
bucket: bucket,
|
bucket: bucket,
|
||||||
path: pathValue
|
path: pathKey // 存储路径键名,不是路径值
|
||||||
};
|
};
|
||||||
|
|
||||||
fs.writeFileSync(configPath, JSON.stringify(fullConfig, null, 2));
|
fs.writeFileSync(configPath, JSON.stringify(fullConfig, null, 2));
|
||||||
|
|
||||||
|
const pathDisplay = pathKey ? `${pathKey} (${fullConfig.uploadPaths[pathKey]})` : '(原文件名)';
|
||||||
await feishu.sendMessage(chatId, {
|
await feishu.sendMessage(chatId, {
|
||||||
msg_type: 'text',
|
msg_type: 'text',
|
||||||
content: { text: `✅ 已添加上传配置:**${name}**\n存储桶:${bucket}\n路径:${pathValue || '(原文件名)'}` }
|
content: { text: `✅ 已添加上传配置:**${name}**\n存储桶:${bucket}\n路径:${pathDisplay}` }
|
||||||
});
|
});
|
||||||
} else if (subCommand === 'remove' || subCommand === 'del') {
|
} else if (subCommand === 'remove' || subCommand === 'del') {
|
||||||
if (args.length < 2) {
|
if (args.length < 2) {
|
||||||
@@ -758,7 +800,7 @@ function createPathsListCard(paths) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 上传配置模板列表卡片(表格形式)
|
// 上传配置模板列表卡片(表格形式)
|
||||||
function createProfilesListCard(profiles) {
|
function createProfilesListCard(profiles, uploadPaths) {
|
||||||
const entries = Object.entries(profiles);
|
const entries = Object.entries(profiles);
|
||||||
|
|
||||||
if (entries.length === 0) {
|
if (entries.length === 0) {
|
||||||
@@ -775,7 +817,9 @@ function createProfilesListCard(profiles) {
|
|||||||
// 构建表格内容
|
// 构建表格内容
|
||||||
let tableContent = '| 名称 | 存储桶 | 路径 |\n|------|--------|------|\n';
|
let tableContent = '| 名称 | 存储桶 | 路径 |\n|------|--------|------|\n';
|
||||||
for (const [name, config] of entries) {
|
for (const [name, config] of entries) {
|
||||||
const pathDisplay = config.path || '(原文件名)';
|
const pathKey = config.path || '';
|
||||||
|
const pathValue = uploadPaths && uploadPaths[pathKey] ? uploadPaths[pathKey] : '(原文件名)';
|
||||||
|
const pathDisplay = pathKey ? `${pathKey} → ${pathValue}` : '(原文件名)';
|
||||||
tableContent += `| **${name}** | ${config.bucket} | ${pathDisplay} |\n`;
|
tableContent += `| **${name}** | ${config.bucket} | ${pathDisplay} |\n`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user