package models import ( "time" "gorm.io/gorm" ) // User 用户模型 type User struct { ID uint `gorm:"primaryKey" json:"id"` Username string `gorm:"uniqueIndex;size:64;not null" json:"username"` PasswordHash string `gorm:"size:255;not null" json:"-"` TrafficQuota int64 `gorm:"default:0" json:"traffic_quota"` // 流量配额(字节) TrafficUsed int64 `gorm:"default:0" json:"traffic_used"` // 已用流量(字节) ExpireAt *time.Time `json:"expire_at"` NodeGroupID *uint `json:"node_group_id"` NodeGroup *NodeGroup `json:"node_group,omitempty"` Status string `gorm:"type:varchar(20);default:'active'" json:"status"` // active, suspended, expired CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"index" json:"-"` } // NodeGroup 节点组 type NodeGroup struct { ID uint `gorm:"primaryKey" json:"id"` Name string `gorm:"size:64;not null" json:"name"` Description string `gorm:"size:255" json:"description"` Nodes []Node `json:"nodes,omitempty"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` } // Node 节点模型 type Node struct { ID uint `gorm:"primaryKey" json:"id"` NodeID string `gorm:"uniqueIndex;size:64;not null" json:"node_id"` Name string `gorm:"size:64;not null" json:"name"` Host string `gorm:"size:255;not null" json:"host"` Port int `gorm:"default:1080" json:"port"` Region string `gorm:"size:32" json:"region"` Country string `gorm:"size:32" json:"country"` CurrentIP string `gorm:"size:64" json:"current_ip"` IPRegion string `gorm:"size:32" json:"ip_region"` Weight int `gorm:"default:100" json:"weight"` MaxConnections int `gorm:"default:1000" json:"max_connections"` CurrentConnections int `gorm:"default:0" json:"current_connections"` Status string `gorm:"type:varchar(20);default:'offline'" json:"status"` // online, offline, maintenance WARPStatus string `gorm:"type:varchar(20);default:'disconnected'" json:"warp_status"` // connected, disconnected, error UnlockStatuses []UnlockStatus `json:"unlock_statuses,omitempty"` NodeGroupID *uint `json:"node_group_id"` NodeGroup *NodeGroup `json:"node_group,omitempty"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` LastHeartbeat *time.Time `json:"last_heartbeat"` } // UnlockStatus 解锁状态 type UnlockStatus struct { ID uint `gorm:"primaryKey" json:"id"` NodeID uint `gorm:"not null;uniqueIndex:idx_node_service" json:"node_id"` Service string `gorm:"size:32;not null;uniqueIndex:idx_node_service" json:"service"` // gpt, netflix, disney... Unlocked bool `gorm:"default:false" json:"unlocked"` Region string `gorm:"size:32" json:"region"` DetectedAt time.Time `json:"detected_at"` } // IPChangeLog IP 变更日志 type IPChangeLog struct { ID uint `gorm:"primaryKey" json:"id"` NodeID uint `gorm:"not null;index" json:"node_id"` OldIP string `gorm:"size:64" json:"old_ip"` NewIP string `gorm:"size:64" json:"new_ip"` Reason string `gorm:"size:64" json:"reason"` // unlock_failure, usage_threshold, scheduled... Success bool `gorm:"default:true" json:"success"` CreatedAt time.Time `json:"created_at"` } // ConnectionLog 连接日志 type ConnectionLog struct { ID uint `gorm:"primaryKey" json:"id"` UserID uint `gorm:"not null;index" json:"user_id"` NodeID uint `gorm:"not null;index" json:"node_id"` ClientIP string `gorm:"size:64" json:"client_ip"` TargetHost string `gorm:"size:255" json:"target_host"` TargetPort int `json:"target_port"` BytesIn int64 `gorm:"default:0" json:"bytes_in"` BytesOut int64 `gorm:"default:0" json:"bytes_out"` Duration int `gorm:"default:0" json:"duration"` // 毫秒 Status string `gorm:"type:varchar(20)" json:"status"` // success, failed, timeout CreatedAt time.Time `gorm:"index" json:"created_at"` } // IPRefreshRule IP 刷新规则 type IPRefreshRule struct { ID uint `gorm:"primaryKey" json:"id"` NodeGroupID *uint `json:"node_group_id"` // NULL 表示全局规则 TriggerType string `gorm:"type:varchar(32);not null" json:"trigger_type"` // unlock_failure, usage_count, usage_traffic, scheduled, anomaly TriggerValue string `gorm:"type:text" json:"trigger_value"` // JSON 配置 Cooldown int `gorm:"default:300" json:"cooldown"` // 冷却时间(秒) Enabled bool `gorm:"default:true" json:"enabled"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` } // NodeStats 节点统计缓存 type NodeStats struct { NodeID string `json:"node_id"` CPUUsage float64 `json:"cpu_usage"` MemoryUsage float64 `json:"memory_usage"` NetworkInMbps float64 `json:"network_in_mbps"` NetworkOutMbps float64 `json:"network_out_mbps"` Connections int `json:"connections"` LastUpdate time.Time `json:"last_update"` }