Skip to content

Commit

Permalink
feat(sunsonic): expose type serverVersion in subsonic responses
Browse files Browse the repository at this point in the history
  • Loading branch information
sentriz committed Apr 8, 2023
1 parent 3974b0d commit b8fceae
Show file tree
Hide file tree
Showing 32 changed files with 94 additions and 60 deletions.
4 changes: 2 additions & 2 deletions cmd/gonic/gonic.go
Expand Up @@ -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", "")
Expand Down
2 changes: 1 addition & 1 deletion server/ctrladmin/adminui/components.tmpl
Expand Up @@ -62,7 +62,7 @@
{{ end }}
{{ slot }}
<div class="px-5 text-right whitespace-nowrap">
<span class="text-gray-500">{{ .Version }}</span>
<span class="text-gray-500">v{{ .Version }}</span>
senan kelly, 2020
<span class="text-gray-500">&#124;</span>
{{ component "ext_link" (props . "To" "https://github.com/sentriz/gonic") }}github{{ end }}
Expand Down
2 changes: 2 additions & 0 deletions server/ctrlsubsonic/ctrl_test.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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())
}
24 changes: 15 additions & 9 deletions server/ctrlsubsonic/spec/spec.go
Expand Up @@ -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"`
Expand Down Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -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,
}
}

Expand Down
Expand Up @@ -3,6 +3,7 @@
"status": "ok",
"version": "1.15.0",
"type": "gonic",
"serverVersion": "",
"albumList": {
"album": [
{
Expand Down
Expand Up @@ -3,6 +3,7 @@
"status": "ok",
"version": "1.15.0",
"type": "gonic",
"serverVersion": "",
"albumList": {
"album": [
{
Expand Down
1 change: 1 addition & 0 deletions server/ctrlsubsonic/testdata/test_get_album_list_newest
Expand Up @@ -3,6 +3,7 @@
"status": "ok",
"version": "1.15.0",
"type": "gonic",
"serverVersion": "",
"albumList": {
"album": [
{
Expand Down
39 changes: 20 additions & 19 deletions server/ctrlsubsonic/testdata/test_get_album_list_random
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Expand Up @@ -3,6 +3,7 @@
"status": "ok",
"version": "1.15.0",
"type": "gonic",
"serverVersion": "",
"albumList2": {
"album": [
{
Expand Down
Expand Up @@ -3,6 +3,7 @@
"status": "ok",
"version": "1.15.0",
"type": "gonic",
"serverVersion": "",
"albumList2": {
"album": [
{
Expand Down
Expand Up @@ -3,6 +3,7 @@
"status": "ok",
"version": "1.15.0",
"type": "gonic",
"serverVersion": "",
"albumList2": {
"album": [
{
Expand Down
55 changes: 28 additions & 27 deletions server/ctrlsubsonic/testdata/test_get_album_list_two_random
Expand Up @@ -3,30 +3,31 @@
"status": "ok",
"version": "1.15.0",
"type": "gonic",
"serverVersion": "",
"albumList2": {
"album": [
{
"id": "al-3",
"coverArt": "al-3",
"artistId": "ar-1",
"artist": "artist-0",
"id": "al-13",
"coverArt": "al-13",
"artistId": "ar-3",
"artist": "artist-2",
"created": "2019-11-30T00:00:00Z",
"title": "",
"album": "",
"name": "album-0",
"name": "album-2",
"songCount": 3,
"duration": 300,
"year": 2021
},
{
"id": "al-5",
"coverArt": "al-5",
"id": "al-4",
"coverArt": "al-4",
"artistId": "ar-1",
"artist": "artist-0",
"created": "2019-11-30T00:00:00Z",
"title": "",
"album": "",
"name": "album-2",
"name": "album-1",
"songCount": 3,
"duration": 300,
"year": 2021
Expand All @@ -45,66 +46,66 @@
"year": 2021
},
{
"id": "al-9",
"coverArt": "al-9",
"artistId": "ar-2",
"artist": "artist-1",
"id": "al-3",
"coverArt": "al-3",
"artistId": "ar-1",
"artist": "artist-0",
"created": "2019-11-30T00:00:00Z",
"title": "",
"album": "",
"name": "album-2",
"name": "album-0",
"songCount": 3,
"duration": 300,
"year": 2021
},
{
"id": "al-13",
"coverArt": "al-13",
"artistId": "ar-3",
"artist": "artist-2",
"id": "al-7",
"coverArt": "al-7",
"artistId": "ar-2",
"artist": "artist-1",
"created": "2019-11-30T00:00:00Z",
"title": "",
"album": "",
"name": "album-2",
"name": "album-0",
"songCount": 3,
"duration": 300,
"year": 2021
},
{
"id": "al-4",
"coverArt": "al-4",
"id": "al-5",
"coverArt": "al-5",
"artistId": "ar-1",
"artist": "artist-0",
"created": "2019-11-30T00:00:00Z",
"title": "",
"album": "",
"name": "album-1",
"name": "album-2",
"songCount": 3,
"duration": 300,
"year": 2021
},
{
"id": "al-8",
"coverArt": "al-8",
"id": "al-9",
"coverArt": "al-9",
"artistId": "ar-2",
"artist": "artist-1",
"created": "2019-11-30T00:00:00Z",
"title": "",
"album": "",
"name": "album-1",
"name": "album-2",
"songCount": 3,
"duration": 300,
"year": 2021
},
{
"id": "al-7",
"coverArt": "al-7",
"id": "al-8",
"coverArt": "al-8",
"artistId": "ar-2",
"artist": "artist-1",
"created": "2019-11-30T00:00:00Z",
"title": "",
"album": "",
"name": "album-0",
"name": "album-1",
"songCount": 3,
"duration": 300,
"year": 2021
Expand Down
1 change: 1 addition & 0 deletions server/ctrlsubsonic/testdata/test_get_album_with_cover
Expand Up @@ -3,6 +3,7 @@
"status": "ok",
"version": "1.15.0",
"type": "gonic",
"serverVersion": "",
"album": {
"id": "al-3",
"coverArt": "al-3",
Expand Down
1 change: 1 addition & 0 deletions server/ctrlsubsonic/testdata/test_get_album_without_cover
Expand Up @@ -3,6 +3,7 @@
"status": "ok",
"version": "1.15.0",
"type": "gonic",
"serverVersion": "",
"album": {
"id": "al-2",
"created": "2019-11-30T00:00:00Z",
Expand Down
1 change: 1 addition & 0 deletions server/ctrlsubsonic/testdata/test_get_artist_id_one
Expand Up @@ -3,6 +3,7 @@
"status": "ok",
"version": "1.15.0",
"type": "gonic",
"serverVersion": "",
"artist": {
"id": "ar-1",
"name": "artist-0",
Expand Down
1 change: 1 addition & 0 deletions server/ctrlsubsonic/testdata/test_get_artist_id_three
Expand Up @@ -3,6 +3,7 @@
"status": "ok",
"version": "1.15.0",
"type": "gonic",
"serverVersion": "",
"artist": {
"id": "ar-3",
"name": "artist-2",
Expand Down
1 change: 1 addition & 0 deletions server/ctrlsubsonic/testdata/test_get_artist_id_two
Expand Up @@ -3,6 +3,7 @@
"status": "ok",
"version": "1.15.0",
"type": "gonic",
"serverVersion": "",
"artist": {
"id": "ar-2",
"name": "artist-1",
Expand Down
1 change: 1 addition & 0 deletions server/ctrlsubsonic/testdata/test_get_artists_no_args
Expand Up @@ -3,6 +3,7 @@
"status": "ok",
"version": "1.15.0",
"type": "gonic",
"serverVersion": "",
"artists": {
"ignoredArticles": "",
"index": [
Expand Down
Expand Up @@ -3,6 +3,7 @@
"status": "ok",
"version": "1.15.0",
"type": "gonic",
"serverVersion": "",
"artists": {
"ignoredArticles": "",
"index": [
Expand Down
Expand Up @@ -3,6 +3,7 @@
"status": "ok",
"version": "1.15.0",
"type": "gonic",
"serverVersion": "",
"artists": {
"ignoredArticles": "",
"index": [
Expand Down
1 change: 1 addition & 0 deletions server/ctrlsubsonic/testdata/test_get_indexes_no_args
Expand Up @@ -3,6 +3,7 @@
"status": "ok",
"version": "1.15.0",
"type": "gonic",
"serverVersion": "",
"indexes": {
"lastModified": 0,
"ignoredArticles": "",
Expand Down

0 comments on commit b8fceae

Please sign in to comment.