fix(listenbrainz): set json header
closes #216 related https://github.com/sentriz/gonic/issues/216 related https://github.com/krateng/maloja/issues/141
This commit is contained in:
@@ -76,19 +76,22 @@ func (s *Scrobbler) Scrobble(user *db.User, track *db.Track, stamp time.Time, su
|
|||||||
} else {
|
} else {
|
||||||
scrobble.ListenType = listenTypePlayingNow
|
scrobble.ListenType = listenTypePlayingNow
|
||||||
}
|
}
|
||||||
payloadBuf := bytes.Buffer{}
|
|
||||||
|
var payloadBuf bytes.Buffer
|
||||||
if err := json.NewEncoder(&payloadBuf).Encode(scrobble); err != nil {
|
if err := json.NewEncoder(&payloadBuf).Encode(scrobble); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
submitURL := fmt.Sprintf("%s%s", user.ListenBrainzURL, submitPath)
|
submitURL := fmt.Sprintf("%s%s", user.ListenBrainzURL, submitPath)
|
||||||
authHeader := fmt.Sprintf("Token %s", user.ListenBrainzToken)
|
authHeader := fmt.Sprintf("Token %s", user.ListenBrainzToken)
|
||||||
req, _ := http.NewRequest(http.MethodPost, submitURL, &payloadBuf)
|
req, _ := http.NewRequest(http.MethodPost, submitURL, &payloadBuf)
|
||||||
|
req.Header.Add("Content-Type", "application/json")
|
||||||
req.Header.Add("Authorization", authHeader)
|
req.Header.Add("Authorization", authHeader)
|
||||||
resp, err := http.DefaultClient.Do(req)
|
resp, err := http.DefaultClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("http post: %w", err)
|
return fmt.Errorf("http post: %w", err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
respBytes, _ := httputil.DumpResponse(resp, true)
|
respBytes, _ := httputil.DumpResponse(resp, true)
|
||||||
switch {
|
switch {
|
||||||
case resp.StatusCode == http.StatusUnauthorized:
|
case resp.StatusCode == http.StatusUnauthorized:
|
||||||
|
|||||||
Reference in New Issue
Block a user