mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-04 13:07:36 +03:00
Add throttling to /share/img endpoint.
See: https://github.com/navidrome/navidrome/issues/2130#issuecomment-1414152343
This commit is contained in:
parent
9b81aa4403
commit
bcab3cc0f9
2 changed files with 10 additions and 2 deletions
|
@ -288,7 +288,7 @@ func init() {
|
||||||
viper.SetDefault("devenablebufferedscrobble", true)
|
viper.SetDefault("devenablebufferedscrobble", true)
|
||||||
viper.SetDefault("devsidebarplaylists", true)
|
viper.SetDefault("devsidebarplaylists", true)
|
||||||
viper.SetDefault("devshowartistpage", 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("devartworkthrottlebackloglimit", consts.RequestThrottleBacklogLimit)
|
||||||
viper.SetDefault("devartworkthrottlebacklogtimeout", consts.RequestThrottleBacklogTimeout)
|
viper.SetDefault("devartworkthrottlebacklogtimeout", consts.RequestThrottleBacklogTimeout)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"path"
|
"path"
|
||||||
|
|
||||||
"github.com/go-chi/chi/v5"
|
"github.com/go-chi/chi/v5"
|
||||||
|
"github.com/go-chi/chi/v5/middleware"
|
||||||
"github.com/navidrome/navidrome/conf"
|
"github.com/navidrome/navidrome/conf"
|
||||||
"github.com/navidrome/navidrome/consts"
|
"github.com/navidrome/navidrome/consts"
|
||||||
"github.com/navidrome/navidrome/core"
|
"github.com/navidrome/navidrome/core"
|
||||||
|
@ -37,7 +38,14 @@ func (p *Router) routes() http.Handler {
|
||||||
|
|
||||||
r.Group(func(r chi.Router) {
|
r.Group(func(r chi.Router) {
|
||||||
r.Use(server.URLParamsMiddleware)
|
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 {
|
if conf.Server.EnableSharing {
|
||||||
r.HandleFunc("/s/{id}", p.handleStream)
|
r.HandleFunc("/s/{id}", p.handleStream)
|
||||||
r.HandleFunc("/{id}", p.handleShares)
|
r.HandleFunc("/{id}", p.handleShares)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue