better sharecode api handling, renamed endpoint to /player/id/track
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"csgowtfd/ent/stats"
|
||||
"encoding/json"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/an0nfunc/go-steamapi"
|
||||
log "github.com/sirupsen/logrus"
|
||||
@@ -187,6 +188,18 @@ type MatchResponse struct {
|
||||
Stats interface{} `json:"stats,omitempty"`
|
||||
}
|
||||
|
||||
type (
|
||||
AuthcodeUnauthorizedError struct {
|
||||
error
|
||||
}
|
||||
AuthcodeRateLimitError struct {
|
||||
error
|
||||
}
|
||||
SharecodeNoMatchError struct {
|
||||
error
|
||||
}
|
||||
)
|
||||
|
||||
const (
|
||||
shareCodeURLEntry = "https://api.steampowered.com/ICSGOPlayers_730/GetNextMatchSharingCode/v1?key=%s&steamid=%d&steamidkey=%s&knowncode=%s"
|
||||
)
|
||||
@@ -328,10 +341,19 @@ func getNextShareCode(lastCode string, apiKey string, authCode string, steamId u
|
||||
return "", err
|
||||
}
|
||||
|
||||
if r.StatusCode == 202 {
|
||||
switch r.StatusCode {
|
||||
case http.StatusAccepted:
|
||||
return "n/a", nil
|
||||
} else if r.StatusCode != 200 {
|
||||
return "", fmt.Errorf("bad response from steam api (HTTP %d)", r.StatusCode)
|
||||
case http.StatusTooManyRequests, http.StatusServiceUnavailable:
|
||||
return "", AuthcodeRateLimitError{errors.New("api temp. ratelimited")}
|
||||
case http.StatusPreconditionFailed:
|
||||
return "", SharecodeNoMatchError{errors.New("sharecode not from player history")}
|
||||
case http.StatusForbidden:
|
||||
return "", AuthcodeUnauthorizedError{errors.New("authcode unauthorized")}
|
||||
case http.StatusOK:
|
||||
break
|
||||
default:
|
||||
return "", errors.New("temporary steamapi error")
|
||||
}
|
||||
|
||||
defer func(Body io.ReadCloser) {
|
||||
|
Reference in New Issue
Block a user