mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-08-12 22:31:00 +00:00
fix(settings): normalize API token timestamps (#5599)
* fix(settings): normalize API token timestamps * refactor(api-token): share timestamp threshold --------- Co-authored-by: Tomilla <5007859+Tomilla@users.noreply.github.com>
This commit is contained in:
@@ -94,6 +94,9 @@ func initModels() error {
|
||||
if err := migrateHostVerifyPeerCertByNameColumn(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := normalizeApiTokenCreatedAtSeconds(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := dropLegacyForeignKeys(); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1085,6 +1088,15 @@ func InitDB(dbPath string) error {
|
||||
return runSeeders(isUsersEmpty)
|
||||
}
|
||||
|
||||
// normalizeApiTokenCreatedAtSeconds repairs rows written while ApiToken used
|
||||
// autoCreateTime:milli. The threshold separates modern Unix milliseconds from
|
||||
// Unix seconds and makes this safe to run on every startup.
|
||||
func normalizeApiTokenCreatedAtSeconds() error {
|
||||
return db.Model(&model.ApiToken{}).
|
||||
Where("created_at >= ?", model.ApiTokenUnixMillisecondsThreshold).
|
||||
UpdateColumn("created_at", gorm.Expr("created_at / ?", 1000)).Error
|
||||
}
|
||||
|
||||
// sqliteSynchronous returns the SQLite synchronous mode, defaulting to FULL.
|
||||
// Whitelisted because the value is interpolated directly into a PRAGMA string.
|
||||
func sqliteSynchronous() string {
|
||||
|
||||
Reference in New Issue
Block a user