added after endpoint
This commit is contained in:
34
main.go
34
main.go
@@ -148,6 +148,20 @@ func housekeeping() {
|
|||||||
func getPlayer(w http.ResponseWriter, r *http.Request) {
|
func getPlayer(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Access-Control-Allow-Origin", conf.Httpd.CORSAllowDomains)
|
w.Header().Set("Access-Control-Allow-Origin", conf.Httpd.CORSAllowDomains)
|
||||||
id := mux.Vars(r)["id"]
|
id := mux.Vars(r)["id"]
|
||||||
|
t := mux.Vars(r)["time"]
|
||||||
|
|
||||||
|
var offsetTime time.Time
|
||||||
|
if t != "" {
|
||||||
|
unixOffset, err := strconv.ParseInt(t, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
log.Infof("[GP] offset not an int: %v", err)
|
||||||
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
offsetTime = time.Unix(unixOffset, 0).UTC()
|
||||||
|
}
|
||||||
|
|
||||||
tPlayer, err := utils.GetPlayer(db, id, conf.Steam.APIKey, nil)
|
tPlayer, err := utils.GetPlayer(db, id, conf.Steam.APIKey, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Infof("[GP] Player not found: %+v", err)
|
log.Infof("[GP] Player not found: %+v", err)
|
||||||
@@ -169,9 +183,16 @@ func getPlayer(w http.ResponseWriter, r *http.Request) {
|
|||||||
response.VACDate = &tPlayer.VacDate
|
response.VACDate = &tPlayer.VacDate
|
||||||
}
|
}
|
||||||
|
|
||||||
db.Lock.RLock()
|
var tMatches []*ent.Match
|
||||||
tMatches, err := tPlayer.QueryMatches().Order(ent.Desc(match.FieldDate)).Limit(10).All(context.Background())
|
if !offsetTime.IsZero() {
|
||||||
db.Lock.RUnlock()
|
db.Lock.RLock()
|
||||||
|
tMatches, err = tPlayer.QueryMatches().Where(match.DateLT(offsetTime)).Order(ent.Desc(match.FieldDate)).Limit(10).All(context.Background())
|
||||||
|
db.Lock.RUnlock()
|
||||||
|
} else {
|
||||||
|
db.Lock.RLock()
|
||||||
|
tMatches, err = tPlayer.QueryMatches().Order(ent.Desc(match.FieldDate)).Limit(10).All(context.Background())
|
||||||
|
db.Lock.RUnlock()
|
||||||
|
}
|
||||||
if err != nil || len(tMatches) == 0 {
|
if err != nil || len(tMatches) == 0 {
|
||||||
log.Debugf("[GP] No matches found for player %s", id)
|
log.Debugf("[GP] No matches found for player %s", id)
|
||||||
err := utils.SendJSON(response, w)
|
err := utils.SendJSON(response, w)
|
||||||
@@ -762,12 +783,13 @@ func main() {
|
|||||||
// routes
|
// routes
|
||||||
router = mux.NewRouter().StrictSlash(true)
|
router = mux.NewRouter().StrictSlash(true)
|
||||||
router.HandleFunc("/player/{id}", getPlayer).Methods(http.MethodGet, http.MethodOptions)
|
router.HandleFunc("/player/{id}", getPlayer).Methods(http.MethodGet, http.MethodOptions)
|
||||||
|
router.HandleFunc(`/player/{id}/after/{time:\d+}`, getPlayer).Methods(http.MethodGet, http.MethodOptions)
|
||||||
router.HandleFunc("/player/{id}/track", postPlayerTrack).Methods(http.MethodPost, http.MethodOptions)
|
router.HandleFunc("/player/{id}/track", postPlayerTrack).Methods(http.MethodPost, http.MethodOptions)
|
||||||
router.HandleFunc("/player/{id}/track", deletePlayerTrack).Methods(http.MethodOptions, http.MethodDelete)
|
router.HandleFunc("/player/{id}/track", deletePlayerTrack).Methods(http.MethodOptions, http.MethodDelete)
|
||||||
router.HandleFunc("/match/parse/{sharecode}", getMatchParse).Methods(http.MethodGet, http.MethodOptions)
|
router.HandleFunc("/match/parse/{sharecode}", getMatchParse).Methods(http.MethodGet, http.MethodOptions)
|
||||||
router.HandleFunc("/match/{id:[0-9]{19}}", getMatch).Methods(http.MethodGet, http.MethodOptions)
|
router.HandleFunc(`/match/{id:\d{19}}`, getMatch).Methods(http.MethodGet, http.MethodOptions)
|
||||||
router.HandleFunc("/match/{id:[0-9]{19}}/weapons", getMatchWeapons).Methods(http.MethodGet, http.MethodOptions)
|
router.HandleFunc(`/match/{id:\d{19}}/weapons`, getMatchWeapons).Methods(http.MethodGet, http.MethodOptions)
|
||||||
router.HandleFunc("/match/{id:[0-9]{19}}/rounds", getMatchRounds).Methods(http.MethodGet, http.MethodOptions)
|
router.HandleFunc(`/match/{id:\d{19}}/rounds`, getMatchRounds).Methods(http.MethodGet, http.MethodOptions)
|
||||||
router.Use(mux.CORSMethodMiddleware(router))
|
router.Use(mux.CORSMethodMiddleware(router))
|
||||||
loggedRouter := handlers.LoggingHandler(os.Stdout, router)
|
loggedRouter := handlers.LoggingHandler(os.Stdout, router)
|
||||||
proxyRouter := handlers.ProxyHeaders(loggedRouter)
|
proxyRouter := handlers.ProxyHeaders(loggedRouter)
|
||||||
|
Reference in New Issue
Block a user