From b8fceae3834d29f447fbb23eeb77f6216018e55a Mon Sep 17 00:00:00 2001 From: sentriz Date: Sat, 8 Apr 2023 01:20:34 +0100 Subject: [PATCH] feat(sunsonic): expose type serverVersion in subsonic responses https://opensubsonic.netlify.app/docs/responses/subsonic-response/ https://github.com/opensubsonic/open-subsonic-api/discussions/3 --- cmd/gonic/gonic.go | 4 +- server/ctrladmin/adminui/components.tmpl | 2 +- server/ctrlsubsonic/ctrl_test.go | 2 + server/ctrlsubsonic/spec/spec.go | 24 ++-- .../testdata/test_get_album_list_alpha_artist | 1 + .../testdata/test_get_album_list_alpha_name | 1 + .../testdata/test_get_album_list_newest | 1 + .../testdata/test_get_album_list_random | 39 +++--- .../test_get_album_list_two_alpha_artist | 1 + .../test_get_album_list_two_alpha_name | 1 + .../testdata/test_get_album_list_two_newest | 1 + .../testdata/test_get_album_list_two_random | 115 +++++++++--------- .../testdata/test_get_album_with_cover | 1 + .../testdata/test_get_album_without_cover | 1 + .../testdata/test_get_artist_id_one | 1 + .../testdata/test_get_artist_id_three | 1 + .../testdata/test_get_artist_id_two | 1 + .../testdata/test_get_artists_no_args | 1 + .../test_get_artists_with_music_folder_1 | 1 + .../test_get_artists_with_music_folder_2 | 1 + .../testdata/test_get_indexes_no_args | 1 + .../test_get_indexes_with_music_folder_1 | 1 + .../test_get_indexes_with_music_folder_2 | 1 + .../test_get_music_directory_with_tracks | 1 + .../test_get_music_directory_without_tracks | 1 + .../testdata/test_search_three_q_alb | 1 + .../testdata/test_search_three_q_art | 1 + .../testdata/test_search_three_q_tra | 1 + .../testdata/test_search_two_q_alb | 1 + .../testdata/test_search_two_q_art | 1 + .../testdata/test_search_two_q_tra | 1 + version.go | 3 +- 32 files changed, 124 insertions(+), 90 deletions(-) diff --git a/cmd/gonic/gonic.go b/cmd/gonic/gonic.go index 4de7704..f8994e6 100644 --- a/cmd/gonic/gonic.go +++ b/cmd/gonic/gonic.go @@ -64,11 +64,11 @@ func main() { } if *confShowVersion { - fmt.Println(gonic.Version) + fmt.Printf("v%s\n", gonic.Version) os.Exit(0) } - log.Printf("starting gonic %s\n", gonic.Version) + log.Printf("starting gonic v%s\n", gonic.Version) log.Printf("provided config\n") set.VisitAll(func(f *flag.Flag) { value := strings.ReplaceAll(f.Value.String(), "\n", "") diff --git a/server/ctrladmin/adminui/components.tmpl b/server/ctrladmin/adminui/components.tmpl index 7bdaae3..af529bf 100644 --- a/server/ctrladmin/adminui/components.tmpl +++ b/server/ctrladmin/adminui/components.tmpl @@ -62,7 +62,7 @@ {{ end }} {{ slot }}
- {{ .Version }} + v{{ .Version }} senan kelly, 2020 | {{ component "ext_link" (props . "To" "https://github.com/sentriz/gonic") }}github{{ end }} diff --git a/server/ctrlsubsonic/ctrl_test.go b/server/ctrlsubsonic/ctrl_test.go index 574b661..034a9ac 100644 --- a/server/ctrlsubsonic/ctrl_test.go +++ b/server/ctrlsubsonic/ctrl_test.go @@ -16,6 +16,7 @@ import ( jd "github.com/josephburnett/jd/lib" + "go.senan.xyz/gonic" "go.senan.xyz/gonic/db" "go.senan.xyz/gonic/mockfs" "go.senan.xyz/gonic/paths" @@ -174,6 +175,7 @@ func makec(t *testing.T, roots []string, audio bool) *Controller { } func TestMain(m *testing.M) { + gonic.Version = "" log.SetOutput(io.Discard) os.Exit(m.Run()) } diff --git a/server/ctrlsubsonic/spec/spec.go b/server/ctrlsubsonic/spec/spec.go index 60c9c91..49012e0 100644 --- a/server/ctrlsubsonic/spec/spec.go +++ b/server/ctrlsubsonic/spec/spec.go @@ -21,10 +21,14 @@ type SubsonicResponse struct { } type Response struct { - Status string `xml:"status,attr" json:"status"` - Version string `xml:"version,attr" json:"version"` - XMLNS string `xml:"xmlns,attr" json:"-"` - Type string `xml:"type,attr" json:"type"` + Status string `xml:"status,attr" json:"status"` + Version string `xml:"version,attr" json:"version"` + XMLNS string `xml:"xmlns,attr" json:"-"` + + // https://opensubsonic.netlify.app/docs/responses/subsonic-response/ + Type string `xml:"type,attr" json:"type"` + ServerVersion string `xml:"serverVersion,attr" json:"serverVersion"` + Error *Error `xml:"error" json:"error,omitempty"` Albums *Albums `xml:"albumList" json:"albumList,omitempty"` AlbumsTwo *Albums `xml:"albumList2" json:"albumList2,omitempty"` @@ -64,10 +68,11 @@ type Response struct { func NewResponse() *Response { return &Response{ - Status: "ok", - XMLNS: xmlns, - Version: apiVersion, - Type: gonic.Name, + Status: "ok", + XMLNS: xmlns, + Version: apiVersion, + Type: gonic.Name, + ServerVersion: gonic.Version, } } @@ -97,7 +102,8 @@ func NewError(code int, message string, a ...interface{}) *Response { Code: code, Message: fmt.Sprintf(message, a...), }, - Type: gonic.Name, + Type: gonic.Name, + ServerVersion: gonic.Version, } } diff --git a/server/ctrlsubsonic/testdata/test_get_album_list_alpha_artist b/server/ctrlsubsonic/testdata/test_get_album_list_alpha_artist index 72d9ee7..568a446 100644 --- a/server/ctrlsubsonic/testdata/test_get_album_list_alpha_artist +++ b/server/ctrlsubsonic/testdata/test_get_album_list_alpha_artist @@ -3,6 +3,7 @@ "status": "ok", "version": "1.15.0", "type": "gonic", + "serverVersion": "", "albumList": { "album": [ { diff --git a/server/ctrlsubsonic/testdata/test_get_album_list_alpha_name b/server/ctrlsubsonic/testdata/test_get_album_list_alpha_name index 41c9049..f55e489 100644 --- a/server/ctrlsubsonic/testdata/test_get_album_list_alpha_name +++ b/server/ctrlsubsonic/testdata/test_get_album_list_alpha_name @@ -3,6 +3,7 @@ "status": "ok", "version": "1.15.0", "type": "gonic", + "serverVersion": "", "albumList": { "album": [ { diff --git a/server/ctrlsubsonic/testdata/test_get_album_list_newest b/server/ctrlsubsonic/testdata/test_get_album_list_newest index 72d9ee7..568a446 100644 --- a/server/ctrlsubsonic/testdata/test_get_album_list_newest +++ b/server/ctrlsubsonic/testdata/test_get_album_list_newest @@ -3,6 +3,7 @@ "status": "ok", "version": "1.15.0", "type": "gonic", + "serverVersion": "", "albumList": { "album": [ { diff --git a/server/ctrlsubsonic/testdata/test_get_album_list_random b/server/ctrlsubsonic/testdata/test_get_album_list_random index 4767066..436f0ff 100644 --- a/server/ctrlsubsonic/testdata/test_get_album_list_random +++ b/server/ctrlsubsonic/testdata/test_get_album_list_random @@ -3,8 +3,22 @@ "status": "ok", "version": "1.15.0", "type": "gonic", + "serverVersion": "", "albumList": { "album": [ + { + "id": "al-13", + "coverArt": "al-13", + "artist": "artist-2", + "created": "2019-11-30T00:00:00Z", + "title": "album-2", + "album": "", + "parent": "al-10", + "isDir": true, + "name": "", + "songCount": 3, + "duration": 300 + }, { "id": "al-12", "coverArt": "al-12", @@ -32,26 +46,13 @@ "duration": 300 }, { - "id": "al-4", - "coverArt": "al-4", + "id": "al-5", + "coverArt": "al-5", "artist": "artist-0", "created": "2019-11-30T00:00:00Z", - "title": "album-1", - "album": "", - "parent": "al-2", - "isDir": true, - "name": "", - "songCount": 3, - "duration": 300 - }, - { - "id": "al-13", - "coverArt": "al-13", - "artist": "artist-2", - "created": "2019-11-30T00:00:00Z", "title": "album-2", "album": "", - "parent": "al-10", + "parent": "al-2", "isDir": true, "name": "", "songCount": 3, @@ -110,11 +111,11 @@ "duration": 300 }, { - "id": "al-5", - "coverArt": "al-5", + "id": "al-4", + "coverArt": "al-4", "artist": "artist-0", "created": "2019-11-30T00:00:00Z", - "title": "album-2", + "title": "album-1", "album": "", "parent": "al-2", "isDir": true, diff --git a/server/ctrlsubsonic/testdata/test_get_album_list_two_alpha_artist b/server/ctrlsubsonic/testdata/test_get_album_list_two_alpha_artist index 1f54a5f..10db2ef 100644 --- a/server/ctrlsubsonic/testdata/test_get_album_list_two_alpha_artist +++ b/server/ctrlsubsonic/testdata/test_get_album_list_two_alpha_artist @@ -3,6 +3,7 @@ "status": "ok", "version": "1.15.0", "type": "gonic", + "serverVersion": "", "albumList2": { "album": [ { diff --git a/server/ctrlsubsonic/testdata/test_get_album_list_two_alpha_name b/server/ctrlsubsonic/testdata/test_get_album_list_two_alpha_name index ded7e5c..34dff4e 100644 --- a/server/ctrlsubsonic/testdata/test_get_album_list_two_alpha_name +++ b/server/ctrlsubsonic/testdata/test_get_album_list_two_alpha_name @@ -3,6 +3,7 @@ "status": "ok", "version": "1.15.0", "type": "gonic", + "serverVersion": "", "albumList2": { "album": [ { diff --git a/server/ctrlsubsonic/testdata/test_get_album_list_two_newest b/server/ctrlsubsonic/testdata/test_get_album_list_two_newest index 1f54a5f..10db2ef 100644 --- a/server/ctrlsubsonic/testdata/test_get_album_list_two_newest +++ b/server/ctrlsubsonic/testdata/test_get_album_list_two_newest @@ -3,6 +3,7 @@ "status": "ok", "version": "1.15.0", "type": "gonic", + "serverVersion": "", "albumList2": { "album": [ { diff --git a/server/ctrlsubsonic/testdata/test_get_album_list_two_random b/server/ctrlsubsonic/testdata/test_get_album_list_two_random index f5bd004..ccbfab4 100644 --- a/server/ctrlsubsonic/testdata/test_get_album_list_two_random +++ b/server/ctrlsubsonic/testdata/test_get_album_list_two_random @@ -3,60 +3,9 @@ "status": "ok", "version": "1.15.0", "type": "gonic", + "serverVersion": "", "albumList2": { "album": [ - { - "id": "al-3", - "coverArt": "al-3", - "artistId": "ar-1", - "artist": "artist-0", - "created": "2019-11-30T00:00:00Z", - "title": "", - "album": "", - "name": "album-0", - "songCount": 3, - "duration": 300, - "year": 2021 - }, - { - "id": "al-5", - "coverArt": "al-5", - "artistId": "ar-1", - "artist": "artist-0", - "created": "2019-11-30T00:00:00Z", - "title": "", - "album": "", - "name": "album-2", - "songCount": 3, - "duration": 300, - "year": 2021 - }, - { - "id": "al-11", - "coverArt": "al-11", - "artistId": "ar-3", - "artist": "artist-2", - "created": "2019-11-30T00:00:00Z", - "title": "", - "album": "", - "name": "album-0", - "songCount": 3, - "duration": 300, - "year": 2021 - }, - { - "id": "al-9", - "coverArt": "al-9", - "artistId": "ar-2", - "artist": "artist-1", - "created": "2019-11-30T00:00:00Z", - "title": "", - "album": "", - "name": "album-2", - "songCount": 3, - "duration": 300, - "year": 2021 - }, { "id": "al-13", "coverArt": "al-13", @@ -84,14 +33,27 @@ "year": 2021 }, { - "id": "al-8", - "coverArt": "al-8", - "artistId": "ar-2", - "artist": "artist-1", + "id": "al-11", + "coverArt": "al-11", + "artistId": "ar-3", + "artist": "artist-2", "created": "2019-11-30T00:00:00Z", "title": "", "album": "", - "name": "album-1", + "name": "album-0", + "songCount": 3, + "duration": 300, + "year": 2021 + }, + { + "id": "al-3", + "coverArt": "al-3", + "artistId": "ar-1", + "artist": "artist-0", + "created": "2019-11-30T00:00:00Z", + "title": "", + "album": "", + "name": "album-0", "songCount": 3, "duration": 300, "year": 2021 @@ -109,6 +71,45 @@ "duration": 300, "year": 2021 }, + { + "id": "al-5", + "coverArt": "al-5", + "artistId": "ar-1", + "artist": "artist-0", + "created": "2019-11-30T00:00:00Z", + "title": "", + "album": "", + "name": "album-2", + "songCount": 3, + "duration": 300, + "year": 2021 + }, + { + "id": "al-9", + "coverArt": "al-9", + "artistId": "ar-2", + "artist": "artist-1", + "created": "2019-11-30T00:00:00Z", + "title": "", + "album": "", + "name": "album-2", + "songCount": 3, + "duration": 300, + "year": 2021 + }, + { + "id": "al-8", + "coverArt": "al-8", + "artistId": "ar-2", + "artist": "artist-1", + "created": "2019-11-30T00:00:00Z", + "title": "", + "album": "", + "name": "album-1", + "songCount": 3, + "duration": 300, + "year": 2021 + }, { "id": "al-12", "coverArt": "al-12", diff --git a/server/ctrlsubsonic/testdata/test_get_album_with_cover b/server/ctrlsubsonic/testdata/test_get_album_with_cover index 04688ad..05178ff 100644 --- a/server/ctrlsubsonic/testdata/test_get_album_with_cover +++ b/server/ctrlsubsonic/testdata/test_get_album_with_cover @@ -3,6 +3,7 @@ "status": "ok", "version": "1.15.0", "type": "gonic", + "serverVersion": "", "album": { "id": "al-3", "coverArt": "al-3", diff --git a/server/ctrlsubsonic/testdata/test_get_album_without_cover b/server/ctrlsubsonic/testdata/test_get_album_without_cover index a71d2c8..8fc1464 100644 --- a/server/ctrlsubsonic/testdata/test_get_album_without_cover +++ b/server/ctrlsubsonic/testdata/test_get_album_without_cover @@ -3,6 +3,7 @@ "status": "ok", "version": "1.15.0", "type": "gonic", + "serverVersion": "", "album": { "id": "al-2", "created": "2019-11-30T00:00:00Z", diff --git a/server/ctrlsubsonic/testdata/test_get_artist_id_one b/server/ctrlsubsonic/testdata/test_get_artist_id_one index 3e34cb1..201fdd8 100644 --- a/server/ctrlsubsonic/testdata/test_get_artist_id_one +++ b/server/ctrlsubsonic/testdata/test_get_artist_id_one @@ -3,6 +3,7 @@ "status": "ok", "version": "1.15.0", "type": "gonic", + "serverVersion": "", "artist": { "id": "ar-1", "name": "artist-0", diff --git a/server/ctrlsubsonic/testdata/test_get_artist_id_three b/server/ctrlsubsonic/testdata/test_get_artist_id_three index b29bc8b..30587c2 100644 --- a/server/ctrlsubsonic/testdata/test_get_artist_id_three +++ b/server/ctrlsubsonic/testdata/test_get_artist_id_three @@ -3,6 +3,7 @@ "status": "ok", "version": "1.15.0", "type": "gonic", + "serverVersion": "", "artist": { "id": "ar-3", "name": "artist-2", diff --git a/server/ctrlsubsonic/testdata/test_get_artist_id_two b/server/ctrlsubsonic/testdata/test_get_artist_id_two index ac1b598..68cf3b8 100644 --- a/server/ctrlsubsonic/testdata/test_get_artist_id_two +++ b/server/ctrlsubsonic/testdata/test_get_artist_id_two @@ -3,6 +3,7 @@ "status": "ok", "version": "1.15.0", "type": "gonic", + "serverVersion": "", "artist": { "id": "ar-2", "name": "artist-1", diff --git a/server/ctrlsubsonic/testdata/test_get_artists_no_args b/server/ctrlsubsonic/testdata/test_get_artists_no_args index 5a604e0..88cfdfa 100644 --- a/server/ctrlsubsonic/testdata/test_get_artists_no_args +++ b/server/ctrlsubsonic/testdata/test_get_artists_no_args @@ -3,6 +3,7 @@ "status": "ok", "version": "1.15.0", "type": "gonic", + "serverVersion": "", "artists": { "ignoredArticles": "", "index": [ diff --git a/server/ctrlsubsonic/testdata/test_get_artists_with_music_folder_1 b/server/ctrlsubsonic/testdata/test_get_artists_with_music_folder_1 index 5ca1d77..0ee73fa 100644 --- a/server/ctrlsubsonic/testdata/test_get_artists_with_music_folder_1 +++ b/server/ctrlsubsonic/testdata/test_get_artists_with_music_folder_1 @@ -3,6 +3,7 @@ "status": "ok", "version": "1.15.0", "type": "gonic", + "serverVersion": "", "artists": { "ignoredArticles": "", "index": [ diff --git a/server/ctrlsubsonic/testdata/test_get_artists_with_music_folder_2 b/server/ctrlsubsonic/testdata/test_get_artists_with_music_folder_2 index 5ca1d77..0ee73fa 100644 --- a/server/ctrlsubsonic/testdata/test_get_artists_with_music_folder_2 +++ b/server/ctrlsubsonic/testdata/test_get_artists_with_music_folder_2 @@ -3,6 +3,7 @@ "status": "ok", "version": "1.15.0", "type": "gonic", + "serverVersion": "", "artists": { "ignoredArticles": "", "index": [ diff --git a/server/ctrlsubsonic/testdata/test_get_indexes_no_args b/server/ctrlsubsonic/testdata/test_get_indexes_no_args index 53517a1..e6bf358 100644 --- a/server/ctrlsubsonic/testdata/test_get_indexes_no_args +++ b/server/ctrlsubsonic/testdata/test_get_indexes_no_args @@ -3,6 +3,7 @@ "status": "ok", "version": "1.15.0", "type": "gonic", + "serverVersion": "", "indexes": { "lastModified": 0, "ignoredArticles": "", diff --git a/server/ctrlsubsonic/testdata/test_get_indexes_with_music_folder_1 b/server/ctrlsubsonic/testdata/test_get_indexes_with_music_folder_1 index 91f3b1b..8b66d90 100644 --- a/server/ctrlsubsonic/testdata/test_get_indexes_with_music_folder_1 +++ b/server/ctrlsubsonic/testdata/test_get_indexes_with_music_folder_1 @@ -3,6 +3,7 @@ "status": "ok", "version": "1.15.0", "type": "gonic", + "serverVersion": "", "indexes": { "lastModified": 0, "ignoredArticles": "", diff --git a/server/ctrlsubsonic/testdata/test_get_indexes_with_music_folder_2 b/server/ctrlsubsonic/testdata/test_get_indexes_with_music_folder_2 index b869074..2eea427 100644 --- a/server/ctrlsubsonic/testdata/test_get_indexes_with_music_folder_2 +++ b/server/ctrlsubsonic/testdata/test_get_indexes_with_music_folder_2 @@ -3,6 +3,7 @@ "status": "ok", "version": "1.15.0", "type": "gonic", + "serverVersion": "", "indexes": { "lastModified": 0, "ignoredArticles": "", diff --git a/server/ctrlsubsonic/testdata/test_get_music_directory_with_tracks b/server/ctrlsubsonic/testdata/test_get_music_directory_with_tracks index e1052cb..b443127 100644 --- a/server/ctrlsubsonic/testdata/test_get_music_directory_with_tracks +++ b/server/ctrlsubsonic/testdata/test_get_music_directory_with_tracks @@ -3,6 +3,7 @@ "status": "ok", "version": "1.15.0", "type": "gonic", + "serverVersion": "", "directory": { "id": "al-3", "parent": "al-2", diff --git a/server/ctrlsubsonic/testdata/test_get_music_directory_without_tracks b/server/ctrlsubsonic/testdata/test_get_music_directory_without_tracks index bae65e9..1e38de8 100644 --- a/server/ctrlsubsonic/testdata/test_get_music_directory_without_tracks +++ b/server/ctrlsubsonic/testdata/test_get_music_directory_without_tracks @@ -3,6 +3,7 @@ "status": "ok", "version": "1.15.0", "type": "gonic", + "serverVersion": "", "directory": { "id": "al-2", "parent": "al-1", diff --git a/server/ctrlsubsonic/testdata/test_search_three_q_alb b/server/ctrlsubsonic/testdata/test_search_three_q_alb index 375d8b2..74a16c2 100644 --- a/server/ctrlsubsonic/testdata/test_search_three_q_alb +++ b/server/ctrlsubsonic/testdata/test_search_three_q_alb @@ -3,6 +3,7 @@ "status": "ok", "version": "1.15.0", "type": "gonic", + "serverVersion": "", "searchResult3": { "album": [ { diff --git a/server/ctrlsubsonic/testdata/test_search_three_q_art b/server/ctrlsubsonic/testdata/test_search_three_q_art index ab266d8..33a55f6 100644 --- a/server/ctrlsubsonic/testdata/test_search_three_q_art +++ b/server/ctrlsubsonic/testdata/test_search_three_q_art @@ -3,6 +3,7 @@ "status": "ok", "version": "1.15.0", "type": "gonic", + "serverVersion": "", "searchResult3": { "artist": [ { "id": "ar-1", "name": "artist-0", "albumCount": 3 }, diff --git a/server/ctrlsubsonic/testdata/test_search_three_q_tra b/server/ctrlsubsonic/testdata/test_search_three_q_tra index 92e98c1..d085a10 100644 --- a/server/ctrlsubsonic/testdata/test_search_three_q_tra +++ b/server/ctrlsubsonic/testdata/test_search_three_q_tra @@ -3,6 +3,7 @@ "status": "ok", "version": "1.15.0", "type": "gonic", + "serverVersion": "", "searchResult3": { "song": [ { diff --git a/server/ctrlsubsonic/testdata/test_search_two_q_alb b/server/ctrlsubsonic/testdata/test_search_two_q_alb index 4886557..99c49df 100644 --- a/server/ctrlsubsonic/testdata/test_search_two_q_alb +++ b/server/ctrlsubsonic/testdata/test_search_two_q_alb @@ -3,6 +3,7 @@ "status": "ok", "version": "1.15.0", "type": "gonic", + "serverVersion": "", "searchResult2": { "album": [ { diff --git a/server/ctrlsubsonic/testdata/test_search_two_q_art b/server/ctrlsubsonic/testdata/test_search_two_q_art index 7f6408e..ce0edb6 100644 --- a/server/ctrlsubsonic/testdata/test_search_two_q_art +++ b/server/ctrlsubsonic/testdata/test_search_two_q_art @@ -3,6 +3,7 @@ "status": "ok", "version": "1.15.0", "type": "gonic", + "serverVersion": "", "searchResult2": { "artist": [ { "id": "al-2", "parent": "al-1", "name": "artist-0" }, diff --git a/server/ctrlsubsonic/testdata/test_search_two_q_tra b/server/ctrlsubsonic/testdata/test_search_two_q_tra index 1b1ab6f..0457901 100644 --- a/server/ctrlsubsonic/testdata/test_search_two_q_tra +++ b/server/ctrlsubsonic/testdata/test_search_two_q_tra @@ -3,6 +3,7 @@ "status": "ok", "version": "1.15.0", "type": "gonic", + "serverVersion": "", "searchResult2": { "song": [ { diff --git a/version.go b/version.go index e708096..b23a444 100644 --- a/version.go +++ b/version.go @@ -3,13 +3,12 @@ package gonic import ( _ "embed" - "fmt" "strings" ) //go:embed version.txt var version string -var Version = fmt.Sprintf("v%s", strings.TrimSpace(version)) +var Version = strings.TrimSpace(version) const Name = "gonic" const NameUpper = "GONIC"