🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
fix(subsonic): make Share's lastVisited optional
Deluanbeff1afad7c6
diff --git a/server/subsonic/responses/.snapshots/Responses Shares with data should match .JSON b/server/subsonic/responses/.snapshots/Responses Shares with data should match .JSONindex 21e603d91..06706a1c5 100644--- a/server/subsonic/responses/.snapshots/Responses Shares with data should match .JSON+++ b/server/subsonic/responses/.snapshots/Responses Shares with data should match .JSON@@ -49,9 +49,9 @@"url": "http://localhost/p/ABC123","description": "Check it out!","username": "deluan",- "created": "0001-01-01T00:00:00Z",- "expires": "0001-01-01T00:00:00Z",- "lastVisited": "0001-01-01T00:00:00Z",+ "created": "2016-03-02T20:30:00Z",+ "expires": "2016-03-02T20:30:00Z",+ "lastVisited": "2016-03-02T20:30:00Z","visitCount": 2}]diff --git a/server/subsonic/responses/.snapshots/Responses Shares with data should match .XML b/server/subsonic/responses/.snapshots/Responses Shares with data should match .XMLindex a53e74114..6d2129877 100644--- a/server/subsonic/responses/.snapshots/Responses Shares with data should match .XML+++ b/server/subsonic/responses/.snapshots/Responses Shares with data should match .XML@@ -1,6 +1,6 @@<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.8.0" type="navidrome" serverVersion="v0.0.0" openSubsonic="true"><shares>- <share id="ABC123" url="http://localhost/p/ABC123" description="Check it out!" username="deluan" created="0001-01-01T00:00:00Z" expires="0001-01-01T00:00:00Z" lastVisited="0001-01-01T00:00:00Z" visitCount="2">+ <share id="ABC123" url="http://localhost/p/ABC123" description="Check it out!" username="deluan" created="2016-03-02T20:30:00Z" expires="2016-03-02T20:30:00Z" lastVisited="2016-03-02T20:30:00Z" visitCount="2"><entry id="1" isDir="false" title="title" album="album" artist="artist" duration="120" isVideo="false" bpm="0" comment="" sortName="" mediaType="" musicBrainzId="" channelCount="0" samplingRate="0"><replayGain></replayGain></entry>diff --git a/server/subsonic/responses/.snapshots/Responses Shares with only required fields should match .JSON b/server/subsonic/responses/.snapshots/Responses Shares with only required fields should match .JSONnew file mode 100644index 000000000..cc1e48667--- /dev/null+++ b/server/subsonic/responses/.snapshots/Responses Shares with only required fields should match .JSON@@ -0,0 +1,18 @@+{+ "status": "ok",+ "version": "1.8.0",+ "type": "navidrome",+ "serverVersion": "v0.0.0",+ "openSubsonic": true,+ "shares": {+ "share": [+ {+ "id": "ABC123",+ "url": "http://localhost/s/ABC123",+ "username": "johndoe",+ "created": "2016-03-02T20:30:00Z",+ "visitCount": 1+ }+ ]+ }+}diff --git a/server/subsonic/responses/.snapshots/Responses Shares with only required fields should match .XML b/server/subsonic/responses/.snapshots/Responses Shares with only required fields should match .XMLnew file mode 100644index 000000000..e59372b26--- /dev/null+++ b/server/subsonic/responses/.snapshots/Responses Shares with only required fields should match .XML@@ -0,0 +1,5 @@+<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.8.0" type="navidrome" serverVersion="v0.0.0" openSubsonic="true">+ <shares>+ <share id="ABC123" url="http://localhost/s/ABC123" username="johndoe" created="2016-03-02T20:30:00Z" visitCount="1"></share>+ </shares>+</subsonic-response>diff --git a/server/subsonic/responses/responses.go b/server/subsonic/responses/responses.goindex f1c0b7bc5..3dce71b0f 100644--- a/server/subsonic/responses/responses.go+++ b/server/subsonic/responses/responses.go@@ -423,7 +423,7 @@ type Share struct {Username string `xml:"username,attr" json:"username"`Created time.Time `xml:"created,attr" json:"created"`Expires *time.Time `xml:"expires,omitempty,attr" json:"expires,omitempty"`- LastVisited time.Time `xml:"lastVisited,omitempty,attr" json:"lastVisited"`+ LastVisited *time.Time `xml:"lastVisited,omitempty,attr" json:"lastVisited,omitempty"`VisitCount int32 `xml:"visitCount,attr" json:"visitCount"`}diff --git a/server/subsonic/responses/responses_test.go b/server/subsonic/responses/responses_test.goindex 13eb1f9ba..a4ccc54f1 100644--- a/server/subsonic/responses/responses_test.go+++ b/server/subsonic/responses/responses_test.go@@ -671,9 +671,28 @@ var _ = Describe("Responses", func() {})})+ Context("with only required fields", func() {+ BeforeEach(func() {+ t := time.Date(2016, 03, 2, 20, 30, 0, 0, time.UTC)+ response.Shares.Share = []Share{{+ ID: "ABC123",+ Url: "http://localhost/s/ABC123",+ Username: "johndoe",+ Created: t,+ VisitCount: 1,+ }}+ })+ It("should match .XML", func() {+ Expect(xml.MarshalIndent(response, "", " ")).To(MatchSnapshot())+ })+ It("should match .JSON", func() {+ Expect(json.MarshalIndent(response, "", " ")).To(MatchSnapshot())+ })+ })+Context("with data", func() {BeforeEach(func() {- t := time.Time{}+ t := time.Date(2016, 03, 2, 20, 30, 0, 0, time.UTC)share := Share{ID: "ABC123",Url: "http://localhost/p/ABC123",@@ -681,7 +700,7 @@ var _ = Describe("Responses", func() {Username: "deluan",Created: t,Expires: &t,- LastVisited: t,+ LastVisited: &t,VisitCount: 2,}share.Entry = make([]Child, 2)diff --git a/server/subsonic/sharing.go b/server/subsonic/sharing.goindex 9848ff510..9cc8d7097 100644--- a/server/subsonic/sharing.go+++ b/server/subsonic/sharing.go@@ -9,7 +9,6 @@ import ("github.com/navidrome/navidrome/model""github.com/navidrome/navidrome/server/public""github.com/navidrome/navidrome/server/subsonic/responses"- . "github.com/navidrome/navidrome/utils/gg""github.com/navidrome/navidrome/utils/req""github.com/navidrome/navidrome/utils/slice")@@ -37,7 +36,7 @@ func (api *Router) buildShare(r *http.Request, share model.Share) responses.SharUsername: share.Username,Created: share.CreatedAt,Expires: share.ExpiresAt,- LastVisited: V(share.LastVisitedAt),+ LastVisited: share.LastVisitedAt,VisitCount: int32(share.VisitCount),}if resp.Description == "" {