feat: persist and expose plugin playlist ValidUntil in Subsonic API

Add a ValidUntil field to the Playlist model and persist it from the
plugin's GetPlaylistResponse during sync. This allows clients to know
when a plugin playlist's data will be refreshed. The value is exposed
in the OpenSubsonic playlist response alongside the existing
smart playlist ValidUntil calculation. The migration is consolidated
into a single multi-statement ExecContext call.
This commit is contained in:
Deluan 2026-03-05 19:00:43 -05:00
commit 9ddbcbf6b4
6 changed files with 33 additions and 22 deletions

View file

@ -168,9 +168,10 @@ func buildOSPlaylist(ctx context.Context, p model.Playlist) *responses.OpenSubso
if p.IsReadOnly() {
pls.Readonly = true
// ValidUntil only applies to smart playlists
if p.IsSmartPlaylist() && p.EvaluatedAt != nil {
pls.ValidUntil = P(p.EvaluatedAt.Add(conf.Server.SmartPlaylistRefreshDelay))
} else if p.IsPluginPlaylist() && p.ValidUntil != nil {
pls.ValidUntil = p.ValidUntil
}
} else {
user, ok := request.UserFrom(ctx)

View file

@ -177,13 +177,23 @@ var _ = Describe("buildPlaylist", func() {
}
})
It("marks plugin playlist as readonly", func() {
It("marks plugin playlist as readonly with no ValidUntil when not set", func() {
ctx = request.WithUser(ctx, model.User{ID: "1234", UserName: "admin"})
result := router.buildPlaylist(ctx, playlist)
Expect(result.Readonly).To(BeTrue())
Expect(result.ValidUntil).To(BeNil())
})
It("exposes ValidUntil when set on the model", func() {
validUntil := time.Date(2023, 3, 1, 12, 0, 0, 0, time.UTC)
playlist.ValidUntil = &validUntil
ctx = request.WithUser(ctx, model.User{ID: "1234", UserName: "admin"})
result := router.buildPlaylist(ctx, playlist)
Expect(result.Readonly).To(BeTrue())
Expect(result.ValidUntil).To(Equal(&validUntil))
})
It("marks plugin playlist as readonly even for non-owner", func() {
ctx = request.WithUser(ctx, model.User{ID: "other-user", UserName: "other"})
result := router.buildPlaylist(ctx, playlist)