mirror of
https://github.com/navidrome/navidrome.git
synced 2026-11-19 15:23:36 +00:00
fix(server): don't update last access for internal plugin calls (#6501)
Plugin SubsonicAPI calls are served by the Subsonic router as the user, so UpdateLastAccessMiddleware marked every user a plugin reads for as active. These requests already carry request.WithInternalAuth; skip the update for them. Fixes #6497 Signed-off-by: nenadjokic <nenad.jokic@me.com>
This commit is contained in:
parent
a40f7b870f
commit
2f85c631bf
@ -374,7 +374,9 @@ func UpdateLastAccessMiddleware(ds model.DataStore) func(next http.Handler) http
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
usr, ok := request.UserFrom(ctx)
|
||||
if ok {
|
||||
// Internal calls (e.g. plugins) are not user activity: skip the last access update.
|
||||
_, internal := request.InternalAuthFrom(ctx)
|
||||
if ok && !internal {
|
||||
userAccessLimiter.Do(usr.ID, func() {
|
||||
start := time.Now()
|
||||
ctx, cancel := context.WithTimeout(ctx, time.Second)
|
||||
|
||||
@ -424,6 +424,28 @@ var _ = Describe("middlewares", func() {
|
||||
req = req.WithContext(ctx)
|
||||
callMiddleware(req)
|
||||
|
||||
usr, _ := ds.MockedUser.FindByUsername(ctx, "johndoe")
|
||||
Expect(usr.LastAccessAt).To(Equal(&lastAccessTime))
|
||||
})
|
||||
})
|
||||
Context("when the request is an internal call (e.g. from a plugin)", func() {
|
||||
BeforeEach(func() {
|
||||
req = req.WithContext(request.WithInternalAuth(req.Context(), "johndoe"))
|
||||
})
|
||||
|
||||
It("calls the next handler", func() {
|
||||
called := false
|
||||
middleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
called = true
|
||||
})).ServeHTTP(nil, req)
|
||||
Expect(called).To(BeTrue())
|
||||
})
|
||||
|
||||
It("does not update the last access time", func() {
|
||||
time.Sleep(3 * time.Millisecond)
|
||||
|
||||
callMiddleware(req)
|
||||
|
||||
usr, _ := ds.MockedUser.FindByUsername(ctx, "johndoe")
|
||||
Expect(usr.LastAccessAt).To(Equal(&lastAccessTime))
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user