backup codes

This commit is contained in:
2026-07-22 14:56:37 +08:00
parent c01c5c98e3
commit 53cd2ea9b8

View File

@@ -406,12 +406,13 @@ function handleAIResult(aiResult, roomId, username, originalText, attachments) {
}
if (aiResult.action === 'purchase') {
// 引用最近图片:用户要求把之前的图片关联到某采购
let usedRecentImage = false;
if (aiResult.use_recent_image) {
const recentMsg = db.prepare("SELECT attachments FROM messages WHERE room_id = ? AND attachments IS NOT NULL AND attachments != '' ORDER BY timestamp DESC LIMIT 1").get(roomId);
if (recentMsg) {
try {
const files = JSON.parse(recentMsg.attachments);
if (files.length) attachments = files;
if (files.length) { attachments = files; usedRecentImage = true; }
} catch(e) {}
}
}
@@ -478,6 +479,12 @@ function handleAIResult(aiResult, roomId, username, originalText, attachments) {
if (attachments?.length) {
const insertAttach = db.prepare('INSERT INTO purchase_attachments (purchase_id, file_path, uploaded_by, timestamp) VALUES (?,?,?,?)');
attachments.forEach(fp => insertAttach.run(purchase.id, fp, username, now));
if (usedRecentImage) {
replyText = `📎 已为「${aiResult.purchase_item}」关联 ${attachments.length} 个附件`;
db.prepare('INSERT INTO purchase_history (purchase_id, action, user, timestamp) VALUES (?,?,?,?)').run(purchase.id, `添加附件:${attachments.length}`, username, now);
}
} else if (usedRecentImage) {
replyText = `❌ 未找到最近的图片消息,请先发送图片再试。`;
}
storeAndBroadcastText(roomId, '小财', replyText);
addToHistory(roomId, 'assistant', replyText);