mirror of
https://github.com/komari-monitor/komari.git
synced 2026-11-22 16:00:46 +00:00
- 在 `go.mod` 中引入 `komari_common` 模块并进行路径替换。 - 更新 `GetMe` 函数以使用用户 UUID 获取用户名。 - 在 `AddClient` 和 `EditClient` 函数中重构客户端配置的处理逻辑,使用 `komari_common.ClientConfig`。 - 优化报告上传和获取功能,确保数据处理逻辑一致性。 - 增强错误处理,确保在数据库操作中更好地捕获和处理异常。
37 lines
873 B
Go
37 lines
873 B
Go
package client
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/akizon77/komari/database/clients"
|
|
"gorm.io/gorm"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func GetRemoteConfig(c *gin.Context) {
|
|
token := c.Query("token")
|
|
|
|
clientUUID, err := clients.GetClientUUIDByToken(token)
|
|
if err == gorm.ErrRecordNotFound {
|
|
c.JSON(http.StatusNotFound, gin.H{"status": "error", "error": "No data found"})
|
|
return
|
|
} else if err != nil {
|
|
c.JSON(http.StatusUnauthorized, gin.H{"error": fmt.Sprintf("%v", err)})
|
|
return
|
|
}
|
|
config, err := clients.GetClientConfig(clientUUID)
|
|
|
|
if err == gorm.ErrRecordNotFound {
|
|
c.JSON(http.StatusNotFound, gin.H{"status": "error", "error": "No data found"})
|
|
return
|
|
} else if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"status": "error", "error": fmt.Errorf("error querying client: %v", err)})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, config)
|
|
|
|
}
|