refactor(subsonic): don't make getMusicFolder a method of ctrl

This commit is contained in:
sentriz
2022-11-02 22:21:19 +00:00
parent 6e6404af73
commit 131e56b3e6
4 changed files with 29 additions and 29 deletions

View File

@@ -26,6 +26,17 @@ func lowerUDecOrHash(in string) string {
return string(lower)
}
func getMusicFolder(musicPaths []string, p params.Params) string {
idx, err := p.GetInt("musicFolderId")
if err != nil {
return ""
}
if idx < 0 || idx > len(musicPaths) {
return ""
}
return musicPaths[idx]
}
func (c *Controller) ServeGetLicence(r *http.Request) *spec.Response {
sub := spec.NewResponse()
sub.Licence = &spec.Licence{
@@ -239,7 +250,7 @@ func (c *Controller) ServeGetRandomSongs(r *http.Request) *spec.Response {
q = q.Joins("JOIN track_genres ON track_genres.track_id=tracks.id")
q = q.Joins("JOIN genres ON genres.id=track_genres.genre_id AND genres.name=?", genre)
}
if m := c.getMusicFolder(params); m != "" {
if m := getMusicFolder(c.MusicPaths, params); m != "" {
q = q.Where("albums.root_dir=?", m)
}
if err := q.Find(&tracks).Error; err != nil {