Files
komari/database/models/models.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

90 lines
3.1 KiB
Go

package models
import (
"time"
)
// Client represents a registered client device
type Client struct {
UUID string `gorm:"type:uuid;primaryKey"`
Token string `gorm:"type:varchar(255);unique;not null"`
ClientName string `gorm:"type:varchar(100);not null"`
CreatedAt time.Time
UpdatedAt time.Time
}
// User represents an authenticated user
type User struct {
UUID string `gorm:"type:uuid;primaryKey"`
Username string `gorm:"type:varchar(50);unique;not null"`
Passwd string `gorm:"type:varchar(255);not null"` // Hashed password
SSOType string `gorm:"type:varchar(20)"` // e.g., "github", "google"
SSOID string `gorm:"type:varchar(100)"` // OAuth provider's user ID
CreatedAt time.Time
UpdatedAt time.Time
}
// Session manages user sessions
type Session struct {
UUID string `gorm:"type:uuid;primaryKey"`
UserUUID string `gorm:"type:uuid;foreignKey:UserUUID;references:UUID;constraint:OnDelete:CASCADE"`
Session string `gorm:"type:varchar(255);unique;not null"`
Expires time.Time `gorm:"not null"`
CreatedAt time.Time
}
// History logs client metrics over time
type History struct {
ID uint64 `gorm:"primaryKey;autoIncrement"`
ClientUUID string `gorm:"type:uuid;index;foreignKey:ClientUUID;references:UUID;constraint:OnDelete:CASCADE"`
Time time.Time `gorm:"index;default:CURRENT_TIMESTAMP"`
CPU float32 `gorm:"type:decimal(5,2)"` // e.g., 75.50%
GPU float32 `gorm:"type:decimal(5,2)"`
RAM int64 `gorm:"type:bigint"`
RAMTotal int64 `gorm:"type:bigint"`
SWAP int64 `gorm:"type:bigint"`
SWAPTotal int64 `gorm:"type:bigint"`
LOAD float32 `gorm:"type:decimal(5,2)"`
TEMP float32 `gorm:"type:decimal(5,2)"`
DISK int64 `gorm:"type:bigint"`
DISKTotal int64 `gorm:"type:bigint"`
NETIn int64 `gorm:"type:bigint"`
NETOut int64 `gorm:"type:bigint"`
NETTotalUp int64 `gorm:"type:bigint"`
NETTotalDown int64 `gorm:"type:bigint"`
PROCESS int
Connections int
ConnectionsUDP int
}
// Config stores site-wide settings
type Config struct {
ID uint `gorm:"primaryKey;autoIncrement"`
Sitename string `gorm:"type:varchar(100);not null"`
Description string `gorm:"type:text"`
CreatedAt time.Time
UpdatedAt time.Time
}
// OAuthConfig stores OAuth provider configurations
type OAuthConfig struct {
ID uint `gorm:"primaryKey;autoIncrement"`
Provider string `gorm:"type:varchar(20);not null;unique"` // e.g., "github"
ClientID string `gorm:"type:varchar(255);not null"`
ClientSecret string `gorm:"type:varchar(255);not null"`
RedirectURI string `gorm:"type:varchar(255);not null"`
Enabled bool `gorm:"default:false"`
CreatedAt time.Time
UpdatedAt time.Time
}
// Custom stores custom configurations
type Custom struct {
ID uint `gorm:"primaryKey;autoIncrement"`
CustomCSS string `gorm:"type:text"`
CustomJS string `gorm:"type:text"`
SiteName string `gorm:"type:varchar(100);not null"`
CreatedAt time.Time
UpdatedAt time.Time
}