diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7a671f6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +licserver.exe diff --git a/api-docs.yaml b/api-docs.yaml index db02768..52f9832 100644 --- a/api-docs.yaml +++ b/api-docs.yaml @@ -275,7 +275,7 @@ paths: description: 生成数量 remark: type: string - description: 备注说明 + description: ���注说明 responses: 200: description: 生成成功 @@ -365,6 +365,10 @@ paths: tags: - 设备管理 summary: 设备注册 + consumes: + - application/json + produces: + - application/json parameters: - in: body name: body @@ -374,7 +378,6 @@ paths: required: - uid - device_model - - license_code properties: uid: type: string @@ -384,7 +387,7 @@ paths: description: 设备型号 license_code: type: string - description: 授权码 + description: 授权码(可选) responses: 200: description: 注册成功 @@ -393,13 +396,26 @@ paths: properties: code: type: integer + example: 0 message: type: string + data: + type: object + properties: + uid: + type: string + device_model: + type: string + status: + type: string 400: - description: 注册失败 + description: 请求错误 schema: type: object properties: + code: + type: integer + example: -1 error: type: string diff --git a/internal/api/device.go b/internal/api/device.go index e5dc4fa..03c7bed 100644 --- a/internal/api/device.go +++ b/internal/api/device.go @@ -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, + }, }) } diff --git a/internal/api/router.go b/internal/api/router.go index b1acce8..4edfb4d 100644 --- a/internal/api/router.go +++ b/internal/api/router.go @@ -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("") diff --git a/internal/service/monitor.go b/internal/service/monitor.go index c9d3804..b187fe4 100644 --- a/internal/service/monitor.go +++ b/internal/service/monitor.go @@ -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 - } - } // 获取接口的地址列表 diff --git a/licserver.exe b/licserver.exe deleted file mode 100644 index bcf0a66..0000000 Binary files a/licserver.exe and /dev/null differ diff --git a/start.ps1 b/start.ps1 index eb239de..8dd3f25 100644 --- a/start.ps1 +++ b/start.ps1 @@ -68,6 +68,8 @@ site: # Compile program Write-ColorOutput Green "Compiling program..." try { + go env -w GOPROXY=https://goproxy.cn,direct + go mod tidy go build -o licserver.exe cmd/main.go if ($LASTEXITCODE -ne 0) { throw "Compilation failed"