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 {
|
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)
|
|
||||||
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
|
|
||||||
}
|
|
||||||
var response struct {
|
var response struct {
|
||||||
Data []struct {
|
Data []struct {
|
||||||
Score Score `json:"score"`
|
Score Score `json:"score"`
|
||||||
Leaderboard Leaderboard `json:"leaderboard"`
|
Leaderboard Leaderboard `json:"leaderboard"`
|
||||||
} `json:"playerScores"`
|
} `json:"playerScores"`
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(body, &response)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
scores := response.Data
|
|
||||||
records := make([]RecordDataLite, 0)
|
records := make([]RecordDataLite, 0)
|
||||||
for k, score := range scores {
|
for i := 0; i < count/8; i++ {
|
||||||
if k > count-1 {
|
fullUrl := fmt.Sprintf(historyUrl, ssId, i+1)
|
||||||
break
|
resp, err := http.Get(fullUrl)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
record := RecordDataLite{
|
defer resp.Body.Close()
|
||||||
ScoreID: score.Score.ID,
|
body, err := io.ReadAll(resp.Body)
|
||||||
SsID: ssId,
|
if err != nil {
|
||||||
Name: playerData.Name,
|
return nil, err
|
||||||
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"),
|
|
||||||
}
|
}
|
||||||
// 检查设备信息并设置
|
err = json.Unmarshal(body, &response)
|
||||||
if score.Score.DeviceHmd != nil {
|
if err != nil {
|
||||||
record.DeviceHmd = *score.Score.DeviceHmd
|
return nil, err
|
||||||
}
|
}
|
||||||
if score.Score.DeviceControllerLeft != nil {
|
scores := response.Data
|
||||||
record.DeviceControllerLeft = *score.Score.DeviceControllerLeft
|
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
|
// 获取歌曲ID
|
||||||
hashs := make([]string, 0)
|
hashs := make([]string, 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user