mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
fix: consider all Machine/UserAgent entries
This commit is contained in:
parent
aaa907a7b2
commit
c7e12ba3b5
@ -4,6 +4,7 @@ package v1
|
||||
|
||||
type MachineViewModel struct {
|
||||
Data []*MachineEntry `json:"data"`
|
||||
TotalPages int `json:"total_pages"`
|
||||
}
|
||||
|
||||
type MachineEntry struct {
|
||||
|
@ -2,6 +2,7 @@ package v1
|
||||
|
||||
type UserAgentsViewModel struct {
|
||||
Data []*UserAgentEntry `json:"data"`
|
||||
TotalPages int `json:"total_pages"`
|
||||
}
|
||||
|
||||
type UserAgentEntry struct {
|
||||
|
@ -15,6 +15,7 @@ import (
|
||||
"golang.org/x/sync/semaphore"
|
||||
"net/http"
|
||||
"time"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
const OriginWakatime = "wakatime"
|
||||
@ -174,7 +175,14 @@ func (w *WakatimeHeartbeatImporter) fetchRange() (time.Time, time.Time, error) {
|
||||
func (w *WakatimeHeartbeatImporter) fetchUserAgents() (map[string]*wakatime.UserAgentEntry, error) {
|
||||
httpClient := &http.Client{Timeout: 10 * time.Second}
|
||||
|
||||
req, err := http.NewRequest(http.MethodGet, config.WakatimeApiUrl+config.WakatimeApiUserAgentsUrl, nil)
|
||||
userAgents := make(map[string]*wakatime.UserAgentEntry)
|
||||
|
||||
done := false
|
||||
for i:=1; !done; i++ {
|
||||
queryStr := "?page="+strconv.Itoa(i)
|
||||
|
||||
req, err := http.NewRequest(http.MethodGet, config.WakatimeApiUrl+
|
||||
config.WakatimeApiUserAgentsUrl+queryStr, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -188,11 +196,14 @@ func (w *WakatimeHeartbeatImporter) fetchUserAgents() (map[string]*wakatime.User
|
||||
if err := json.NewDecoder(res.Body).Decode(&userAgentsData); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if i == userAgentsData.TotalPages {
|
||||
done = true
|
||||
}
|
||||
|
||||
userAgents := make(map[string]*wakatime.UserAgentEntry)
|
||||
for _, ua := range userAgentsData.Data {
|
||||
userAgents[ua.Id] = ua
|
||||
}
|
||||
}
|
||||
|
||||
return userAgents, nil
|
||||
}
|
||||
@ -202,7 +213,14 @@ func (w *WakatimeHeartbeatImporter) fetchUserAgents() (map[string]*wakatime.User
|
||||
func (w *WakatimeHeartbeatImporter) fetchMachineNames() (map[string]*wakatime.MachineEntry, error) {
|
||||
httpClient := &http.Client{Timeout: 10 * time.Second}
|
||||
|
||||
req, err := http.NewRequest(http.MethodGet, config.WakatimeApiUrl+config.WakatimeApiMachineNamesUrl, nil)
|
||||
machines := make(map[string]*wakatime.MachineEntry)
|
||||
|
||||
done := false
|
||||
for i:=1; !done; i++ {
|
||||
queryStr := "?page="+strconv.Itoa(i)
|
||||
|
||||
req, err := http.NewRequest(http.MethodGet, config.WakatimeApiUrl+
|
||||
config.WakatimeApiMachineNamesUrl+queryStr, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -216,11 +234,14 @@ func (w *WakatimeHeartbeatImporter) fetchMachineNames() (map[string]*wakatime.Ma
|
||||
if err := json.NewDecoder(res.Body).Decode(&machineData); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if i == machineData.TotalPages {
|
||||
done = true
|
||||
}
|
||||
|
||||
machines := make(map[string]*wakatime.MachineEntry)
|
||||
for _, ma := range machineData.Data {
|
||||
machines[ma.Id] = ma
|
||||
}
|
||||
}
|
||||
|
||||
return machines, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user