summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main.go8
-rw-r--r--modern.go4
2 files changed, 7 insertions, 5 deletions
diff --git a/main.go b/main.go
index 787c811..de5ba2a 100644
--- a/main.go
+++ b/main.go
@@ -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")
diff --git a/modern.go b/modern.go
index 9106123..45c92bd 100644
--- a/modern.go
+++ b/modern.go
@@ -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
}
}