fix GetSteam250
This commit is contained in:
parent
d91ca35a83
commit
1fbe80f0b9
@ -113,6 +113,55 @@ func GetIGDBAppParent(id int) (int, error) {
|
||||
return id, nil
|
||||
}
|
||||
|
||||
func GetIGDBAppParetns(ids []int) (map[int]int, error) {
|
||||
var err error
|
||||
if TwitchToken == "" {
|
||||
TwitchToken, err = LoginTwitch()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
idsStr := make([]string, len(ids))
|
||||
for i, id := range ids {
|
||||
idsStr[i] = strconv.Itoa(id)
|
||||
}
|
||||
resp, err := utils.Fetch(utils.FetchConfig{
|
||||
Url: constant.IGDBGameURL,
|
||||
Headers: map[string]string{
|
||||
"Client-ID": config.Config.Twitch.ClientID,
|
||||
"Authorization": "Bearer " + TwitchToken,
|
||||
"User-Agent": "",
|
||||
"Content-Type": "text/plain",
|
||||
},
|
||||
Data: fmt.Sprintf(`where id=(%s) ;fields version_parent;`, strings.Join(idsStr, ",")),
|
||||
Method: "POST",
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var data []struct {
|
||||
ID int `json:"id"`
|
||||
VersionParent int `json:"version_parent"`
|
||||
}
|
||||
if err = json.Unmarshal(resp.Data, &data); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal: %w, %s", err, debug.Stack())
|
||||
}
|
||||
parents := make(map[int]int)
|
||||
for _, item := range data {
|
||||
if item.VersionParent != 0 {
|
||||
pid, err := GetIGDBAppParentCache(item.VersionParent)
|
||||
if err != nil {
|
||||
parents[item.ID] = item.ID
|
||||
} else {
|
||||
parents[item.ID] = pid
|
||||
}
|
||||
} else {
|
||||
parents[item.ID] = item.ID
|
||||
}
|
||||
}
|
||||
return parents, nil
|
||||
}
|
||||
|
||||
func GetIGDBAppParentCache(id int) (int, error) {
|
||||
if config.Config.RedisAvaliable {
|
||||
key := fmt.Sprintf("igdb_parent:%d", id)
|
||||
|
@ -44,7 +44,10 @@ func GetSteam250(url string) ([]*model.GameInfo, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(infos) > 10 {
|
||||
return infos[:10], nil
|
||||
}
|
||||
return infos, nil
|
||||
}
|
||||
|
||||
func GetSteam250Top250() ([]*model.GameInfo, error) {
|
||||
|
Loading…
Reference in New Issue
Block a user