fix: 优化获取最近分数的逻辑,支持分页获取数据以处理超过8条记录的情况
This commit is contained in:
parent
6ddb3574d0
commit
8f91ac21df
@ -329,9 +329,17 @@ func (ss *ssQuery) GetRecentScores(count int, qqId string) ([]RecordDataLite, er
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
historyUrl := "https://scoresaber.com/api/player/%s/scores?page=1&sort=recent"
|
||||
fullUrl := fmt.Sprintf(historyUrl, ssId)
|
||||
//一页8条,超过8条则取两页
|
||||
historyUrl := "https://scoresaber.com/api/player/%s/scores?page=%d&sort=recent"
|
||||
var response struct {
|
||||
Data []struct {
|
||||
Score Score `json:"score"`
|
||||
Leaderboard Leaderboard `json:"leaderboard"`
|
||||
} `json:"playerScores"`
|
||||
}
|
||||
records := make([]RecordDataLite, 0)
|
||||
for i := 0; i < count/8; i++ {
|
||||
fullUrl := fmt.Sprintf(historyUrl, ssId, i+1)
|
||||
resp, err := http.Get(fullUrl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -341,18 +349,11 @@ func (ss *ssQuery) GetRecentScores(count int, qqId string) ([]RecordDataLite, er
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var response struct {
|
||||
Data []struct {
|
||||
Score Score `json:"score"`
|
||||
Leaderboard Leaderboard `json:"leaderboard"`
|
||||
} `json:"playerScores"`
|
||||
}
|
||||
err = json.Unmarshal(body, &response)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
scores := response.Data
|
||||
records := make([]RecordDataLite, 0)
|
||||
for k, score := range scores {
|
||||
if k > count-1 {
|
||||
break
|
||||
@ -396,6 +397,7 @@ func (ss *ssQuery) GetRecentScores(count int, qqId string) ([]RecordDataLite, er
|
||||
}
|
||||
records = append(records, record)
|
||||
}
|
||||
}
|
||||
// 获取歌曲ID
|
||||
hashs := make([]string, 0)
|
||||
for _, record := range records {
|
||||
|
Loading…
x
Reference in New Issue
Block a user