run gofumpt / format comments / comment blocks
This commit is contained in:
@@ -44,10 +44,8 @@ func runQueryCases(t *testing.T, h subsonicHandler, cases []*queryCase) {
|
||||
qc := qc // pin
|
||||
t.Run(qc.expectPath, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
//
|
||||
// ensure the handlers give us json
|
||||
qc.params.Add("f", "json")
|
||||
//
|
||||
// request from the handler in question
|
||||
req, _ := http.NewRequest("", "?"+qc.params.Encode(), nil)
|
||||
params := params.New(req)
|
||||
@@ -59,13 +57,11 @@ func runQueryCases(t *testing.T, h subsonicHandler, cases []*queryCase) {
|
||||
if status := rr.Code; status != http.StatusOK {
|
||||
t.Fatalf("didn't give a 200\n%s", body)
|
||||
}
|
||||
//
|
||||
// convert test name to query case path
|
||||
snake := testCamelExpr.ReplaceAllString(t.Name(), "${1}_${2}")
|
||||
lower := strings.ToLower(snake)
|
||||
relPath := strings.Replace(lower, "/", "_", -1)
|
||||
absExpPath := path.Join(testDataDir, relPath)
|
||||
//
|
||||
// read case to differ with handler result
|
||||
expected, err := jd.ReadJsonFile(absExpPath)
|
||||
if err != nil {
|
||||
@@ -80,7 +76,6 @@ func runQueryCases(t *testing.T, h subsonicHandler, cases []*queryCase) {
|
||||
diffOpts = append(diffOpts, jd.SET)
|
||||
}
|
||||
diff := expected.Diff(actual, diffOpts...)
|
||||
//
|
||||
// pass or fail
|
||||
if len(diff) == 0 {
|
||||
return
|
||||
|
||||
@@ -18,7 +18,6 @@ import (
|
||||
// we can't access artists. so instead we'll consider the artist of
|
||||
// an track to be the it's respective folder that comes directly
|
||||
// under the root directory
|
||||
|
||||
func (c *Controller) ServeGetIndexes(r *http.Request) *spec.Response {
|
||||
var folders []*db.Album
|
||||
c.DB.
|
||||
@@ -64,8 +63,7 @@ func (c *Controller) ServeGetMusicDirectory(r *http.Request) *spec.Response {
|
||||
childrenObj := []*spec.TrackChild{}
|
||||
folder := &db.Album{}
|
||||
c.DB.First(folder, id)
|
||||
//
|
||||
// start looking for child childFolders in the current dir
|
||||
// ** begin start looking for child childFolders in the current dir
|
||||
var childFolders []*db.Album
|
||||
c.DB.
|
||||
Where("parent_id=?", id).
|
||||
@@ -73,8 +71,7 @@ func (c *Controller) ServeGetMusicDirectory(r *http.Request) *spec.Response {
|
||||
for _, c := range childFolders {
|
||||
childrenObj = append(childrenObj, spec.NewTCAlbumByFolder(c))
|
||||
}
|
||||
//
|
||||
// start looking for child childTracks in the current dir
|
||||
// ** begin start looking for child childTracks in the current dir
|
||||
var childTracks []*db.Track
|
||||
c.DB.
|
||||
Where("album_id=?", id).
|
||||
@@ -90,8 +87,7 @@ func (c *Controller) ServeGetMusicDirectory(r *http.Request) *spec.Response {
|
||||
}
|
||||
childrenObj = append(childrenObj, toAppend)
|
||||
}
|
||||
//
|
||||
// respond section
|
||||
// ** begin respond section
|
||||
sub := spec.NewResponse()
|
||||
sub.Directory = spec.NewDirectoryByFolder(folder, childrenObj)
|
||||
return sub
|
||||
@@ -165,8 +161,7 @@ func (c *Controller) ServeSearchTwo(r *http.Request) *spec.Response {
|
||||
}
|
||||
query = fmt.Sprintf("%%%s%%", strings.TrimSuffix(query, "*"))
|
||||
results := &spec.SearchResultTwo{}
|
||||
//
|
||||
// search "artists"
|
||||
// ** begin search "artists"
|
||||
var artists []*db.Album
|
||||
c.DB.
|
||||
Where(`
|
||||
@@ -181,8 +176,7 @@ func (c *Controller) ServeSearchTwo(r *http.Request) *spec.Response {
|
||||
results.Artists = append(results.Artists,
|
||||
spec.NewDirectoryByFolder(a, nil))
|
||||
}
|
||||
//
|
||||
// search "albums"
|
||||
// ** begin search "albums"
|
||||
var albums []*db.Album
|
||||
c.DB.
|
||||
Where(`
|
||||
@@ -196,8 +190,7 @@ func (c *Controller) ServeSearchTwo(r *http.Request) *spec.Response {
|
||||
for _, a := range albums {
|
||||
results.Albums = append(results.Albums, spec.NewTCAlbumByFolder(a))
|
||||
}
|
||||
//
|
||||
// search tracks
|
||||
// ** begin search tracks
|
||||
var tracks []*db.Track
|
||||
c.DB.
|
||||
Preload("Album").
|
||||
|
||||
@@ -166,8 +166,7 @@ func (c *Controller) ServeSearchThree(r *http.Request) *spec.Response {
|
||||
query = fmt.Sprintf("%%%s%%",
|
||||
strings.TrimSuffix(query, "*"))
|
||||
results := &spec.SearchResultThree{}
|
||||
//
|
||||
// search "artists"
|
||||
// ** begin search "artists"
|
||||
var artists []*db.Artist
|
||||
c.DB.
|
||||
Where("name LIKE ? OR name_u_dec LIKE ?",
|
||||
@@ -179,8 +178,7 @@ func (c *Controller) ServeSearchThree(r *http.Request) *spec.Response {
|
||||
results.Artists = append(results.Artists,
|
||||
spec.NewArtistByTags(a))
|
||||
}
|
||||
//
|
||||
// search "albums"
|
||||
// ** begin search "albums"
|
||||
var albums []*db.Album
|
||||
c.DB.
|
||||
Preload("TagArtist").
|
||||
@@ -193,8 +191,7 @@ func (c *Controller) ServeSearchThree(r *http.Request) *spec.Response {
|
||||
results.Albums = append(results.Albums,
|
||||
spec.NewAlbumByTags(a, a.TagArtist))
|
||||
}
|
||||
//
|
||||
// search tracks
|
||||
// ** begin search tracks
|
||||
var tracks []*db.Track
|
||||
c.DB.
|
||||
Preload("Album").
|
||||
@@ -287,7 +284,6 @@ func (c *Controller) ServeGetGenres(r *http.Request) *spec.Response {
|
||||
(SELECT count(id) FROM tracks WHERE tag_genre_id=genres.id) track_count`).
|
||||
Group("genres.id").
|
||||
Find(&genres)
|
||||
|
||||
sub := spec.NewResponse()
|
||||
sub.Genres = &spec.Genres{
|
||||
List: make([]*spec.Genre, len(genres)),
|
||||
@@ -304,10 +300,8 @@ func (c *Controller) ServeGetSongsByGenre(r *http.Request) *spec.Response {
|
||||
if genre == "" {
|
||||
return spec.NewError(10, "please provide an `genre` parameter")
|
||||
}
|
||||
|
||||
// TODO: add musicFolderId parameter:
|
||||
// (Since 1.12.0) Only return albums in the music folder with the given ID.
|
||||
|
||||
// TODO: add musicFolderId parameter
|
||||
// (since 1.12.0) only return albums in the music folder with the given id
|
||||
var tracks []*db.Track
|
||||
c.DB.
|
||||
Joins("JOIN albums ON tracks.album_id=albums.id").
|
||||
@@ -316,7 +310,6 @@ func (c *Controller) ServeGetSongsByGenre(r *http.Request) *spec.Response {
|
||||
Offset(params.GetIntOr("offset", 0)).
|
||||
Limit(params.GetIntOr("count", 10)).
|
||||
Find(&tracks)
|
||||
|
||||
sub := spec.NewResponse()
|
||||
sub.TracksByGenre = &spec.TracksByGenre{
|
||||
List: make([]*spec.TrackChild, len(tracks)),
|
||||
|
||||
@@ -287,13 +287,11 @@ func (c *Controller) ServeGetSong(r *http.Request) *spec.Response {
|
||||
func (c *Controller) ServeGetRandomSongs(r *http.Request) *spec.Response {
|
||||
params := r.Context().Value(CtxParams).(params.Params)
|
||||
var tracks []*db.Track
|
||||
|
||||
q := c.DB.DB.
|
||||
Joins("JOIN albums ON tracks.album_id=albums.id").
|
||||
Limit(params.GetIntOr("size", 10)).
|
||||
Preload("Album").
|
||||
Order(gorm.Expr("random()"))
|
||||
|
||||
if year, err := params.GetInt("fromYear"); err == nil {
|
||||
q = q.Where("albums.tag_year >= ?", year)
|
||||
}
|
||||
@@ -307,7 +305,6 @@ func (c *Controller) ServeGetRandomSongs(r *http.Request) *spec.Response {
|
||||
)
|
||||
}
|
||||
q.Find(&tracks)
|
||||
|
||||
sub := spec.NewResponse()
|
||||
sub.RandomTracks = &spec.RandomTracks{}
|
||||
sub.RandomTracks.List = make([]*spec.TrackChild, len(tracks))
|
||||
|
||||
@@ -20,7 +20,6 @@ import (
|
||||
// a) write to response writer
|
||||
// b) return a non-nil spec.Response
|
||||
// _but not both_
|
||||
|
||||
func (c *Controller) ServeGetCoverArt(w http.ResponseWriter, r *http.Request) *spec.Response {
|
||||
params := r.Context().Value(CtxParams).(params.Params)
|
||||
id, err := params.GetInt("id")
|
||||
|
||||
@@ -75,8 +75,8 @@ func NewArtistByTags(a *db.Artist) *Artist {
|
||||
|
||||
func NewGenre(g *db.Genre) *Genre {
|
||||
return &Genre{
|
||||
Name: g.Name,
|
||||
Name: g.Name,
|
||||
AlbumCount: g.AlbumCount,
|
||||
SongCount: g.TrackCount,
|
||||
SongCount: g.TrackCount,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,6 @@ func NewResponse() *Response {
|
||||
// 50 user is not authorized for the given operation
|
||||
// 60 the trial period for the subsonic server is over
|
||||
// 70 the requested data was not found
|
||||
|
||||
type Error struct {
|
||||
Code int `xml:"code,attr" json:"code"`
|
||||
Message string `xml:"message,attr" json:"message"`
|
||||
|
||||
BIN
server/ctrlsubsonic/testdata/db
vendored
BIN
server/ctrlsubsonic/testdata/db
vendored
Binary file not shown.
Reference in New Issue
Block a user