| | package model
|
| |
|
| | import (
|
| | "time"
|
| | )
|
| |
|
| |
|
| | type MorphCookie struct {
|
| | ID uint `gorm:"primaryKey" json:"id"`
|
| | UserID uint `gorm:"not null;index" json:"user_id"`
|
| | User User `gorm:"foreignKey:UserID;constraint:OnDelete:CASCADE" json:"-"`
|
| | Name string `gorm:"size:100;not null" json:"name"`
|
| | APIKey string `gorm:"column:api_key;type:text;not null" json:"api_key"`
|
| | SessionKey string `gorm:"column:session_key;type:text" json:"session_key"`
|
| | IsValid bool `gorm:"default:true;index" json:"is_valid"`
|
| | LastValidated *time.Time `gorm:"column:last_validated" json:"last_validated"`
|
| | LastUsed *time.Time `gorm:"column:last_used" json:"last_used"`
|
| | Priority int `gorm:"default:0;index" json:"priority"`
|
| | UsageCount int64 `gorm:"default:0" json:"usage_count"`
|
| | ErrorCount int `gorm:"default:0" json:"error_count"`
|
| | CreatedAt time.Time `json:"created_at"`
|
| | UpdatedAt time.Time `json:"updated_at"`
|
| | }
|
| |
|
| |
|
| | type CookieStats struct {
|
| | TotalCount int64 `json:"total_count"`
|
| | ValidCount int64 `json:"valid_count"`
|
| | InvalidCount int64 `json:"invalid_count"`
|
| | TotalUsage int64 `json:"total_usage"`
|
| | }
|
| |
|
| |
|
| | func (MorphCookie) TableName() string {
|
| | return "morph_cookies"
|
| | }
|
| |
|
| |
|
| | func (c *MorphCookie) MarkUsed() {
|
| | now := time.Now()
|
| | c.LastUsed = &now
|
| | c.UsageCount++
|
| | c.ErrorCount = 0
|
| | }
|
| |
|
| |
|
| | func (c *MorphCookie) MarkError() {
|
| | c.ErrorCount++
|
| | }
|
| |
|
| |
|
| | func (c *MorphCookie) MarkInvalid() {
|
| | c.IsValid = false
|
| | now := time.Now()
|
| | c.LastValidated = &now
|
| | }
|
| |
|
| |
|
| | func (c *MorphCookie) MarkValid() {
|
| | c.IsValid = true
|
| | c.ErrorCount = 0
|
| | now := time.Now()
|
| | c.LastValidated = &now
|
| | } |