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))
|
newData := make([]interface{}, 0, len(heartbeats))
|
||||||
|
|
||||||
for i, hb := range heartbeats {
|
process := func(heartbeat *models.Heartbeat, rawData interface{}) {
|
||||||
hb = hb.Hashed()
|
heartbeat = heartbeat.Hashed()
|
||||||
|
|
||||||
// we didn't see this particular heartbeat before
|
// we didn't see this particular heartbeat before
|
||||||
if _, found := m.hashCache.Get(hb.Hash); !found {
|
if _, found := m.hashCache.Get(heartbeat.Hash); !found {
|
||||||
m.hashCache.SetDefault(hb.Hash, true)
|
m.hashCache.SetDefault(heartbeat.Hash, true)
|
||||||
newData = append(newData, rawData.([]interface{})[i])
|
newData = append(newData, rawData)
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
if len(newData) == 0 {
|
||||||
return errors.New("no new heartbeats to relay")
|
return errors.New("no new heartbeats to relay")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user