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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
//一页8条,超过8条则取两页
|
||||||
historyUrl := "https://scoresaber.com/api/player/%s/scores?page=1&sort=recent"
|
historyUrl := "https://scoresaber.com/api/player/%s/scores?page=%d&sort=recent"
|
||||||
fullUrl := fmt.Sprintf(historyUrl, ssId)
|
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)
|
resp, err := http.Get(fullUrl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -341,18 +349,11 @@ func (ss *ssQuery) GetRecentScores(count int, qqId string) ([]RecordDataLite, er
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var response struct {
|
|
||||||
Data []struct {
|
|
||||||
Score Score `json:"score"`
|
|
||||||
Leaderboard Leaderboard `json:"leaderboard"`
|
|
||||||
} `json:"playerScores"`
|
|
||||||
}
|
|
||||||
err = json.Unmarshal(body, &response)
|
err = json.Unmarshal(body, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
scores := response.Data
|
scores := response.Data
|
||||||
records := make([]RecordDataLite, 0)
|
|
||||||
for k, score := range scores {
|
for k, score := range scores {
|
||||||
if k > count-1 {
|
if k > count-1 {
|
||||||
break
|
break
|
||||||
@ -396,6 +397,7 @@ func (ss *ssQuery) GetRecentScores(count int, qqId string) ([]RecordDataLite, er
|
|||||||
}
|
}
|
||||||
records = append(records, record)
|
records = append(records, record)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// 获取歌曲ID
|
// 获取歌曲ID
|
||||||
hashs := make([]string, 0)
|
hashs := make([]string, 0)
|
||||||
for _, record := range records {
|
for _, record := range records {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user