mirror of
https://github.com/navidrome/navidrome.git
synced 2026-08-31 07:30:32 +00:00
Merge 879354ad79b8176c29ef0c9b961ba2f519cd9965 into dbd26ba2e71d0a5b79dba873a2beeff59f1cd8dd
This commit is contained in:
commit
ab229c2f9c
@ -42,15 +42,21 @@ func (f Folder) String() string {
|
||||
// FolderID generates a unique ID for a folder in a library.
|
||||
// The ID is generated based on the library ID and the folder path relative to the library root.
|
||||
// Any leading or trailing slashes are removed from the folder path.
|
||||
func FolderID(lib Library, path string) string {
|
||||
path = strings.TrimPrefix(path, lib.Path)
|
||||
path = strings.TrimPrefix(path, string(os.PathSeparator))
|
||||
path = filepath.Clean(path)
|
||||
key := fmt.Sprintf("%d:%s", lib.ID, path)
|
||||
func FolderID(lib Library, folderPath string) string {
|
||||
folderPath = strings.TrimPrefix(folderPath, lib.Path)
|
||||
folderPath = strings.TrimPrefix(folderPath, string(os.PathSeparator))
|
||||
// Folder IDs must be stable across operating systems, so normalize to
|
||||
// forward slashes (path.Clean, not filepath.Clean) before hashing;
|
||||
// otherwise a nested path on Windows would hash with back-slashes.
|
||||
folderPath = path.Clean(filepath.ToSlash(folderPath))
|
||||
key := fmt.Sprintf("%d:%s", lib.ID, folderPath)
|
||||
return id.NewHash(key)
|
||||
}
|
||||
|
||||
func NewFolder(lib Library, folderPath string) *Folder {
|
||||
// path.Split/path.Clean below only treat "/" as a separator, so normalize
|
||||
// OS separators first to derive dir/name correctly on Windows.
|
||||
folderPath = filepath.ToSlash(folderPath)
|
||||
newID := FolderID(lib, folderPath)
|
||||
dir, name := path.Split(folderPath)
|
||||
dir = path.Clean(dir)
|
||||
|
||||
@ -7,7 +7,6 @@ import (
|
||||
|
||||
"github.com/navidrome/navidrome/model"
|
||||
"github.com/navidrome/navidrome/model/id"
|
||||
"github.com/navidrome/navidrome/tests"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
@ -67,7 +66,6 @@ var _ = Describe("Folder", func() {
|
||||
|
||||
When("the folder has multiple subdirs", func() {
|
||||
It("should return the correct folder ID", func() {
|
||||
tests.SkipOnWindows("path separator bug (#TBD-path-sep-model)")
|
||||
folderPath := filepath.FromSlash("/music/rock/metal")
|
||||
expectedID := id.NewHash("1:rock/metal")
|
||||
Expect(model.FolderID(lib, folderPath)).To(Equal(expectedID))
|
||||
@ -77,7 +75,6 @@ var _ = Describe("Folder", func() {
|
||||
|
||||
Describe("NewFolder", func() {
|
||||
It("should create a new SubFolder with the correct attributes", func() {
|
||||
tests.SkipOnWindows("path separator bug (#TBD-path-sep-model)")
|
||||
folderPath := filepath.FromSlash("rock/metal")
|
||||
folder := model.NewFolder(lib, folderPath)
|
||||
|
||||
|
||||
@ -525,11 +525,13 @@ func (mfs MediaFiles) ToM3U8(title string, absolutePaths bool) string {
|
||||
buf.WriteString(fmt.Sprintf("#PLAYLIST:%s\n", title))
|
||||
for _, t := range mfs {
|
||||
buf.WriteString(fmt.Sprintf("#EXTINF:%.f,%s - %s\n", t.Duration, t.Artist, t.Title))
|
||||
p := t.Path
|
||||
if absolutePaths {
|
||||
buf.WriteString(t.AbsolutePath() + "\n")
|
||||
} else {
|
||||
buf.WriteString(t.Path + "\n")
|
||||
p = t.AbsolutePath()
|
||||
}
|
||||
// Emit forward slashes so the exported .m3u8 is consistent across OSes
|
||||
// (AbsolutePath returns native separators on Windows).
|
||||
buf.WriteString(filepath.ToSlash(p) + "\n")
|
||||
}
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
@ -6,7 +6,6 @@ import (
|
||||
"github.com/navidrome/navidrome/conf"
|
||||
"github.com/navidrome/navidrome/conf/configtest"
|
||||
. "github.com/navidrome/navidrome/model"
|
||||
"github.com/navidrome/navidrome/tests"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
@ -477,9 +476,6 @@ var _ = Describe("MediaFiles", func() {
|
||||
|
||||
DescribeTable("generates correct output",
|
||||
func(absolutePaths bool, expectedContent string) {
|
||||
if absolutePaths {
|
||||
tests.SkipOnWindows("path separator bug (#TBD-path-sep-model)")
|
||||
}
|
||||
result := mfs.ToM3U8("Multi Track", absolutePaths)
|
||||
Expect(result).To(Equal(expectedContent))
|
||||
},
|
||||
@ -500,7 +496,6 @@ var _ = Describe("MediaFiles", func() {
|
||||
|
||||
Context("path variations", func() {
|
||||
It("handles different path structures", func() {
|
||||
tests.SkipOnWindows("path separator bug (#TBD-path-sep-model)")
|
||||
mfs = MediaFiles{
|
||||
{Title: "Root", Artist: "Artist", Duration: 60, Path: "song.mp3", LibraryPath: "/lib"},
|
||||
{Title: "Nested", Artist: "Artist", Duration: 60, Path: "deep/nested/song.mp3", LibraryPath: "/lib"},
|
||||
|
||||
@ -7,7 +7,6 @@ import (
|
||||
"github.com/navidrome/navidrome/conf/configtest"
|
||||
"github.com/navidrome/navidrome/model"
|
||||
"github.com/navidrome/navidrome/model/criteria"
|
||||
"github.com/navidrome/navidrome/tests"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
@ -33,7 +32,6 @@ var _ = Describe("Playlist", func() {
|
||||
}
|
||||
})
|
||||
It("generates the correct M3U format", func() {
|
||||
tests.SkipOnWindows("path separator bug (#TBD-path-sep-model)")
|
||||
expected := `#EXTM3U
|
||||
#PLAYLIST:Mellow sunset
|
||||
#EXTINF:378,Morcheeba feat. Kurt Wagner - What New York Couples Fight About
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user