mirror of
https://github.com/navidrome/navidrome.git
synced 2026-10-08 02:17:25 +02:00
* feat(model): add per-library PID config columns * refactor(metadata): pass PID config to ToMediaFile and add spec validation * feat(scanner): rescan only libraries whose PID config changed * feat(server): validate library PID config and rescan on change * feat(ui): edit per-library PID config * fix(ui): label the PID mode selects * fix: tighten per-library PID rescan edge cases An interrupted PID rescan no longer upgrades every library to a full scan, a save that loses the race for the scanner logs at debug, the confirm dialog only shows when the effective PID spec changes, and it now gets translation keys. * refactor(metadata): pass the library to ToMediaFile ToMediaFile and core.Inspect took the library ID and its PID config as separate arguments, so a caller could mix values from two libraries. They now take the model.Library and resolve the effective PID config from it. * chore: tidy per-library PID comments, PropTypes and migration Trim comments that restated the code, add PropTypes to the new UI components, and recreate the migration with make migration-sql. * fix(ui): show the PID spec help under its input * feat(cmd): make inspect use the file's library PID config inspect always used the global PID config, so it showed different IDs than the scanner for files in a library with an override. It now finds the file's library in the DB and uses its effective config, falling back to the global config when there is no DB or the file is outside every library. It never creates a DB. The library path matcher moves from core/playlists to model so both can use it. * refactor: simplify per-library PID code Share the DB-file check between CLI commands, move ErrAlreadyScanning to model so core no longer imports scanner, read the libraries once for insights, and let ValidatePIDSpec accept an empty spec and look tags up directly. In the scanner, use FullScanInProgress instead of a second flag, and skip recomputing album IDs when the album spec did not change. In the UI, share the PID inputs between Create and Edit, and use docsUrl. * feat(ui): add section titles to Library Create and pre-fill Custom PID specs Custom now starts from the global spec, so admins edit a working spec instead of typing one from scratch. * fix(inspect): map files with the library-relative path the scanner uses Inspect gave metadata the file's directory as typed, so folder-based PIDs never matched the DB. It now uses the path relative to the library root, through the scanner's helper, which moves to model. * fix(scanner): say when a PID rescan only covers target folders * fix: reject tag aliases in album PID specs and match root libraries Tags are stored under canonical names, so an alias in a spec always reads as empty. In an album spec that gives every album the same ID, so album specs now require the tag name. Track specs keep accepting aliases, since the default one uses them. LibraryMatcher now matches paths under a library at the filesystem root. * refactor(model): move the tag alias lookup to tag_mappings.go * test: run the library matcher and inspect tests on Windows Build test paths with filepath instead of Unix literals, so they use the OS separator like filepath.Abs output, and drop the Windows skips. * feat(ui): add pt-BR translations for per-library PID settings
91 lines
4.2 KiB
Go
91 lines
4.2 KiB
Go
package model_test
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/navidrome/navidrome/model"
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
var _ = Describe("LibraryMatcher", func() {
|
|
// Paths are written Unix-style and converted, so they use the OS separator, as filepath.Abs output does
|
|
find := func(libs model.Libraries, path string) int {
|
|
for i := range libs {
|
|
libs[i].Path = filepath.FromSlash(libs[i].Path)
|
|
}
|
|
lib, ok := model.NewLibraryMatcher(libs).FindLibrary(filepath.FromSlash(path))
|
|
if !ok {
|
|
return 0
|
|
}
|
|
return lib.ID
|
|
}
|
|
|
|
DescribeTable("matches the longest library path",
|
|
func(libs model.Libraries, path string, expectedID int) {
|
|
Expect(find(libs, path)).To(Equal(expectedID))
|
|
},
|
|
Entry("nested library", model.Libraries{{ID: 1, Path: "/music"}, {ID: 2, Path: "/music-classical"}, {ID: 3, Path: "/music-classical/opera"}}, "/music-classical/opera/subdir/track.mp3", 3),
|
|
Entry("sibling with a shared prefix", model.Libraries{{ID: 1, Path: "/music"}, {ID: 2, Path: "/music-classical"}}, "/music-classical/track.mp3", 2),
|
|
Entry("shorter library", model.Libraries{{ID: 1, Path: "/music"}, {ID: 2, Path: "/music-classical"}}, "/music/track.mp3", 1),
|
|
Entry("exact library root", model.Libraries{{ID: 1, Path: "/music"}, {ID: 2, Path: "/music-classical"}}, "/music-classical", 2),
|
|
Entry("deeply nested libraries", model.Libraries{{ID: 1, Path: "/media"}, {ID: 2, Path: "/media/audio"}, {ID: 3, Path: "/media/audio/classical"}, {ID: 4, Path: "/media/audio/classical/baroque"}}, "/media/audio/classical/mozart/track.mp3", 3),
|
|
Entry("prefix that is not a path boundary", model.Libraries{{ID: 1, Path: "/a"}, {ID: 2, Path: "/ab"}, {ID: 3, Path: "/abc"}}, "/ab/file.mp3", 2),
|
|
Entry("special characters match literally", model.Libraries{{ID: 1, Path: "/music[test]"}, {ID: 2, Path: "/music(backup)"}}, "/music[test]/track.mp3", 1),
|
|
Entry("library path with a trailing slash", model.Libraries{{ID: 1, Path: "/music/"}}, "/music/track.mp3", 1),
|
|
Entry("library at the filesystem root", model.Libraries{{ID: 1, Path: "/"}}, "/music/track.mp3", 1),
|
|
Entry("nested library under a root library", model.Libraries{{ID: 1, Path: "/"}, {ID: 2, Path: "/music"}}, "/music/track.mp3", 2),
|
|
)
|
|
|
|
It("does not match a path outside every library", func() {
|
|
Expect(find(model.Libraries{{ID: 1, Path: "/music"}}, "/music-backup/track.mp3")).To(BeZero())
|
|
})
|
|
|
|
It("does not match anything without libraries", func() {
|
|
Expect(find(nil, "/music/track.mp3")).To(BeZero())
|
|
})
|
|
|
|
It("does not reorder the caller's libraries", func() {
|
|
libs := model.Libraries{{ID: 1, Path: "/a"}, {ID: 2, Path: "/abc"}}
|
|
model.NewLibraryMatcher(libs)
|
|
Expect(libs.IDs()).To(Equal([]int{1, 2}))
|
|
})
|
|
})
|
|
|
|
var _ = Describe("LibraryRelativePath", func() {
|
|
// Paths are built with filepath so the "absolute" cases stay absolute on every OS
|
|
// (a Unix-style "/foo" is not absolute on Windows).
|
|
libRoot, _ := filepath.Abs(filepath.Join("jukebox", "collection"))
|
|
outside, _ := filepath.Abs(filepath.Join("somewhere", "else"))
|
|
|
|
It("returns a relative path unchanged", func() {
|
|
Expect(model.LibraryRelativePath(libRoot, "_Collection")).To(Equal("_Collection"))
|
|
})
|
|
|
|
It("rebases an absolute target when the library root is relative", func() {
|
|
cwd, err := os.Getwd()
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(model.LibraryRelativePath(filepath.Join("music", "library"), filepath.Join(cwd, "music", "library", "rock"))).To(Equal("rock"))
|
|
})
|
|
|
|
It("rebases an absolute path that equals the library root to '.'", func() {
|
|
Expect(model.LibraryRelativePath(libRoot, libRoot)).To(Equal("."))
|
|
})
|
|
|
|
It("rebases an absolute path under the library root", func() {
|
|
Expect(model.LibraryRelativePath(libRoot, filepath.Join(libRoot, "_Collection"))).To(Equal("_Collection"))
|
|
})
|
|
|
|
It("handles a trailing slash on the library path", func() {
|
|
Expect(model.LibraryRelativePath(libRoot+string(filepath.Separator), filepath.Join(libRoot, "_Collection"))).To(Equal("_Collection"))
|
|
})
|
|
|
|
It("leaves an absolute path outside the library root unchanged", func() {
|
|
Expect(model.LibraryRelativePath(libRoot, outside)).To(Equal(outside))
|
|
})
|
|
|
|
It("returns an empty path unchanged", func() {
|
|
Expect(model.LibraryRelativePath(libRoot, "")).To(Equal(""))
|
|
})
|
|
})
|