diff --git a/conf/configuration.go b/conf/configuration.go index f2dd406dd..55f87f00d 100644 --- a/conf/configuration.go +++ b/conf/configuration.go @@ -288,7 +288,7 @@ func init() { viper.SetDefault("devenablebufferedscrobble", true) viper.SetDefault("devsidebarplaylists", true) viper.SetDefault("devshowartistpage", true) - viper.SetDefault("devartworkmaxrequests", number.Max(2, runtime.NumCPU())) + viper.SetDefault("devartworkmaxrequests", number.Max(2, runtime.NumCPU()/3)) viper.SetDefault("devartworkthrottlebackloglimit", consts.RequestThrottleBacklogLimit) viper.SetDefault("devartworkthrottlebacklogtimeout", consts.RequestThrottleBacklogTimeout) } diff --git a/server/public/public_endpoints.go b/server/public/public_endpoints.go index 440fa7b1c..93538ca06 100644 --- a/server/public/public_endpoints.go +++ b/server/public/public_endpoints.go @@ -5,6 +5,7 @@ import ( "path" "github.com/go-chi/chi/v5" + "github.com/go-chi/chi/v5/middleware" "github.com/navidrome/navidrome/conf" "github.com/navidrome/navidrome/consts" "github.com/navidrome/navidrome/core" @@ -37,7 +38,14 @@ func (p *Router) routes() http.Handler { r.Group(func(r chi.Router) { r.Use(server.URLParamsMiddleware) - r.HandleFunc("/img/{id}", p.handleImages) + r.Group(func(r chi.Router) { + if conf.Server.DevArtworkMaxRequests > 0 { + maxRequests := conf.Server.DevArtworkMaxRequests + r.Use(middleware.ThrottleBacklog(maxRequests, conf.Server.DevArtworkThrottleBacklogLimit, + conf.Server.DevArtworkThrottleBacklogTimeout)) + } + r.HandleFunc("/img/{id}", p.handleImages) + }) if conf.Server.EnableSharing { r.HandleFunc("/s/{id}", p.handleStream) r.HandleFunc("/{id}", p.handleShares)