mirror of
https://github.com/komari-monitor/komari.git
synced 2026-11-24 09:05:49 +00:00
- 在 `go.mod` 中引入 `komari_common` 模块并进行路径替换。 - 更新 `GetMe` 函数以使用用户 UUID 获取用户名。 - 在 `AddClient` 和 `EditClient` 函数中重构客户端配置的处理逻辑,使用 `komari_common.ClientConfig`。 - 优化报告上传和获取功能,确保数据处理逻辑一致性。 - 增强错误处理,确保在数据库操作中更好地捕获和处理异常。
28 lines
523 B
Go
28 lines
523 B
Go
package api
|
|
|
|
import (
|
|
"github.com/akizon77/komari/database/accounts"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func GetMe(c *gin.Context) {
|
|
session, err := c.Cookie("session_token")
|
|
if err != nil {
|
|
c.JSON(200, gin.H{"username": "Guest"})
|
|
return
|
|
}
|
|
uuid, err := accounts.GetSession(session)
|
|
if err != nil {
|
|
c.JSON(200, gin.H{"username": "Guest"})
|
|
return
|
|
}
|
|
user, err := accounts.GetUserByUUID(uuid)
|
|
if err != nil {
|
|
c.JSON(200, gin.H{"username": "Guest"})
|
|
return
|
|
}
|
|
c.JSON(200, gin.H{"username": user.Username})
|
|
|
|
}
|