Merge branch 'master' into ldap_auth

This commit is contained in:
Daniel
2023-12-08 23:12:25 -08:00
committed by GitHub
28 changed files with 473 additions and 333 deletions

No files matched your search

+18 -4
View File
@@ -10,6 +10,7 @@ import (
"io"
"log"
"net/http"
"time"
"go.senan.xyz/gonic/db"
"go.senan.xyz/gonic/handlerutil"
@@ -96,6 +97,10 @@ func New(dbc *db.DB, scannr *scanner.Scanner, musicPaths []MusicPath, podcastsPa
withRequiredParams,
c.withUser,
)
chainRaw := handlerutil.Chain(
chain,
slow,
)
c.Handle("/getLicense", chain(resp(c.ServeGetLicence)))
c.Handle("/ping", chain(resp(c.ServePing)))
@@ -126,10 +131,10 @@ func New(dbc *db.DB, scannr *scanner.Scanner, musicPaths []MusicPath, podcastsPa
c.Handle("/getLyrics", chain(resp(c.ServeGetLyrics)))
// raw
c.Handle("/getCoverArt", chain(respRaw(c.ServeGetCoverArt)))
c.Handle("/stream", chain(respRaw(c.ServeStream)))
c.Handle("/download", chain(respRaw(c.ServeStream)))
c.Handle("/getAvatar", chain(respRaw(c.ServeGetAvatar)))
c.Handle("/getCoverArt", chainRaw(respRaw(c.ServeGetCoverArt)))
c.Handle("/stream", chainRaw(respRaw(c.ServeStream)))
c.Handle("/download", chainRaw(respRaw(c.ServeStream)))
c.Handle("/getAvatar", chainRaw(respRaw(c.ServeGetAvatar)))
// browse by tag
c.Handle("/getAlbum", chain(resp(c.ServeGetAlbum)))
@@ -375,6 +380,15 @@ func createLDAPconnection(tls string, fqdn string, port string) (*ldap.Conn, err
return l, nil
}
func slow(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
rc := http.NewResponseController(w) //nolint:bodyclose
_ = rc.SetWriteDeadline(time.Time{}) // set no deadline, since we're probably streaming
_ = rc.SetReadDeadline(time.Time{}) // set no deadline, since we're probably streaming
next.ServeHTTP(w, r)
})
}
func checkCredsToken(password, token, salt string) bool {
toHash := fmt.Sprintf("%s%s", password, salt)
hash := md5.Sum([]byte(toHash))
+21
View File
@@ -15,6 +15,7 @@ import (
"testing"
jd "github.com/josephburnett/jd/lib"
"github.com/stretchr/testify/require"
"go.senan.xyz/gonic"
"go.senan.xyz/gonic/db"
@@ -163,3 +164,23 @@ func makec(tb testing.TB, roots []string, audio bool) *Controller {
return contr
}
func TestParams(t *testing.T) {
t.Parallel()
handler := withParams(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
params := r.Context().Value(CtxParams).(params.Params)
require.Equal(t, "Client", params.GetOr("c", ""))
}))
params := url.Values{}
params.Set("c", "Client")
r, err := http.NewRequest(http.MethodGet, "/?"+params.Encode(), nil)
require.NoError(t, err)
handler.ServeHTTP(nil, r)
r, err = http.NewRequest(http.MethodPost, "/", strings.NewReader(params.Encode()))
require.NoError(t, err)
r.Header.Set("Content-Type", "application/x-www-form-urlencoded")
handler.ServeHTTP(nil, r)
}
+5
View File
@@ -40,6 +40,7 @@ func (c *Controller) ServeGetOpenSubsonicExtensions(_ *http.Request) *spec.Respo
sub := spec.NewResponse()
sub.OpenSubsonicExtensions = &spec.OpenSubsonicExtensions{
{Name: "transcodeOffset", Versions: []int{1}},
{Name: "formPost", Versions: []int{1}},
}
return sub
}
@@ -332,6 +333,10 @@ func (c *Controller) ServeGetRandomSongs(r *http.Request) *spec.Response {
var errNotATrack = errors.New("not a track")
func (c *Controller) ServeJukebox(r *http.Request) *spec.Response { // nolint:gocyclo
if c.jukebox == nil {
return spec.NewError(0, "jukebox not enabled")
}
params := r.Context().Value(CtxParams).(params.Params)
trackPaths := func(ids []specid.ID) ([]string, error) {
var paths []string
@@ -74,6 +74,7 @@ func NewTCTrackByFolder(t *db.Track, parent *db.Album) *TrackChild {
Bitrate: t.Bitrate,
IsDir: false,
Type: "music",
MusicBrainzID: t.TagBrainzID,
CreatedAt: t.CreatedAt,
AverageRating: formatRating(t.AverageRating),
}
@@ -77,6 +77,7 @@ func NewTrackByTags(t *db.Track, album *db.Album) *TrackChild {
TrackNumber: t.TagTrackNumber,
DiscNumber: t.TagDiscNumber,
Type: "music",
MusicBrainzID: t.TagBrainzID,
Year: album.TagYear,
AverageRating: formatRating(t.AverageRating),
TranscodeMeta: TranscodeMeta{},
+3
View File
@@ -200,6 +200,9 @@ type TrackChild struct {
DiscNumber int `xml:"discNumber,attr,omitempty" json:"discNumber,omitempty"`
Type string `xml:"type,attr,omitempty" json:"type,omitempty"`
Year int `xml:"year,attr,omitempty" json:"year,omitempty"`
MusicBrainzID string `xml:"musicBrainzId,attr" json:"musicBrainzId"`
// star / rating
Starred *time.Time `xml:"starred,attr,omitempty" json:"starred,omitempty"`
UserRating int `xml:"userRating,attr,omitempty" json:"userRating,omitempty"`
+38 -38
View File
@@ -8,16 +8,31 @@
"albumList": {
"album": [
{
"id": "al-4",
"id": "al-12",
"created": "2019-11-30T00:00:00Z",
"artist": "artist-0",
"artist": "artist-2",
"artists": null,
"displayArtist": "",
"title": "album-1",
"album": "album-1",
"parent": "al-2",
"parent": "al-10",
"isDir": true,
"coverArt": "al-4",
"coverArt": "al-12",
"name": "album-1",
"songCount": 3,
"duration": 300
},
{
"id": "al-8",
"created": "2019-11-30T00:00:00Z",
"artist": "artist-1",
"artists": null,
"displayArtist": "",
"title": "album-1",
"album": "album-1",
"parent": "al-6",
"isDir": true,
"coverArt": "al-8",
"name": "album-1",
"songCount": 3,
"duration": 300
@@ -38,16 +53,31 @@
"duration": 300
},
{
"id": "al-12",
"id": "al-9",
"created": "2019-11-30T00:00:00Z",
"artist": "artist-2",
"artist": "artist-1",
"artists": null,
"displayArtist": "",
"title": "album-2",
"album": "album-2",
"parent": "al-6",
"isDir": true,
"coverArt": "al-9",
"name": "album-2",
"songCount": 3,
"duration": 300
},
{
"id": "al-4",
"created": "2019-11-30T00:00:00Z",
"artist": "artist-0",
"artists": null,
"displayArtist": "",
"title": "album-1",
"album": "album-1",
"parent": "al-10",
"parent": "al-2",
"isDir": true,
"coverArt": "al-12",
"coverArt": "al-4",
"name": "album-1",
"songCount": 3,
"duration": 300
@@ -111,36 +141,6 @@
"name": "album-0",
"songCount": 3,
"duration": 300
},
{
"id": "al-9",
"created": "2019-11-30T00:00:00Z",
"artist": "artist-1",
"artists": null,
"displayArtist": "",
"title": "album-2",
"album": "album-2",
"parent": "al-6",
"isDir": true,
"coverArt": "al-9",
"name": "album-2",
"songCount": 3,
"duration": 300
},
{
"id": "al-8",
"created": "2019-11-30T00:00:00Z",
"artist": "artist-1",
"artists": null,
"displayArtist": "",
"title": "album-1",
"album": "album-1",
"parent": "al-6",
"isDir": true,
"coverArt": "al-8",
"name": "album-1",
"songCount": 3,
"duration": 300
}
]
}
+74 -74
View File
@@ -8,61 +8,16 @@
"albumList2": {
"album": [
{
"id": "al-12",
"created": "2019-11-30T00:00:00Z",
"artistId": "ar-3",
"artist": "artist-2",
"artists": [{ "id": "ar-3", "name": "artist-2" }],
"displayArtist": "artist-2",
"title": "album-1",
"album": "album-1",
"coverArt": "al-12",
"name": "album-1",
"songCount": 3,
"duration": 300,
"year": 2021
},
{
"id": "al-11",
"created": "2019-11-30T00:00:00Z",
"artistId": "ar-3",
"artist": "artist-2",
"artists": [{ "id": "ar-3", "name": "artist-2" }],
"displayArtist": "artist-2",
"title": "album-0",
"album": "album-0",
"coverArt": "al-11",
"name": "album-0",
"songCount": 3,
"duration": 300,
"year": 2021
},
{
"id": "al-13",
"created": "2019-11-30T00:00:00Z",
"artistId": "ar-3",
"artist": "artist-2",
"artists": [{ "id": "ar-3", "name": "artist-2" }],
"displayArtist": "artist-2",
"title": "album-2",
"album": "album-2",
"coverArt": "al-13",
"name": "album-2",
"songCount": 3,
"duration": 300,
"year": 2021
},
{
"id": "al-9",
"id": "al-7",
"created": "2019-11-30T00:00:00Z",
"artistId": "ar-2",
"artist": "artist-1",
"artists": [{ "id": "ar-2", "name": "artist-1" }],
"displayArtist": "artist-1",
"title": "album-2",
"album": "album-2",
"coverArt": "al-9",
"name": "album-2",
"title": "album-0",
"album": "album-0",
"coverArt": "al-7",
"name": "album-0",
"songCount": 3,
"duration": 300,
"year": 2021
@@ -83,31 +38,16 @@
"year": 2021
},
{
"id": "al-7",
"id": "al-12",
"created": "2019-11-30T00:00:00Z",
"artistId": "ar-2",
"artist": "artist-1",
"artists": [{ "id": "ar-2", "name": "artist-1" }],
"displayArtist": "artist-1",
"title": "album-0",
"album": "album-0",
"coverArt": "al-7",
"name": "album-0",
"songCount": 3,
"duration": 300,
"year": 2021
},
{
"id": "al-5",
"created": "2019-11-30T00:00:00Z",
"artistId": "ar-1",
"artist": "artist-0",
"artists": [{ "id": "ar-1", "name": "artist-0" }],
"displayArtist": "artist-0",
"title": "album-2",
"album": "album-2",
"coverArt": "al-5",
"name": "album-2",
"artistId": "ar-3",
"artist": "artist-2",
"artists": [{ "id": "ar-3", "name": "artist-2" }],
"displayArtist": "artist-2",
"title": "album-1",
"album": "album-1",
"coverArt": "al-12",
"name": "album-1",
"songCount": 3,
"duration": 300,
"year": 2021
@@ -141,6 +81,66 @@
"songCount": 3,
"duration": 300,
"year": 2021
},
{
"id": "al-9",
"created": "2019-11-30T00:00:00Z",
"artistId": "ar-2",
"artist": "artist-1",
"artists": [{ "id": "ar-2", "name": "artist-1" }],
"displayArtist": "artist-1",
"title": "album-2",
"album": "album-2",
"coverArt": "al-9",
"name": "album-2",
"songCount": 3,
"duration": 300,
"year": 2021
},
{
"id": "al-5",
"created": "2019-11-30T00:00:00Z",
"artistId": "ar-1",
"artist": "artist-0",
"artists": [{ "id": "ar-1", "name": "artist-0" }],
"displayArtist": "artist-0",
"title": "album-2",
"album": "album-2",
"coverArt": "al-5",
"name": "album-2",
"songCount": 3,
"duration": 300,
"year": 2021
},
{
"id": "al-13",
"created": "2019-11-30T00:00:00Z",
"artistId": "ar-3",
"artist": "artist-2",
"artists": [{ "id": "ar-3", "name": "artist-2" }],
"displayArtist": "artist-2",
"title": "album-2",
"album": "album-2",
"coverArt": "al-13",
"name": "album-2",
"songCount": 3,
"duration": 300,
"year": 2021
},
{
"id": "al-11",
"created": "2019-11-30T00:00:00Z",
"artistId": "ar-3",
"artist": "artist-2",
"artists": [{ "id": "ar-3", "name": "artist-2" }],
"displayArtist": "artist-2",
"title": "album-0",
"album": "album-0",
"coverArt": "al-11",
"name": "album-0",
"songCount": 3,
"duration": 300,
"year": 2021
}
]
}
+6 -3
View File
@@ -46,7 +46,8 @@
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
"year": 2021,
"musicBrainzId": ""
},
{
"id": "tr-2",
@@ -72,7 +73,8 @@
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
"year": 2021,
"musicBrainzId": ""
},
{
"id": "tr-3",
@@ -98,7 +100,8 @@
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
"year": 2021,
"musicBrainzId": ""
}
]
}
@@ -32,7 +32,8 @@
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
"year": 2021,
"musicBrainzId": ""
},
{
"id": "tr-2",
@@ -56,7 +57,8 @@
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
"year": 2021,
"musicBrainzId": ""
},
{
"id": "tr-3",
@@ -80,7 +82,8 @@
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
"year": 2021,
"musicBrainzId": ""
}
]
}
@@ -22,7 +22,8 @@
"isDir": true,
"isVideo": false,
"parent": "al-2",
"title": "album-0"
"title": "album-0",
"musicBrainzId": ""
},
{
"id": "al-4",
@@ -36,7 +37,8 @@
"isDir": true,
"isVideo": false,
"parent": "al-2",
"title": "album-1"
"title": "album-1",
"musicBrainzId": ""
},
{
"id": "al-5",
@@ -50,7 +52,8 @@
"isDir": true,
"isVideo": false,
"parent": "al-2",
"title": "album-2"
"title": "album-2",
"musicBrainzId": ""
}
]
}
+40 -20
View File
@@ -33,7 +33,8 @@
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
"year": 2021,
"musicBrainzId": ""
},
{
"id": "tr-2",
@@ -61,7 +62,8 @@
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
"year": 2021,
"musicBrainzId": ""
},
{
"id": "tr-3",
@@ -89,7 +91,8 @@
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
"year": 2021,
"musicBrainzId": ""
},
{
"id": "tr-4",
@@ -117,7 +120,8 @@
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
"year": 2021,
"musicBrainzId": ""
},
{
"id": "tr-5",
@@ -145,7 +149,8 @@
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
"year": 2021,
"musicBrainzId": ""
},
{
"id": "tr-6",
@@ -173,7 +178,8 @@
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
"year": 2021,
"musicBrainzId": ""
},
{
"id": "tr-7",
@@ -201,7 +207,8 @@
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
"year": 2021,
"musicBrainzId": ""
},
{
"id": "tr-8",
@@ -229,7 +236,8 @@
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
"year": 2021,
"musicBrainzId": ""
},
{
"id": "tr-9",
@@ -257,7 +265,8 @@
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
"year": 2021,
"musicBrainzId": ""
},
{
"id": "tr-10",
@@ -285,7 +294,8 @@
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
"year": 2021,
"musicBrainzId": ""
},
{
"id": "tr-11",
@@ -313,7 +323,8 @@
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
"year": 2021,
"musicBrainzId": ""
},
{
"id": "tr-12",
@@ -341,7 +352,8 @@
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
"year": 2021,
"musicBrainzId": ""
},
{
"id": "tr-13",
@@ -369,7 +381,8 @@
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
"year": 2021,
"musicBrainzId": ""
},
{
"id": "tr-14",
@@ -397,7 +410,8 @@
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
"year": 2021,
"musicBrainzId": ""
},
{
"id": "tr-15",
@@ -425,7 +439,8 @@
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
"year": 2021,
"musicBrainzId": ""
},
{
"id": "tr-16",
@@ -453,7 +468,8 @@
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
"year": 2021,
"musicBrainzId": ""
},
{
"id": "tr-17",
@@ -481,7 +497,8 @@
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
"year": 2021,
"musicBrainzId": ""
},
{
"id": "tr-18",
@@ -509,7 +526,8 @@
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
"year": 2021,
"musicBrainzId": ""
},
{
"id": "tr-19",
@@ -537,7 +555,8 @@
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
"year": 2021,
"musicBrainzId": ""
},
{
"id": "tr-20",
@@ -565,7 +584,8 @@
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
"year": 2021,
"musicBrainzId": ""
}
]
}
+18 -9
View File
@@ -19,7 +19,8 @@
"isDir": true,
"isVideo": false,
"parent": "al-2",
"title": "album-0"
"title": "album-0",
"musicBrainzId": ""
},
{
"id": "al-4",
@@ -33,7 +34,8 @@
"isDir": true,
"isVideo": false,
"parent": "al-2",
"title": "album-1"
"title": "album-1",
"musicBrainzId": ""
},
{
"id": "al-5",
@@ -47,7 +49,8 @@
"isDir": true,
"isVideo": false,
"parent": "al-2",
"title": "album-2"
"title": "album-2",
"musicBrainzId": ""
},
{
"id": "al-7",
@@ -61,7 +64,8 @@
"isDir": true,
"isVideo": false,
"parent": "al-6",
"title": "album-0"
"title": "album-0",
"musicBrainzId": ""
},
{
"id": "al-8",
@@ -75,7 +79,8 @@
"isDir": true,
"isVideo": false,
"parent": "al-6",
"title": "album-1"
"title": "album-1",
"musicBrainzId": ""
},
{
"id": "al-9",
@@ -89,7 +94,8 @@
"isDir": true,
"isVideo": false,
"parent": "al-6",
"title": "album-2"
"title": "album-2",
"musicBrainzId": ""
},
{
"id": "al-11",
@@ -103,7 +109,8 @@
"isDir": true,
"isVideo": false,
"parent": "al-10",
"title": "album-0"
"title": "album-0",
"musicBrainzId": ""
},
{
"id": "al-12",
@@ -117,7 +124,8 @@
"isDir": true,
"isVideo": false,
"parent": "al-10",
"title": "album-1"
"title": "album-1",
"musicBrainzId": ""
},
{
"id": "al-13",
@@ -131,7 +139,8 @@
"isDir": true,
"isVideo": false,
"parent": "al-10",
"title": "album-2"
"title": "album-2",
"musicBrainzId": ""
}
]
}
+40 -20
View File
@@ -29,7 +29,8 @@
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
"year": 2021,
"musicBrainzId": ""
},
{
"id": "tr-2",
@@ -53,7 +54,8 @@
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
"year": 2021,
"musicBrainzId": ""
},
{
"id": "tr-3",
@@ -77,7 +79,8 @@
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
"year": 2021,
"musicBrainzId": ""
},
{
"id": "tr-4",
@@ -101,7 +104,8 @@
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
"year": 2021,
"musicBrainzId": ""
},
{
"id": "tr-5",
@@ -125,7 +129,8 @@
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
"year": 2021,
"musicBrainzId": ""
},
{
"id": "tr-6",
@@ -149,7 +154,8 @@
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
"year": 2021,
"musicBrainzId": ""
},
{
"id": "tr-7",
@@ -173,7 +179,8 @@
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
"year": 2021,
"musicBrainzId": ""
},
{
"id": "tr-8",
@@ -197,7 +204,8 @@
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
"year": 2021,
"musicBrainzId": ""
},
{
"id": "tr-9",
@@ -221,7 +229,8 @@
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
"year": 2021,
"musicBrainzId": ""
},
{
"id": "tr-10",
@@ -245,7 +254,8 @@
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
"year": 2021,
"musicBrainzId": ""
},
{
"id": "tr-11",
@@ -269,7 +279,8 @@
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
"year": 2021,
"musicBrainzId": ""
},
{
"id": "tr-12",
@@ -293,7 +304,8 @@
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
"year": 2021,
"musicBrainzId": ""
},
{
"id": "tr-13",
@@ -317,7 +329,8 @@
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
"year": 2021,
"musicBrainzId": ""
},
{
"id": "tr-14",
@@ -341,7 +354,8 @@
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
"year": 2021,
"musicBrainzId": ""
},
{
"id": "tr-15",
@@ -365,7 +379,8 @@
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
"year": 2021,
"musicBrainzId": ""
},
{
"id": "tr-16",
@@ -389,7 +404,8 @@
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
"year": 2021,
"musicBrainzId": ""
},
{
"id": "tr-17",
@@ -413,7 +429,8 @@
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
"year": 2021,
"musicBrainzId": ""
},
{
"id": "tr-18",
@@ -437,7 +454,8 @@
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
"year": 2021,
"musicBrainzId": ""
},
{
"id": "tr-19",
@@ -461,7 +479,8 @@
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
"year": 2021,
"musicBrainzId": ""
},
{
"id": "tr-20",
@@ -485,7 +504,8 @@
"track": 1,
"discNumber": 1,
"type": "music",
"year": 2021
"year": 2021,
"musicBrainzId": ""
}
]
}