diff options
| author | Guillaume Horel <guillaume.horel@gmail.com> | 2016-12-13 21:47:52 -0500 |
|---|---|---|
| committer | Guillaume Horel <guillaume.horel@gmail.com> | 2016-12-13 21:47:52 -0500 |
| commit | 3f3cb7c7cede379914eed51c57e58f66ffdd1856 (patch) | |
| tree | 8d876ddc66060664825417b67a70ba982c8f45dc | |
| parent | 6bb509f48f20a20e16b447ddcecbf3d55a4aa0a3 (diff) | |
| download | lastfm-api-3f3cb7c7cede379914eed51c57e58f66ffdd1856.tar.gz | |
return the number of accepted and ignored scrobbles
| -rw-r--r-- | main.go | 8 | ||||
| -rw-r--r-- | modern.go | 4 |
2 files changed, 7 insertions, 5 deletions
@@ -134,7 +134,7 @@ func parsePart2(values url.Values) (Scrobble, error) { return scrobble, nil } -func parseScrobbles(values url.Values, session *Session) []Scrobble { +func parseScrobbles(values url.Values, session *Session) ([]Scrobble, int) { scrobbles := make([]Scrobble, 0, 1) parts := parseValues(values) var parsePart func(url.Values) (Scrobble, error) @@ -143,25 +143,27 @@ func parseScrobbles(values url.Values, session *Session) []Scrobble { } else { parsePart = parsePart1 } + ignored := 0 for i, c := 0, 0; i < 50 && c < len(parts); i++ { if part, ok := parts[i]; ok { c++ if scrobble, err := parsePart(part); err != nil { fmt.Printf("%v\n", err) + ignored++ } else { scrobble.Session = session.Key scrobbles = append(scrobbles, scrobble) } } } - return scrobbles + return scrobbles, ignored } func scrobbleHandler(ds DataStore, w http.ResponseWriter, r *http.Request) { if session, err := ds.GetSession(r.FormValue("s")); err != nil { fmt.Fprintln(w, "BADSESSION") } else { - scrobbles := parseScrobbles(r.Form, session) + scrobbles, _ := parseScrobbles(r.Form, session) fmt.Printf("%v\n", scrobbles) ds.PutScrobbles(scrobbles) fmt.Fprintln(w, "OK") @@ -94,10 +94,10 @@ func (store *SqlStore) TrackScrobble(r *http.Request) (ApiResponse, error) { fmt.Printf("%v\n", err) return struct{}{}, err } else { - scrobbles := parseScrobbles(r.Form, session) + scrobbles, ignored := parseScrobbles(r.Form, session) store.PutScrobbles(scrobbles) return Scrobbles{Scrobbles: scrobbles, - Attrs: Attrs{1, 0}}, nil + Attrs: Attrs{len(scrobbles), ignored}}, nil } } |
