mirror of
https://github.com/navidrome/navidrome.git
synced 2026-11-26 11:59:48 +01:00
refactor(api): reuse existing helpers in API v1 auth
Use gg.V, slice.Map, chi's RequestSize, core/auth's encryption key and ClientIPRateLimiter instead of local copies; share the grant idle expiry constant and a Grant.LastActivity helper; pass last use as a time value.
This commit is contained in:
parent
88a652346b
commit
a41e656706
14 changed files with 70 additions and 71 deletions
|
|
@ -23,6 +23,13 @@ type Grant struct {
|
|||
LastUsedIP string `structs:"last_used_ip" json:"lastUsedIp"`
|
||||
}
|
||||
|
||||
func (g Grant) LastActivity() time.Time {
|
||||
if g.LastUsedAt != nil {
|
||||
return *g.LastUsedAt
|
||||
}
|
||||
return g.CreatedAt
|
||||
}
|
||||
|
||||
type Grants []Grant
|
||||
|
||||
// Scopes is stored as a single space-separated column.
|
||||
|
|
|
|||
24
model/grant_test.go
Normal file
24
model/grant_test.go
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
package model_test
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/navidrome/navidrome/model"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var _ = Describe("Grant", func() {
|
||||
Describe("LastActivity", func() {
|
||||
created := time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC)
|
||||
|
||||
It("is the creation time for a grant never used", func() {
|
||||
Expect(model.Grant{CreatedAt: created}.LastActivity()).To(Equal(created))
|
||||
})
|
||||
|
||||
It("is the last use once the grant was used", func() {
|
||||
used := created.Add(time.Hour)
|
||||
Expect(model.Grant{CreatedAt: created, LastUsedAt: &used}.LastActivity()).To(Equal(used))
|
||||
})
|
||||
})
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue