fix: 修复单个哈希查询时的歌曲ID获取逻辑
This commit is contained in:
parent
e645ed5366
commit
b22185e87f
@ -381,11 +381,15 @@ func GetSongIdsByHash(hashs []string) (hashToSongId map[string]string, err error
|
||||
}
|
||||
batchHashs := hashs[i:end]
|
||||
queryUrl := "https://api.beatsaver.com/maps/hash/" + strings.Join(batchHashs, ",")
|
||||
log.Default().Printf("获取歌曲ID,url:%s", queryUrl)
|
||||
resp, err := http.Get(queryUrl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("获取歌曲ID失败,状态码:%d,url:%s", resp.StatusCode, queryUrl)
|
||||
}
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -393,7 +397,15 @@ func GetSongIdsByHash(hashs []string) (hashToSongId map[string]string, err error
|
||||
var response map[string]struct {
|
||||
ID string `json:"id"`
|
||||
}
|
||||
err = json.Unmarshal(body, &response)
|
||||
if len(batchHashs) == 1 {
|
||||
var singleResponse struct {
|
||||
ID string `json:"id"`
|
||||
}
|
||||
err = json.Unmarshal(body, &singleResponse)
|
||||
response[batchHashs[0]] = singleResponse
|
||||
} else {
|
||||
err = json.Unmarshal(body, &response)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -389,7 +389,7 @@ func (ss *ssQuery) GetRecentScores(count int, qqId string) ([]RecordDataLite, er
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for i := 0; i < len(records); i++ {
|
||||
for i := range records {
|
||||
records[i].SongId = hashToSongId[records[i].SongHash]
|
||||
}
|
||||
return records, nil
|
||||
@ -425,7 +425,15 @@ func GetSongIdsByHash(hashs []string) (hashToSongId map[string]string, err error
|
||||
var response map[string]struct {
|
||||
ID string `json:"id"`
|
||||
}
|
||||
err = json.Unmarshal(body, &response)
|
||||
if len(batchHashs) == 1 {
|
||||
var singleResponse struct {
|
||||
ID string `json:"id"`
|
||||
}
|
||||
err = json.Unmarshal(body, &singleResponse)
|
||||
response[batchHashs[0]] = singleResponse
|
||||
} else {
|
||||
err = json.Unmarshal(body, &response)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user