up
This commit is contained in:
@@ -148,13 +148,45 @@ func (h *DeviceHandler) DeleteDevice(c *gin.Context) {
|
||||
|
||||
func (h *DeviceHandler) RegisterDevice(c *gin.Context) {
|
||||
var input service.DeviceRegisterInput
|
||||
if err := c.ShouldBindJSON(&input); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
|
||||
// 检查Content-Type
|
||||
if c.ContentType() != "application/json" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Content-Type must be application/json"})
|
||||
return
|
||||
}
|
||||
|
||||
// 绑定JSON数据
|
||||
if err := c.ShouldBindJSON(&input); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"code": -1,
|
||||
"error": "无效的请求数据: " + err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 验证必填字段
|
||||
if input.UID == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"code": -1,
|
||||
"error": "设备UID不能为空",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if input.DeviceModel == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"code": -1,
|
||||
"error": "设备型号不能为空",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 注册设备
|
||||
if err := h.deviceService.RegisterDevice(&input, c.ClientIP()); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"code": -1,
|
||||
"error": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -166,6 +198,11 @@ func (h *DeviceHandler) RegisterDevice(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 0,
|
||||
"message": fmt.Sprintf("设备注册成功,当前状态:%s", status),
|
||||
"data": gin.H{
|
||||
"uid": input.UID,
|
||||
"device_model": input.DeviceModel,
|
||||
"status": status,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
|
@@ -62,6 +62,7 @@ func SetupRouter(
|
||||
api.POST("/captcha/register", userHandler.SendRegisterCaptcha)
|
||||
api.POST("/captcha/reset-password", userHandler.SendResetPasswordCaptcha)
|
||||
api.POST("/validate-token", tokenHandler.ValidateToken)
|
||||
api.POST("/devices/register", deviceHandler.RegisterDevice)
|
||||
|
||||
// 需要认证的API
|
||||
authorized := api.Group("")
|
||||
|
@@ -198,20 +198,13 @@ func (s *MonitorService) getDiskInfo(status *model.SystemStatus) error {
|
||||
}
|
||||
|
||||
status.Disk.Partitions = append(status.Disk.Partitions, model.DiskPartition{
|
||||
|
||||
Device: partition.Device,
|
||||
|
||||
Device: partition.Device,
|
||||
Mountpoint: partition.Mountpoint,
|
||||
|
||||
Fstype: partition.Fstype,
|
||||
|
||||
Total: usage.Total,
|
||||
|
||||
Used: usage.Used,
|
||||
|
||||
Free: usage.Free,
|
||||
|
||||
UsageRate: usage.UsedPercent,
|
||||
Fstype: partition.Fstype,
|
||||
Total: usage.Total,
|
||||
Used: usage.Used,
|
||||
Free: usage.Free,
|
||||
UsageRate: usage.UsedPercent,
|
||||
})
|
||||
|
||||
}
|
||||
@@ -247,13 +240,9 @@ func (s *MonitorService) getNetworkInfo(status *model.SystemStatus) error {
|
||||
for _, io := range ioCounters {
|
||||
|
||||
if io.Name == iface.Name {
|
||||
|
||||
counter = io
|
||||
|
||||
break
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 获取接口的地址列表
|
||||
|
Reference in New Issue
Block a user