JiXieShi 2024-11-14 23:32:08 +08:00
parent 421cfb8cfa
commit f722153536
7 changed files with 70 additions and 24 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
licserver.exe

View File

@ -275,7 +275,7 @@ paths:
description: 生成数量
remark:
type: string
description: 注说明
description: <EFBFBD><EFBFBD><EFBFBD>注说明
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

View File

@ -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,
},
})
}

View File

@ -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("")

View File

@ -198,19 +198,12 @@ func (s *MonitorService) getDiskInfo(status *model.SystemStatus) error {
}
status.Disk.Partitions = append(status.Disk.Partitions, model.DiskPartition{
Device: partition.Device,
Mountpoint: partition.Mountpoint,
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
}
}
// 获取接口的地址列表

Binary file not shown.

View File

@ -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"