mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
fix: make wakatime relay middleware accept single heartbeat format (resolve #445)
This commit is contained in:
parent
a49abfe0de
commit
fb5b2f52c7
@ -160,17 +160,23 @@ func (m *WakatimeRelayMiddleware) filterByCache(r *http.Request) error {
|
||||
|
||||
newData := make([]interface{}, 0, len(heartbeats))
|
||||
|
||||
for i, hb := range heartbeats {
|
||||
hb = hb.Hashed()
|
||||
|
||||
process := func(heartbeat *models.Heartbeat, rawData interface{}) {
|
||||
heartbeat = heartbeat.Hashed()
|
||||
// we didn't see this particular heartbeat before
|
||||
if _, found := m.hashCache.Get(hb.Hash); !found {
|
||||
m.hashCache.SetDefault(hb.Hash, true)
|
||||
newData = append(newData, rawData.([]interface{})[i])
|
||||
continue
|
||||
if _, found := m.hashCache.Get(heartbeat.Hash); !found {
|
||||
m.hashCache.SetDefault(heartbeat.Hash, true)
|
||||
newData = append(newData, rawData)
|
||||
}
|
||||
}
|
||||
|
||||
if _, isList := rawData.([]interface{}); isList {
|
||||
for i, hb := range heartbeats {
|
||||
process(hb, rawData.([]interface{})[i])
|
||||
}
|
||||
} else if len(heartbeats) > 0 {
|
||||
process(heartbeats[0], rawData.(interface{}))
|
||||
}
|
||||
|
||||
if len(newData) == 0 {
|
||||
return errors.New("no new heartbeats to relay")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user