This commit is contained in:
张成
2026-03-13 16:53:26 +08:00
parent 2c021c24ef
commit 6aeee136c4
3 changed files with 51 additions and 16 deletions

View File

@@ -75,7 +75,7 @@ module.exports = {
* example: '用户不存在或密码错误' * example: '用户不存在或密码错误'
*/ */
"POST /user/login": async (ctx) => { "POST /user/login": async (ctx) => {
const { login_name:email, password, device_id: client_device_id } = ctx.getBody(); const { login_name: email, password, device_id: client_device_id } = ctx.getBody();
const dayjs = require('dayjs'); const dayjs = require('dayjs');
const { verifyPassword, validateDeviceId, maskEmail } = require('../utils/crypto_utils'); const { verifyPassword, validateDeviceId, maskEmail } = require('../utils/crypto_utils');
@@ -87,16 +87,6 @@ module.exports = {
// 统一邮箱地址为小写 // 统一邮箱地址为小写
const email_normalized = email.toLowerCase().trim(); const email_normalized = email.toLowerCase().trim();
// 验证邮箱格式
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(email_normalized)) {
return ctx.fail('邮箱格式不正确');
}
// 验证密码长度
if (password.length < 6 || password.length > 50) {
return ctx.fail('密码长度不正确');
}
const { pla_account } = await Framework.getModels(); const { pla_account } = await Framework.getModels();
@@ -447,7 +437,7 @@ module.exports = {
console.log('[保存投递配置成功]', { console.log('[保存投递配置成功]', {
sn_code, sn_code,
deliver_config:new_deliver_config, deliver_config: new_deliver_config,
auto_deliver: auto_deliver_value, auto_deliver: auto_deliver_value,
timestamp: new Date().toISOString() timestamp: new Date().toISOString()
}); });

View File

@@ -300,6 +300,40 @@ class MqttDispatcher {
} }
} }
/**
* 处理来自 boss-automation-nodejs 的 Boss 聊天消息
* @param {object|string} message - Boss 消息对象或 JSON 字符串
*/
async handleBossMessage(message) {
try {
let data = message;
if (typeof message === 'string') {
try {
data = JSON.parse(message);
} catch (e) {
console.warn('[MQTT Boss 消息] JSON 解析失败,按原始字符串处理');
}
}
const sn_code = data && data.sn_code ? data.sn_code : null;
const payload = data && data.payload ? data.payload : null;
if (!sn_code || !payload) {
console.warn('[MQTT Boss 消息] sn_code 或 payload 缺失,忽略:', data);
return;
}
console.log(`[MQTT Boss 消息] 收到设备 ${sn_code} 的新消息payload 长度:`, typeof payload === 'string' ? payload.length : 'object');
// TODO: 这里可以根据业务需要:
// - 写入 chat_message / chat_reply_intent_log 等表
// - 触发 AI 自动回复流程
// 当前先只是打印日志,预留扩展点。
} catch (error) {
console.error('[MQTT Boss 消息] 处理 Boss 消息失败:', error);
}
}
/** /**
* 处理响应消息 * 处理响应消息
* @param {object|string} message - 响应消息对象或JSON字符串 * @param {object|string} message - 响应消息对象或JSON字符串

View File

@@ -130,6 +130,17 @@ class ScheduleManager {
console.error('[调度管理器] 处理响应消息失败:', error); console.error('[调度管理器] 处理响应消息失败:', error);
} }
}); });
// 订阅 Boss 聊天消息主题,将 boss-automation-nodejs 转发过来的新消息交给 mqttDispatcher 处理
this.mqttClient.subscribe("boss/message", async (topic, message) => {
try {
if (this.mqttDispatcher && typeof this.mqttDispatcher.handleBossMessage === 'function') {
await this.mqttDispatcher.handleBossMessage(message);
}
} catch (error) {
console.error('[调度管理器] 处理 Boss 消息失败:', error);
}
});
} }