1
This commit is contained in:
@@ -75,7 +75,7 @@ module.exports = {
|
||||
* example: '用户不存在或密码错误'
|
||||
*/
|
||||
"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 { verifyPassword, validateDeviceId, maskEmail } = require('../utils/crypto_utils');
|
||||
|
||||
@@ -87,16 +87,6 @@ module.exports = {
|
||||
// 统一邮箱地址为小写
|
||||
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();
|
||||
|
||||
@@ -404,17 +394,17 @@ module.exports = {
|
||||
|
||||
// 获取原有配置
|
||||
const original_deliver_config = user.deliver_config || {};
|
||||
|
||||
|
||||
// 深度合并配置(只覆盖传入的字段,保留原有的其他字段)
|
||||
const deepMerge = (target, source) => {
|
||||
const result = { ...target };
|
||||
Object.keys(source).forEach(key => {
|
||||
const sourceValue = source[key];
|
||||
const targetValue = target[key];
|
||||
|
||||
|
||||
// 如果源值是对象且目标值也是对象,递归合并(排除数组)
|
||||
if (sourceValue && typeof sourceValue === 'object' && !Array.isArray(sourceValue) &&
|
||||
targetValue && typeof targetValue === 'object' && !Array.isArray(targetValue)) {
|
||||
targetValue && typeof targetValue === 'object' && !Array.isArray(targetValue)) {
|
||||
result[key] = deepMerge(targetValue, sourceValue);
|
||||
} else {
|
||||
// 否则直接覆盖
|
||||
@@ -423,7 +413,7 @@ module.exports = {
|
||||
});
|
||||
return result;
|
||||
};
|
||||
|
||||
|
||||
const new_deliver_config = deepMerge(original_deliver_config, deliver_config);
|
||||
|
||||
// 处理 auto_deliver 字段(支持 auto_deliver 和 auto_delivery 两种字段名)
|
||||
@@ -447,7 +437,7 @@ module.exports = {
|
||||
|
||||
console.log('[保存投递配置成功]', {
|
||||
sn_code,
|
||||
deliver_config:new_deliver_config,
|
||||
deliver_config: new_deliver_config,
|
||||
auto_deliver: auto_deliver_value,
|
||||
timestamp: new Date().toISOString()
|
||||
});
|
||||
|
||||
@@ -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字符串
|
||||
|
||||
@@ -130,6 +130,17 @@ class ScheduleManager {
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user