mirror of
https://github.com/navidrome/navidrome.git
synced 2025-08-10 00:52:20 +00:00
separate responses from model
This commit is contained in:
@@ -10,17 +10,17 @@ import (
|
||||
)
|
||||
|
||||
type Line struct {
|
||||
Start *int64 `structs:"start,omitempty" xml:"start,attr,omitempty" json:"start,omitempty"`
|
||||
Value string `structs:"value" xml:"value" json:"value"`
|
||||
Start *int64 `structs:"start,omitempty" json:"start,omitempty"`
|
||||
Value string `structs:"value" json:"value"`
|
||||
}
|
||||
|
||||
type Lyric struct {
|
||||
DisplayArtist string `structs:"displayArtist,omitempty" xml:"displayArtist,attr,omitempty" json:"displayArtist,omitempty"`
|
||||
DisplayTitle string `structs:"displayTitle,omitempty" xml:"displayTitle,attr,omitempty" json:"displayTitle,omitempty"`
|
||||
Lang string `structs:"lang" xml:"lang,attr" json:"lang"`
|
||||
Line []Line `structs:"line" xml:"line" json:"line"`
|
||||
Offset *int64 `structs:"offset,omitempty" xml:"offset,attr,omitempty" json:"offset,omitempty"`
|
||||
Synced bool `structs:"synced" xml:"synced,attr" json:"synced"`
|
||||
DisplayArtist string `structs:"displayArtist,omitempty" json:"displayArtist,omitempty"`
|
||||
DisplayTitle string `structs:"displayTitle,omitempty" json:"displayTitle,omitempty"`
|
||||
Lang string `structs:"lang" json:"lang"`
|
||||
Line []Line `structs:"line" json:"line"`
|
||||
Offset *int64 `structs:"offset,omitempty" json:"offset,omitempty"`
|
||||
Synced bool `structs:"synced" json:"synced"`
|
||||
}
|
||||
|
||||
// support the standard [mm:ss.mm], as well as [hh:*] and [*.mmm]
|
||||
|
||||
@@ -320,3 +320,38 @@ func buildAlbumID3(ctx context.Context, album model.Album) responses.AlbumID3 {
|
||||
dir.SortName = album.SortAlbumName
|
||||
return dir
|
||||
}
|
||||
|
||||
func buildStructuredLyric(lyric model.Lyric) responses.StructuredLyric {
|
||||
lines := make([]responses.Line, len(lyric.Line))
|
||||
|
||||
for i, line := range lyric.Line {
|
||||
lines[i] = responses.Line{
|
||||
Start: line.Start,
|
||||
Value: line.Value,
|
||||
}
|
||||
}
|
||||
|
||||
structured := responses.StructuredLyric{
|
||||
DisplayArtist: lyric.DisplayArtist,
|
||||
DisplayTitle: lyric.DisplayTitle,
|
||||
Lang: lyric.Lang,
|
||||
Line: lines,
|
||||
Offset: lyric.Offset,
|
||||
Synced: lyric.Synced,
|
||||
}
|
||||
|
||||
return structured
|
||||
}
|
||||
|
||||
func buildStructuredLyrics(lyrics model.Lyrics) *responses.LyricsList {
|
||||
lyricList := make(responses.StructuredLyrics, len(lyrics))
|
||||
|
||||
for i, lyric := range lyrics {
|
||||
lyricList[i] = buildStructuredLyric(lyric)
|
||||
}
|
||||
|
||||
res := &responses.LyricsList{
|
||||
StructuredLyrics: lyricList,
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
@@ -139,10 +139,7 @@ func (api *Router) GetLyricsBySongId(r *http.Request) (*responses.Subsonic, erro
|
||||
}
|
||||
|
||||
response := newResponse()
|
||||
allLyrics := responses.LyricsList{
|
||||
StructuredLyrics: lyrics,
|
||||
}
|
||||
response.LyricsList = &allLyrics
|
||||
response.LyricsList = buildStructuredLyrics(lyrics)
|
||||
|
||||
return response, nil
|
||||
}
|
||||
|
||||
@@ -169,11 +169,11 @@ var _ = Describe("MediaRetrievalController", func() {
|
||||
response, err := router.GetLyricsBySongId(r)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
compareResponses(response.LyricsList, responses.LyricsList{
|
||||
StructuredLyrics: model.Lyrics{
|
||||
StructuredLyrics: responses.StructuredLyrics{
|
||||
{
|
||||
Lang: "eng",
|
||||
Synced: true,
|
||||
Line: []model.Line{
|
||||
Line: []responses.Line{
|
||||
{
|
||||
Start: ×[0],
|
||||
Value: "We're no strangers to love",
|
||||
@@ -187,7 +187,7 @@ var _ = Describe("MediaRetrievalController", func() {
|
||||
{
|
||||
Lang: "xxx",
|
||||
Synced: false,
|
||||
Line: []model.Line{
|
||||
Line: []responses.Line{
|
||||
{
|
||||
Value: "We're no strangers to love",
|
||||
},
|
||||
@@ -221,13 +221,13 @@ var _ = Describe("MediaRetrievalController", func() {
|
||||
|
||||
offset := int64(-100)
|
||||
compareResponses(response.LyricsList, responses.LyricsList{
|
||||
StructuredLyrics: model.Lyrics{
|
||||
StructuredLyrics: responses.StructuredLyrics{
|
||||
{
|
||||
DisplayArtist: "Rick Astley",
|
||||
DisplayTitle: "That one song",
|
||||
Lang: "eng",
|
||||
Synced: true,
|
||||
Line: []model.Line{
|
||||
Line: []responses.Line{
|
||||
{
|
||||
Start: ×[0],
|
||||
Value: "We're no strangers to love",
|
||||
|
||||
@@ -4,8 +4,6 @@ import (
|
||||
"encoding/json"
|
||||
"encoding/xml"
|
||||
"time"
|
||||
|
||||
"github.com/navidrome/navidrome/model"
|
||||
)
|
||||
|
||||
type Subsonic struct {
|
||||
@@ -448,8 +446,24 @@ type JukeboxPlaylist struct {
|
||||
JukeboxStatus
|
||||
Entry []Child `xml:"entry,omitempty" json:"entry,omitempty"`
|
||||
}
|
||||
|
||||
type Line struct {
|
||||
Start *int64 `xml:"start,attr,omitempty" json:"start,omitempty"`
|
||||
Value string `xml:"value" json:"value"`
|
||||
}
|
||||
|
||||
type StructuredLyric struct {
|
||||
DisplayArtist string `xml:"displayArtist,attr,omitempty" json:"displayArtist,omitempty"`
|
||||
DisplayTitle string `xml:"displayTitle,attr,omitempty" json:"displayTitle,omitempty"`
|
||||
Lang string `xml:"lang,attr" json:"lang"`
|
||||
Line []Line `xml:"line" json:"line"`
|
||||
Offset *int64 `xml:"offset,attr,omitempty" json:"offset,omitempty"`
|
||||
Synced bool `xml:"synced,attr" json:"synced"`
|
||||
}
|
||||
|
||||
type StructuredLyrics []StructuredLyric
|
||||
type LyricsList struct {
|
||||
StructuredLyrics model.Lyrics `xml:"structuredLyrics,omitempty" json:"structuredLyrics,omitempty"`
|
||||
StructuredLyrics []StructuredLyric `xml:"structuredLyrics,omitempty" json:"structuredLyrics,omitempty"`
|
||||
}
|
||||
|
||||
type OpenSubsonicExtension struct {
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/navidrome/navidrome/consts"
|
||||
"github.com/navidrome/navidrome/model"
|
||||
. "github.com/navidrome/navidrome/server/subsonic/responses"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
@@ -815,11 +814,11 @@ var _ = Describe("Responses", func() {
|
||||
BeforeEach(func() {
|
||||
times := []int64{int64(18800), int64(22801)}
|
||||
|
||||
response.LyricsList.StructuredLyrics = model.Lyrics{
|
||||
response.LyricsList.StructuredLyrics = StructuredLyrics{
|
||||
{
|
||||
Lang: "eng",
|
||||
Synced: true,
|
||||
Line: []model.Line{
|
||||
Line: []Line{
|
||||
{
|
||||
Start: ×[0],
|
||||
Value: "We're no strangers to love",
|
||||
@@ -833,7 +832,7 @@ var _ = Describe("Responses", func() {
|
||||
{
|
||||
Lang: "xxx",
|
||||
Synced: false,
|
||||
Line: []model.Line{
|
||||
Line: []Line{
|
||||
{
|
||||
Value: "We're no strangers to love",
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user