mirror of
https://github.com/navidrome/navidrome.git
synced 2026-05-03 06:51:16 +00:00
feat(plugins): add LibraryID to TrackInfo
Add LibraryID field to TrackInfo so plugins with library filesystem access can determine which library a track belongs to. This lets plugins resolve the full filesystem path by combining the library's root path with the track's relative path. LibraryID is gated behind the same filesystem access permission check as Path.
This commit is contained in:
parent
1bd736dae9
commit
fd930eefd7
@ -68,6 +68,9 @@ type TrackInfo struct {
|
||||
MBZReleaseGroupID string `json:"mbzReleaseGroupId,omitempty"`
|
||||
// MBZReleaseTrackID is the MusicBrainz release track ID.
|
||||
MBZReleaseTrackID string `json:"mbzReleaseTrackId,omitempty"`
|
||||
// LibraryID is the ID of the library the track belongs to.
|
||||
// Only included if the plugin has library permission with filesystem access for the track's library.
|
||||
LibraryID int32 `json:"libraryId,omitempty"`
|
||||
// Path is the full path to the track file, relative to the library root.
|
||||
// Only included if the plugin has library permission with filesystem access for the track's library.
|
||||
Path string `json:"path,omitempty"`
|
||||
|
||||
@ -130,6 +130,7 @@ func mediaFileToTrackInfo(p *plugin, mf *model.MediaFile) capabilities.TrackInfo
|
||||
MBZReleaseTrackID: mf.MbzReleaseTrackID,
|
||||
}
|
||||
if p.hasLibraryFilesystemAccess(mf.LibraryID) {
|
||||
ti.LibraryID = int32(mf.LibraryID)
|
||||
ti.Path = mf.Path
|
||||
}
|
||||
return ti
|
||||
|
||||
@ -259,19 +259,25 @@ var _ = Describe("ScrobblerPlugin", Ordered, func() {
|
||||
},
|
||||
}
|
||||
|
||||
It("includes Path when the plugin has filesystem access to the track's library", func() {
|
||||
It("includes LibraryID and Path when the plugin has filesystem access to the track's library", func() {
|
||||
p := &plugin{manifest: fsManifest, libraries: newLibraryAccess([]int{1}, false)}
|
||||
Expect(mediaFileToTrackInfo(p, track).Path).To(Equal("/music/test.flac"))
|
||||
ti := mediaFileToTrackInfo(p, track)
|
||||
Expect(ti.LibraryID).To(Equal(int32(1)))
|
||||
Expect(ti.Path).To(Equal("/music/test.flac"))
|
||||
})
|
||||
|
||||
It("omits Path when the plugin lacks filesystem permission", func() {
|
||||
It("omits LibraryID and Path when the plugin lacks filesystem permission", func() {
|
||||
p := &plugin{manifest: &Manifest{}, libraries: newLibraryAccess([]int{1}, false)}
|
||||
Expect(mediaFileToTrackInfo(p, track).Path).To(BeEmpty())
|
||||
ti := mediaFileToTrackInfo(p, track)
|
||||
Expect(ti.LibraryID).To(BeZero())
|
||||
Expect(ti.Path).To(BeEmpty())
|
||||
})
|
||||
|
||||
It("omits Path when the track's library is not in the allowed set", func() {
|
||||
It("omits LibraryID and Path when the track's library is not in the allowed set", func() {
|
||||
p := &plugin{manifest: fsManifest, libraries: newLibraryAccess([]int{2}, false)}
|
||||
Expect(mediaFileToTrackInfo(p, track).Path).To(BeEmpty())
|
||||
ti := mediaFileToTrackInfo(p, track)
|
||||
Expect(ti.LibraryID).To(BeZero())
|
||||
Expect(ti.Path).To(BeEmpty())
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user