mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-24 08:03:53 +08:00
feature:OTA能力完善
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
import agent from './module/agent.js'
|
||||
import device from './module/device.js'
|
||||
import user from './module/user.js'
|
||||
import ota from './module/ota.js'
|
||||
|
||||
/**
|
||||
* 接口地址
|
||||
@@ -11,7 +12,7 @@ import user from './module/user.js'
|
||||
*/
|
||||
// const DEV_API_SERVICE = 'https://m1.apifoxmock.com/m1/5931378-5618560-default'
|
||||
// 8002开发完成完成后使用这个
|
||||
const DEV_API_SERVICE = '/xiaozhi-esp32-api'
|
||||
const DEV_API_SERVICE = '/xiaozhi-esp32-api/api/v1'
|
||||
|
||||
/**
|
||||
* 根据开发环境返回接口url
|
||||
@@ -27,5 +28,6 @@ export default {
|
||||
getServiceUrl,
|
||||
user,
|
||||
agent,
|
||||
device
|
||||
device,
|
||||
ota
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import {getServiceUrl} from '../api'
|
||||
export default {
|
||||
//智能体列表
|
||||
getAgentList(callback) {
|
||||
RequestService.sendRequest().url(`${getServiceUrl()}/api/v1/user/agent`)
|
||||
RequestService.sendRequest().url(`${getServiceUrl()}/user/agent`)
|
||||
.method('GET')
|
||||
.success((res) => {
|
||||
RequestService.clearRequestTime()
|
||||
@@ -18,7 +18,7 @@ export default {
|
||||
//添加智能体
|
||||
addAgent(agentName, callback) {
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/api/v1/user/agent`)
|
||||
.url(`${getServiceUrl()}/user/agent`)
|
||||
.method('POST')
|
||||
.data({agentName})
|
||||
.success((res) => {
|
||||
@@ -30,9 +30,9 @@ export default {
|
||||
}).send();
|
||||
},
|
||||
//获取智能体配置
|
||||
getAgentConfig(agent_id, callback) {
|
||||
getAgentConfig(agentId, callback) {
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/api/v1/user/agent/${agent_id}`)
|
||||
.url(`${getServiceUrl()}/user/agent/${agentId}`)
|
||||
.method('GET')
|
||||
.success((res) => {
|
||||
RequestService.clearRequestTime();
|
||||
@@ -40,15 +40,15 @@ export default {
|
||||
})
|
||||
.fail((err) => {
|
||||
console.error('获取智能体配置失败:', err);
|
||||
RequestService.reAjaxFun(() => {
|
||||
this.getAgentConfig(agent_id, callback);
|
||||
});
|
||||
// RequestService.reAjaxFun(() => {
|
||||
// this.getAgentConfig(agent_id, callback);
|
||||
// });
|
||||
}).send();
|
||||
},
|
||||
//配置智能体
|
||||
saveAgentConfig(agent_id, configData, callback) {
|
||||
saveAgentConfig(agentId, configData, callback) {
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/api/v1/user/agent/${agent_id}`)
|
||||
.url(`${getServiceUrl()}/user/agent/${agentId}`)
|
||||
.method('PUT')
|
||||
.data(configData)
|
||||
.success((res) => {
|
||||
@@ -57,15 +57,15 @@ export default {
|
||||
})
|
||||
.fail((err) => {
|
||||
console.error('保存智能体配置失败:', err);
|
||||
RequestService.reAjaxFun(() => {
|
||||
this.saveAgentConfig(device_id, configData, callback);
|
||||
});
|
||||
// RequestService.reAjaxFun(() => {
|
||||
// this.saveAgentConfig(device_id, configData, callback);
|
||||
// });
|
||||
}).send();
|
||||
},
|
||||
//删除智能体
|
||||
delAgent(agent_id, callback) {
|
||||
delAgent(agentId, callback) {
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/api/v1/user/agent/${agent_id}`)
|
||||
.url(`${getServiceUrl()}/user/agent/${agentId}`)
|
||||
.method('DELETE')
|
||||
.success((res) => {
|
||||
RequestService.clearRequestTime();
|
||||
@@ -73,9 +73,9 @@ export default {
|
||||
})
|
||||
.fail((err) => {
|
||||
console.error('删除智能体失败:', err);
|
||||
RequestService.reAjaxFun(() => {
|
||||
this.deleteAgent(agent_id, callback);
|
||||
});
|
||||
// RequestService.reAjaxFun(() => {
|
||||
// this.deleteAgent(agent_id, callback);
|
||||
// });
|
||||
}).send();
|
||||
},
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import {getServiceUrl} from '../api'
|
||||
export default {
|
||||
//设备列表
|
||||
getDeviceList(agent_id, page, callback) {
|
||||
RequestService.sendRequest().url(`${getServiceUrl()}/api/v1/user/agent/device/bind/${agent_id}`)
|
||||
RequestService.sendRequest().url(`${getServiceUrl()}/user/agent/device/bind/${agent_id}`)
|
||||
.method('GET')
|
||||
.data(page)
|
||||
.success((res) => {
|
||||
@@ -19,7 +19,7 @@ export default {
|
||||
//绑定设备
|
||||
bindDevice(agentId, deviceCode, callback) {
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/api/v1/user/agent/device/bind/${agentId}`)
|
||||
.url(`${getServiceUrl()}/user/agent/device/bind/${agentId}`)
|
||||
.method('POST')
|
||||
.data({deviceCode})
|
||||
.success((res) => {
|
||||
@@ -28,24 +28,53 @@ export default {
|
||||
})
|
||||
.fail((err) => {
|
||||
console.error('绑定设备失败:', err);
|
||||
RequestService.reAjaxFun(() => {
|
||||
this.addDevice(agentId, deviceCode, callback);
|
||||
});
|
||||
// RequestService.reAjaxFun(() => {
|
||||
// this.addDevice(agentId, deviceCode, callback);
|
||||
// });
|
||||
}).send();
|
||||
},
|
||||
// 解绑设备
|
||||
unbindDevice(deviceId, callback) {
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/api/v1/user/agent/device/unbind/${deviceId}`)
|
||||
.url(`${getServiceUrl()}/user/agent/device/unbind/${deviceId}`)
|
||||
.method('PUT')
|
||||
.success((res) => {
|
||||
RequestService.clearRequestTime();
|
||||
callback(res);
|
||||
})
|
||||
.fail(() => {
|
||||
RequestService.reAjaxFun(() => {
|
||||
this.unbindDevice(deviceId, callback);
|
||||
});
|
||||
.fail((err) => {
|
||||
console.error('解绑设备失败:', err);
|
||||
// RequestService.reAjaxFun(() => {
|
||||
// this.unbindDevice(deviceId, callback);
|
||||
// });
|
||||
}).send()
|
||||
},
|
||||
// 切换设备OTA升级状态
|
||||
toggleAutoUpdate(deviceId, autoUpdate, callback) {
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/user/agent/device/autoUpdate/${deviceId}`)
|
||||
.method('POST')
|
||||
.data({autoUpdate})
|
||||
.success((res) => {
|
||||
RequestService.clearRequestTime();
|
||||
callback(res);
|
||||
})
|
||||
.fail((err) => {
|
||||
console.error('切换设备OTA升级状态失败:', err);
|
||||
}).send()
|
||||
},
|
||||
// 设置设备别名
|
||||
setAlias(deviceId, alias, callback) {
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/user/agent/device/alias/${deviceId}`)
|
||||
.method('POST')
|
||||
.data({alias})
|
||||
.success((res) => {
|
||||
RequestService.clearRequestTime();
|
||||
callback(res);
|
||||
})
|
||||
.fail((err) => {
|
||||
console.error('设置设备别名失败:', err);
|
||||
}).send()
|
||||
},
|
||||
|
||||
|
||||
Executable
+67
@@ -0,0 +1,67 @@
|
||||
import RequestService from '../httpRequest'
|
||||
import {getServiceUrl} from '../api'
|
||||
|
||||
|
||||
export default {
|
||||
//设备OTA列表
|
||||
getOtaList(page, callback) {
|
||||
RequestService.sendRequest().url(`${getServiceUrl()}/ota/sys/getOtalist`)
|
||||
.method('GET')
|
||||
.data(page)
|
||||
.success((res) => {
|
||||
RequestService.clearRequestTime()
|
||||
callback(res)
|
||||
})
|
||||
.fail((err) => {
|
||||
console.error('获取设备OTA列表失败:', err);
|
||||
}).send()
|
||||
},
|
||||
//添加设备OTA
|
||||
saveOta(ota, callback) {
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/ota/sys/save`)
|
||||
.method('POST')
|
||||
.data(ota)
|
||||
.success((res) => {
|
||||
RequestService.clearRequestTime();
|
||||
callback(res);
|
||||
})
|
||||
.fail((err) => {
|
||||
console.error('添加设备OTA失败:', err);
|
||||
}).send();
|
||||
},
|
||||
//配置设备OTA
|
||||
updateOta(ota, callback) {
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/ota/sys/update`)
|
||||
.method('POST')
|
||||
.data(ota)
|
||||
.success((res) => {
|
||||
RequestService.clearRequestTime();
|
||||
callback(res);
|
||||
})
|
||||
.fail((err) => {
|
||||
console.error('保存设备OTA配置失败:', err);
|
||||
// RequestService.reAjaxFun(() => {
|
||||
// this.saveAgentConfig(device_id, configData, callback);
|
||||
// });
|
||||
}).send();
|
||||
},
|
||||
//切换设备OTA可用状态失败
|
||||
toggleEnabled(ota, callback) {
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/ota/sys/toggleEnabled`)
|
||||
.method('POST')
|
||||
.data(ota)
|
||||
.success((res) => {
|
||||
RequestService.clearRequestTime();
|
||||
callback(res);
|
||||
})
|
||||
.fail((err) => {
|
||||
console.error('切换设备OTA可用状态失败:', err);
|
||||
// RequestService.reAjaxFun(() => {
|
||||
// this.deleteAgent(agent_id, callback);
|
||||
// });
|
||||
}).send();
|
||||
},
|
||||
}
|
||||
@@ -5,53 +5,24 @@ import {getServiceUrl} from '../api'
|
||||
export default {
|
||||
// 登录
|
||||
login(loginForm, callback) {
|
||||
RequestService.sendRequest().url(`${getServiceUrl()}/api/v1/user/login`)
|
||||
RequestService.sendRequest().url(`${getServiceUrl()}/user/login`)
|
||||
.method('POST')
|
||||
.data(loginForm)
|
||||
.success((res) => {
|
||||
RequestService.clearRequestTime()
|
||||
callback(res)
|
||||
})
|
||||
.fail(() => {
|
||||
RequestService.reAjaxFun(() => {
|
||||
this.login(loginForm, callback)
|
||||
})
|
||||
.fail((err) => {
|
||||
console.error('登录失败:', err);
|
||||
// RequestService.reAjaxFun(() => {
|
||||
// this.login(loginForm, callback)
|
||||
// })
|
||||
}).send()
|
||||
},
|
||||
// 获取设备信息
|
||||
getHomeList(callback) {
|
||||
RequestService.sendRequest().url(`${getServiceUrl()}/api/v1/user/device/bind`)
|
||||
.method('GET')
|
||||
.success((res) => {
|
||||
RequestService.clearRequestTime()
|
||||
callback(res)
|
||||
})
|
||||
.fail(() => {
|
||||
RequestService.reAjaxFun(() => {
|
||||
this.getUserInfo()
|
||||
})
|
||||
}).send()
|
||||
},
|
||||
// 解绑设备
|
||||
unbindDevice(device_id, callback) {
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/api/v1/user/device/unbind/${device_id}`)
|
||||
.method('PUT')
|
||||
.success((res) => {
|
||||
RequestService.clearRequestTime();
|
||||
callback(res);
|
||||
})
|
||||
.fail(() => {
|
||||
RequestService.reAjaxFun(() => {
|
||||
this.unbindDevice(device_id, callback);
|
||||
});
|
||||
}).send()
|
||||
},
|
||||
// 获取验证码
|
||||
}, // 获取验证码
|
||||
getCaptcha(uuid, callback) {
|
||||
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/api/v1/user/captcha?uuid=${uuid}`)
|
||||
.url(`${getServiceUrl()}/user/captcha?uuid=${uuid}`)
|
||||
.method('GET')
|
||||
.type('blob')
|
||||
.header({
|
||||
@@ -64,104 +35,57 @@ export default {
|
||||
callback(res);
|
||||
})
|
||||
.fail((err) => { // 添加错误参数
|
||||
|
||||
console.error('获取验证码失败:', err);
|
||||
}).send()
|
||||
},
|
||||
// 注册账号
|
||||
register(registerForm, callback) {
|
||||
RequestService.sendRequest().url(`${getServiceUrl()}/api/v1/user/register`).method('POST')
|
||||
RequestService.sendRequest().url(`${getServiceUrl()}/user/register`).method('POST')
|
||||
.data(registerForm)
|
||||
.success((res) => {
|
||||
RequestService.clearRequestTime()
|
||||
callback(res)
|
||||
})
|
||||
.fail(() => {
|
||||
.fail((err) => {
|
||||
console.error('注册账号失败:', err);
|
||||
}).send()
|
||||
},
|
||||
|
||||
// 保存设备配置
|
||||
saveDeviceConfig(device_id, configData, callback) {
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/api/v1/user/configDevice/${device_id}`)
|
||||
.method('PUT')
|
||||
.data(configData)
|
||||
.success((res) => {
|
||||
RequestService.clearRequestTime();
|
||||
callback(res);
|
||||
})
|
||||
.fail((err) => {
|
||||
console.error('保存配置失败:', err);
|
||||
RequestService.reAjaxFun(() => {
|
||||
this.saveDeviceConfig(device_id, configData, callback);
|
||||
});
|
||||
}).send();
|
||||
},
|
||||
// 获取设备配置
|
||||
getDeviceConfig(device_id, callback) {
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/api/v1/user/configDevice/${device_id}`)
|
||||
.method('GET')
|
||||
.success((res) => {
|
||||
RequestService.clearRequestTime();
|
||||
callback(res);
|
||||
})
|
||||
.fail((err) => {
|
||||
console.error('获取配置失败:', err);
|
||||
RequestService.reAjaxFun(() => {
|
||||
this.getDeviceConfig(device_id, callback);
|
||||
});
|
||||
}).send();
|
||||
},
|
||||
// 获取所有模型名称
|
||||
getModelNames(callback) {
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/api/v1/models/names`)
|
||||
.url(`${getServiceUrl()}/models/names`)
|
||||
.method('GET')
|
||||
.success((res) => {
|
||||
RequestService.clearRequestTime();
|
||||
callback(res);
|
||||
})
|
||||
.fail(() => {
|
||||
RequestService.reAjaxFun(() => {
|
||||
this.getModelNames(callback);
|
||||
});
|
||||
// RequestService.reAjaxFun(() => {
|
||||
// this.getModelNames(callback);
|
||||
// });
|
||||
}).send();
|
||||
},
|
||||
|
||||
// 获取模型音色
|
||||
getModelVoices(modelName, callback) {
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/api/v1/models/${modelName}/voices`)
|
||||
.url(`${getServiceUrl()}/models/${modelName}/voices`)
|
||||
.method('GET')
|
||||
.success((res) => {
|
||||
RequestService.clearRequestTime();
|
||||
callback(res);
|
||||
})
|
||||
.fail(() => {
|
||||
RequestService.reAjaxFun(() => {
|
||||
this.getModelVoices(modelName, callback);
|
||||
});
|
||||
// RequestService.reAjaxFun(() => {
|
||||
// this.getModelVoices(modelName, callback);
|
||||
// });
|
||||
}).send();
|
||||
},
|
||||
// 获取智能体列表
|
||||
getAgentList(callback) {
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/api/v1/user/agent`)
|
||||
.method('GET')
|
||||
.success((res) => {
|
||||
RequestService.clearRequestTime();
|
||||
callback(res);
|
||||
})
|
||||
.fail(() => {
|
||||
RequestService.reAjaxFun(() => {
|
||||
this.getAgentList(callback);
|
||||
});
|
||||
}).send();
|
||||
},
|
||||
|
||||
// 获取用户信息
|
||||
getUserInfo(callback) {
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/api/v1/user/info`)
|
||||
.url(`${getServiceUrl()}/user/info`)
|
||||
.method('GET')
|
||||
.success((res) => {
|
||||
RequestService.clearRequestTime()
|
||||
@@ -169,26 +93,9 @@ export default {
|
||||
})
|
||||
.fail((err) => {
|
||||
console.error('接口请求失败:', err)
|
||||
RequestService.reAjaxFun(() => {
|
||||
this.getUserInfo(callback)
|
||||
})
|
||||
// RequestService.reAjaxFun(() => {
|
||||
// this.getUserInfo(callback)
|
||||
// })
|
||||
}).send()
|
||||
},
|
||||
// 添加智能体
|
||||
addAgent(agentName, callback) {
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/api/v1/user/agent`)
|
||||
.method('POST')
|
||||
.data({ name: agentName })
|
||||
.success((res) => {
|
||||
RequestService.clearRequestTime();
|
||||
callback(res);
|
||||
})
|
||||
.fail(() => {
|
||||
RequestService.reAjaxFun(() => {
|
||||
this.addAgent(agentName, callback);
|
||||
});
|
||||
}).send();
|
||||
},
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user