diff --git a/crawler/igdb.go b/crawler/igdb.go index a5d0888..e41f568 100644 --- a/crawler/igdb.go +++ b/crawler/igdb.go @@ -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) diff --git a/crawler/steam250.go b/crawler/steam250.go index b52501d..a81fd98 100644 --- a/crawler/steam250.go +++ b/crawler/steam250.go @@ -44,7 +44,10 @@ func GetSteam250(url string) ([]*model.GameInfo, error) { if err != nil { return nil, err } - return infos[:10], nil + if len(infos) > 10 { + return infos[:10], nil + } + return infos, nil } func GetSteam250Top250() ([]*model.GameInfo, error) {