Files
komari/api/client/getRemoteConfig.go
T
Akizon77 c3172059ef 添加对 komari_common 模块的支持,重构客户端管理功能
- 在 `go.mod` 中引入 `komari_common` 模块并进行路径替换。
- 更新 `GetMe` 函数以使用用户 UUID 获取用户名。
- 在 `AddClient` 和 `EditClient` 函数中重构客户端配置的处理逻辑,使用 `komari_common.ClientConfig`。
- 优化报告上传和获取功能,确保数据处理逻辑一致性。
- 增强错误处理,确保在数据库操作中更好地捕获和处理异常。
2025-04-18 00:41:00 +08:00

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