fix: IoT设备控制仅限管理员
This commit is contained in:
@@ -5,6 +5,8 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
plgManager "git.yeij.top/AskaEth/Cyrene-Plugins/manager"
|
||||
)
|
||||
|
||||
// IoTControlTool IoT 设备控制工具
|
||||
@@ -123,6 +125,15 @@ func normalizeAction(arguments map[string]interface{}) string {
|
||||
|
||||
// Execute 执行设备控制
|
||||
func (t *IoTControlTool) Execute(ctx context.Context, arguments map[string]interface{}) (*ToolResult, error) {
|
||||
// 仅管理员可以控制设备
|
||||
isAdmin, _ := ctx.Value(plgManager.CtxKeyIsAdmin).(bool)
|
||||
if !isAdmin {
|
||||
return &ToolResult{
|
||||
ToolName: "iot_control",
|
||||
Success: false,
|
||||
Error: "只有管理员才能控制设备哦~",
|
||||
}, nil
|
||||
}
|
||||
if t.iotClient == nil {
|
||||
return &ToolResult{
|
||||
ToolName: "iot_control",
|
||||
|
||||
Reference in New Issue
Block a user