132 lines
2.5 KiB
Go
132 lines
2.5 KiB
Go
package models
|
|
|
|
import (
|
|
"encoding/json"
|
|
"time"
|
|
)
|
|
|
|
type User struct {
|
|
ID int
|
|
Username string
|
|
PasswordHash string
|
|
Role string
|
|
CreatedAt time.Time
|
|
}
|
|
|
|
type ShareLink struct {
|
|
ID int
|
|
Token string
|
|
ServerID *int
|
|
ExpiresAt *time.Time
|
|
MaxUses int
|
|
ValidityDays *int
|
|
UseCount int
|
|
CreatedAt time.Time
|
|
CleanedAt *time.Time
|
|
TrafficQuotaGB *float64
|
|
TrafficUsedGB float64
|
|
SubscriptionUntil *time.Time
|
|
AllowedServerIDs json.RawMessage
|
|
}
|
|
|
|
type ShareCreation struct {
|
|
ID int64
|
|
ShareLinkID int
|
|
ServerID int
|
|
Protocol string
|
|
ClientID string
|
|
ConnectionName string
|
|
ResponseJSON *string
|
|
CreatedAt time.Time
|
|
DeletedAt *time.Time
|
|
}
|
|
|
|
type RenewalCode struct {
|
|
ID int
|
|
Code string
|
|
AddDays int
|
|
MaxUses int
|
|
UseCount int
|
|
ShareLinkID *int
|
|
CodeExpiresAt *time.Time
|
|
Note *string
|
|
CodeTarget string
|
|
CreatedAt time.Time
|
|
}
|
|
|
|
type Member struct {
|
|
ID int
|
|
Username string
|
|
Email *string
|
|
PasswordHash string
|
|
CreatedAt time.Time
|
|
LastLoginAt *time.Time
|
|
}
|
|
|
|
type MemberSubscription struct {
|
|
MemberID int
|
|
ExpiresAt *time.Time
|
|
ValidityDays *int
|
|
MaxConfigs int
|
|
ConfigCount int
|
|
CleanedAt *time.Time
|
|
}
|
|
|
|
type ServerInfo struct {
|
|
ID int `json:"id"`
|
|
Label string `json:"label"`
|
|
Name string `json:"name,omitempty"`
|
|
Protocols []string `json:"protocols"`
|
|
Disabled bool `json:"disabled"`
|
|
Flag string `json:"flag,omitempty"`
|
|
FlagURL string `json:"flag_url,omitempty"`
|
|
Speed string `json:"speed,omitempty"`
|
|
Notice string `json:"notice,omitempty"`
|
|
}
|
|
|
|
func (l ShareLink) IsFloating() bool {
|
|
return l.ValidityDays != nil && *l.ValidityDays > 0 && l.ExpiresAt == nil
|
|
}
|
|
|
|
func (l ShareLink) IsExpired() bool {
|
|
if l.IsFloating() {
|
|
return false
|
|
}
|
|
if l.ExpiresAt == nil {
|
|
return true
|
|
}
|
|
return l.ExpiresAt.Before(time.Now())
|
|
}
|
|
|
|
func (l ShareLink) ExpiresLabel() string {
|
|
if l.ExpiresAt != nil {
|
|
return l.ExpiresAt.Format("2006-01-02 15:04:05")
|
|
}
|
|
if l.ValidityDays != nil && *l.ValidityDays > 0 {
|
|
return "с первого конфига — " + itoa(*l.ValidityDays) + " дн."
|
|
}
|
|
return "—"
|
|
}
|
|
|
|
func itoa(n int) string {
|
|
if n == 0 {
|
|
return "0"
|
|
}
|
|
neg := n < 0
|
|
if neg {
|
|
n = -n
|
|
}
|
|
var b [20]byte
|
|
i := len(b)
|
|
for n > 0 {
|
|
i--
|
|
b[i] = byte('0' + n%10)
|
|
n /= 10
|
|
}
|
|
if neg {
|
|
i--
|
|
b[i] = '-'
|
|
}
|
|
return string(b[i:])
|
|
}
|