mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-08-04 15:17:27 +00:00
refactor(api-token): share timestamp threshold
This commit is contained in:
parent
e56e317f1c
commit
98f4c12bbc
3 changed files with 6 additions and 8 deletions
|
|
@ -1092,9 +1092,8 @@ func InitDB(dbPath string) error {
|
|||
// autoCreateTime:milli. The threshold separates modern Unix milliseconds from
|
||||
// Unix seconds and makes this safe to run on every startup.
|
||||
func normalizeApiTokenCreatedAtSeconds() error {
|
||||
const unixMillisecondsThreshold int64 = 100_000_000_000
|
||||
return db.Model(&model.ApiToken{}).
|
||||
Where("created_at >= ?", unixMillisecondsThreshold).
|
||||
Where("created_at >= ?", model.ApiTokenUnixMillisecondsThreshold).
|
||||
UpdateColumn("created_at", gorm.Expr("created_at / ?", 1000)).Error
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -149,6 +149,10 @@ type HistoryOfSeeders struct {
|
|||
SeederName string `json:"seederName"`
|
||||
}
|
||||
|
||||
// ApiTokenUnixMillisecondsThreshold separates legacy millisecond timestamps
|
||||
// from the seconds-based API token timestamp contract.
|
||||
const ApiTokenUnixMillisecondsThreshold int64 = 100_000_000_000
|
||||
|
||||
type ApiToken struct {
|
||||
Id int `json:"id" gorm:"primaryKey;autoIncrement"`
|
||||
Name string `json:"name" gorm:"uniqueIndex;not null"`
|
||||
|
|
|
|||
|
|
@ -16,11 +16,6 @@ type ApiTokenService struct{}
|
|||
|
||||
const apiTokenLength = 48
|
||||
|
||||
// API token timestamps predate the model's temporary switch to milliseconds.
|
||||
// Keep the API contract in Unix seconds while accepting rows written in either
|
||||
// unit during that period.
|
||||
const unixMillisecondsThreshold int64 = 100_000_000_000
|
||||
|
||||
type ApiTokenView struct {
|
||||
Id int `json:"id" example:"2"`
|
||||
Name string `json:"name" example:"central-panel-a"`
|
||||
|
|
@ -30,7 +25,7 @@ type ApiTokenView struct {
|
|||
}
|
||||
|
||||
func apiTokenCreatedAtSeconds(createdAt int64) int64 {
|
||||
if createdAt >= unixMillisecondsThreshold {
|
||||
if createdAt >= model.ApiTokenUnixMillisecondsThreshold {
|
||||
return createdAt / 1000
|
||||
}
|
||||
return createdAt
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue