fix: 上传成功后清除文件状态,防止重复使用旧文件

- select_profile: 选择配置时清除 file_key,确保必须重新发送文件
- confirm_upload: 上传成功后 clearUserState() 完整清除状态
- handleFileReceived: 收到新文件时清除旧配置,避免配置污染

修复问题:之前上传成功后 userStates 中的 file_key 未清除,
导致再次点击配置可能误用之前的文件,造成混乱。
This commit is contained in:
饭团
2026-03-20 00:48:13 +08:00
parent 7a183d3324
commit 68f7fb57ee

View File

@@ -153,11 +153,16 @@ async function handleCardInteraction(event) {
const { profile_name, bucket, path_key } = actionData.value;
log('📋 选择上传配置:', profile_name);
// path_key 是预设路径的名称,需要从配置中获取实际路径
// 清除之前的文件信息,确保必须重新上传文件
const state = getUserState(chatId);
setUserState(chatId, {
profile_name,
bucket,
path_key
path_key,
// 清除文件信息
file_key: undefined,
file_name: undefined,
message_id: undefined
});
await feishu.sendMessage(chatId, {
@@ -209,6 +214,7 @@ async function handleCardInteraction(event) {
await doUpload(chatId, feishu, uploader, {
file_key, file_name, message_id, bucket, upload_path, path_label, path_key
});
// 上传成功后清除所有状态(包括文件信息)
clearUserState(chatId);
break;
}
@@ -320,11 +326,15 @@ async function handleFileReceived(messageData, feishu, uploader) {
if (!fileKey) return;
// 保存文件信息到状态
// 清除之前的配置,保存文件信息(覆盖旧文件)
setUserState(chatId, {
file_key: fileKey,
file_name: fileName,
message_id: messageId
message_id: messageId,
// 清除之前的配置选择
profile_name: undefined,
bucket: undefined,
path_key: undefined
});
const state = getUserState(chatId);