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:
Tomi lla
2026-06-27 16:30:58 +08:00
committed by GitHub
parent 6964d84742
commit 7a2179535a
7 changed files with 141 additions and 4 deletions
+8 -1
View File
@@ -24,6 +24,13 @@ type ApiTokenView struct {
CreatedAt int64 `json:"createdAt" example:"1736000000"`
}
func apiTokenCreatedAtSeconds(createdAt int64) int64 {
if createdAt >= model.ApiTokenUnixMillisecondsThreshold {
return createdAt / 1000
}
return createdAt
}
// toView builds the metadata view returned by List. It never carries the
// token value: only a SHA-256 hash is stored, and the plaintext is shown
// exactly once at creation time.
@@ -32,7 +39,7 @@ func toView(t *model.ApiToken) *ApiTokenView {
Id: t.Id,
Name: t.Name,
Enabled: t.Enabled,
CreatedAt: t.CreatedAt,
CreatedAt: apiTokenCreatedAtSeconds(t.CreatedAt),
}
}