fix: 优化获取最近分数的逻辑,支持分页获取数据以处理超过8条记录的情况
This commit is contained in:
parent
6ddb3574d0
commit
8f91ac21df
@ -329,72 +329,74 @@ 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)
|
||||
resp, err := http.Get(fullUrl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
//一页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"`
|
||||
}
|
||||
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
|
||||
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
|
||||
}
|
||||
record := RecordDataLite{
|
||||
ScoreID: score.Score.ID,
|
||||
SsID: ssId,
|
||||
Name: playerData.Name,
|
||||
Country: playerData.Country,
|
||||
SongName: score.Leaderboard.SongName,
|
||||
SongSubName: score.Leaderboard.SongSubName,
|
||||
SongAuthorName: score.Leaderboard.SongAuthorName,
|
||||
SongHash: score.Leaderboard.SongHash,
|
||||
SongId: "",
|
||||
CoverImage: score.Leaderboard.CoverImage,
|
||||
DifficultyRaw: score.Leaderboard.Difficulty.DifficultyRaw,
|
||||
Stars: score.Leaderboard.Stars,
|
||||
PP: score.Score.Pp,
|
||||
Weight: score.Score.Weight,
|
||||
Modifiers: score.Score.Modifiers,
|
||||
Multiplier: score.Score.Multiplier,
|
||||
Rank: score.Score.Rank,
|
||||
BadCuts: score.Score.BadCuts,
|
||||
Score: score.Score.ModifiedScore,
|
||||
MaxScore: score.Leaderboard.MaxScore,
|
||||
FullCombo: score.Score.FullCombo,
|
||||
DeviceHmd: "",
|
||||
DeviceControllerLeft: "",
|
||||
DeviceControllerRight: "",
|
||||
GeneratedTime: score.Score.TimeSet.Format("2006-01-02 15:04:05.999999999-07:00"),
|
||||
defer resp.Body.Close()
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// 检查设备信息并设置
|
||||
if score.Score.DeviceHmd != nil {
|
||||
record.DeviceHmd = *score.Score.DeviceHmd
|
||||
err = json.Unmarshal(body, &response)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if score.Score.DeviceControllerLeft != nil {
|
||||
record.DeviceControllerLeft = *score.Score.DeviceControllerLeft
|
||||
scores := response.Data
|
||||
for k, score := range scores {
|
||||
if k > count-1 {
|
||||
break
|
||||
}
|
||||
record := RecordDataLite{
|
||||
ScoreID: score.Score.ID,
|
||||
SsID: ssId,
|
||||
Name: playerData.Name,
|
||||
Country: playerData.Country,
|
||||
SongName: score.Leaderboard.SongName,
|
||||
SongSubName: score.Leaderboard.SongSubName,
|
||||
SongAuthorName: score.Leaderboard.SongAuthorName,
|
||||
SongHash: score.Leaderboard.SongHash,
|
||||
SongId: "",
|
||||
CoverImage: score.Leaderboard.CoverImage,
|
||||
DifficultyRaw: score.Leaderboard.Difficulty.DifficultyRaw,
|
||||
Stars: score.Leaderboard.Stars,
|
||||
PP: score.Score.Pp,
|
||||
Weight: score.Score.Weight,
|
||||
Modifiers: score.Score.Modifiers,
|
||||
Multiplier: score.Score.Multiplier,
|
||||
Rank: score.Score.Rank,
|
||||
BadCuts: score.Score.BadCuts,
|
||||
Score: score.Score.ModifiedScore,
|
||||
MaxScore: score.Leaderboard.MaxScore,
|
||||
FullCombo: score.Score.FullCombo,
|
||||
DeviceHmd: "",
|
||||
DeviceControllerLeft: "",
|
||||
DeviceControllerRight: "",
|
||||
GeneratedTime: score.Score.TimeSet.Format("2006-01-02 15:04:05.999999999-07:00"),
|
||||
}
|
||||
// 检查设备信息并设置
|
||||
if score.Score.DeviceHmd != nil {
|
||||
record.DeviceHmd = *score.Score.DeviceHmd
|
||||
}
|
||||
if score.Score.DeviceControllerLeft != nil {
|
||||
record.DeviceControllerLeft = *score.Score.DeviceControllerLeft
|
||||
}
|
||||
if score.Score.DeviceControllerRight != nil {
|
||||
record.DeviceControllerRight = *score.Score.DeviceControllerRight
|
||||
}
|
||||
records = append(records, record)
|
||||
}
|
||||
if score.Score.DeviceControllerRight != nil {
|
||||
record.DeviceControllerRight = *score.Score.DeviceControllerRight
|
||||
}
|
||||
records = append(records, record)
|
||||
}
|
||||
// 获取歌曲ID
|
||||
hashs := make([]string, 0)
|
||||
|
Loading…
x
Reference in New Issue
Block a user