feat: allow for custom music folder path alias

closes #259
This commit is contained in:
sentriz
2022-11-21 20:17:55 +00:00
parent 92a73b2d61
commit 7e097c9bdf
6 changed files with 81 additions and 32 deletions

View File

@@ -10,6 +10,7 @@ import (
"net/http"
"go.senan.xyz/gonic/jukebox"
"go.senan.xyz/gonic/paths"
"go.senan.xyz/gonic/podcasts"
"go.senan.xyz/gonic/scrobble"
"go.senan.xyz/gonic/server/ctrlbase"
@@ -31,7 +32,7 @@ type Controller struct {
CachePath string
CoverCachePath string
PodcastsPath string
MusicPaths []string
MusicPaths paths.MusicPaths
Jukebox *jukebox.Jukebox
Scrobblers []scrobble.Scrobbler
Podcasts *podcasts.Podcasts

View File

@@ -19,6 +19,7 @@ import (
"go.senan.xyz/gonic/db"
"go.senan.xyz/gonic/mockfs"
"go.senan.xyz/gonic/paths"
"go.senan.xyz/gonic/server/ctrlbase"
"go.senan.xyz/gonic/server/ctrlsubsonic/params"
"go.senan.xyz/gonic/transcode"
@@ -158,9 +159,9 @@ func makec(t *testing.T, roots []string, audio bool) *Controller {
m.ScanAndClean()
m.ResetDates()
var absRoots []string
var absRoots paths.MusicPaths
for _, root := range roots {
absRoots = append(absRoots, filepath.Join(m.TmpDir(), root))
absRoots = append(absRoots, paths.MusicPath{Alias: "", Path: filepath.Join(m.TmpDir(), root)})
}
base := &ctrlbase.Controller{DB: m.DB()}

View File

@@ -15,6 +15,7 @@ import (
"go.senan.xyz/gonic/db"
"go.senan.xyz/gonic/multierr"
"go.senan.xyz/gonic/paths"
"go.senan.xyz/gonic/scanner"
"go.senan.xyz/gonic/server/ctrlsubsonic/params"
"go.senan.xyz/gonic/server/ctrlsubsonic/spec"
@@ -29,7 +30,7 @@ func lowerUDecOrHash(in string) string {
return string(lower)
}
func getMusicFolder(musicPaths []string, p params.Params) string {
func getMusicFolder(musicPaths paths.MusicPaths, p params.Params) string {
idx, err := p.GetInt("musicFolderId")
if err != nil {
return ""
@@ -37,7 +38,7 @@ func getMusicFolder(musicPaths []string, p params.Params) string {
if idx < 0 || idx > len(musicPaths) {
return ""
}
return musicPaths[idx]
return musicPaths[idx].Path
}
func (c *Controller) ServeGetLicence(r *http.Request) *spec.Response {
@@ -91,7 +92,7 @@ func (c *Controller) ServeGetMusicFolders(r *http.Request) *spec.Response {
sub.MusicFolders = &spec.MusicFolders{}
sub.MusicFolders.List = make([]*spec.MusicFolder, len(c.MusicPaths))
for i, path := range c.MusicPaths {
sub.MusicFolders.List[i] = &spec.MusicFolder{ID: i, Name: filepath.Base(path)}
sub.MusicFolders.List[i] = &spec.MusicFolder{ID: i, Name: path.DisplayAlias()}
}
return sub
}