Replace MinInt/MaxInt with generic versions
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/navidrome/navidrome/server/subsonic/filter"
|
||||
"github.com/navidrome/navidrome/server/subsonic/responses"
|
||||
"github.com/navidrome/navidrome/utils"
|
||||
"github.com/navidrome/navidrome/utils/math2"
|
||||
)
|
||||
|
||||
func (api *Router) getAlbumList(r *http.Request) (model.Albums, int64, error) {
|
||||
@@ -59,7 +60,7 @@ func (api *Router) getAlbumList(r *http.Request) (model.Albums, int64, error) {
|
||||
}
|
||||
|
||||
opts.Offset = utils.ParamInt(r, "offset", 0)
|
||||
opts.Max = utils.MinInt(utils.ParamInt(r, "size", 10), 500)
|
||||
opts.Max = math2.Min(utils.ParamInt(r, "size", 10), 500)
|
||||
albums, err := api.ds.Album(r.Context()).GetAllWithoutGenres(opts)
|
||||
|
||||
if err != nil {
|
||||
@@ -167,7 +168,7 @@ func (api *Router) GetNowPlaying(r *http.Request) (*responses.Subsonic, error) {
|
||||
}
|
||||
|
||||
func (api *Router) GetRandomSongs(r *http.Request) (*responses.Subsonic, error) {
|
||||
size := utils.MinInt(utils.ParamInt(r, "size", 10), 500)
|
||||
size := math2.Min(utils.ParamInt(r, "size", 10), 500)
|
||||
genre := utils.ParamString(r, "genre")
|
||||
fromYear := utils.ParamInt(r, "fromYear", 0)
|
||||
toYear := utils.ParamInt(r, "toYear", 0)
|
||||
@@ -185,8 +186,8 @@ func (api *Router) GetRandomSongs(r *http.Request) (*responses.Subsonic, error)
|
||||
}
|
||||
|
||||
func (api *Router) GetSongsByGenre(r *http.Request) (*responses.Subsonic, error) {
|
||||
count := utils.MinInt(utils.ParamInt(r, "count", 10), 500)
|
||||
offset := utils.MinInt(utils.ParamInt(r, "offset", 0), 500)
|
||||
count := math2.Min(utils.ParamInt(r, "count", 10), 500)
|
||||
offset := math2.Min(utils.ParamInt(r, "offset", 0), 500)
|
||||
genre := utils.ParamString(r, "genre")
|
||||
|
||||
songs, err := api.getSongs(r.Context(), offset, count, filter.SongsByGenre(genre))
|
||||
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
"github.com/navidrome/navidrome/server/events"
|
||||
"github.com/navidrome/navidrome/server/subsonic/responses"
|
||||
"github.com/navidrome/navidrome/utils"
|
||||
"github.com/navidrome/navidrome/utils/math2"
|
||||
)
|
||||
|
||||
const Version = "1.16.1"
|
||||
@@ -137,7 +138,7 @@ func (api *Router) routes() http.Handler {
|
||||
})
|
||||
r.Group(func(r chi.Router) {
|
||||
// configure request throttling
|
||||
maxRequests := utils.MaxInt(2, runtime.NumCPU())
|
||||
maxRequests := math2.Max(2, runtime.NumCPU())
|
||||
r.Use(middleware.ThrottleBacklog(maxRequests, consts.RequestThrottleBacklogLimit, consts.RequestThrottleBacklogTimeout))
|
||||
hr(r, "getAvatar", api.GetAvatar)
|
||||
hr(r, "getCoverArt", api.GetCoverArt)
|
||||
|
||||
Reference in New Issue
Block a user