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]
|
batchHashs := hashs[i:end]
|
||||||
queryUrl := "https://api.beatsaver.com/maps/hash/" + strings.Join(batchHashs, ",")
|
queryUrl := "https://api.beatsaver.com/maps/hash/" + strings.Join(batchHashs, ",")
|
||||||
|
log.Default().Printf("获取歌曲ID,url:%s", queryUrl)
|
||||||
resp, err := http.Get(queryUrl)
|
resp, err := http.Get(queryUrl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
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)
|
body, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -393,7 +397,15 @@ func GetSongIdsByHash(hashs []string) (hashToSongId map[string]string, err error
|
|||||||
var response map[string]struct {
|
var response map[string]struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
}
|
}
|
||||||
|
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)
|
err = json.Unmarshal(body, &response)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -389,7 +389,7 @@ func (ss *ssQuery) GetRecentScores(count int, qqId string) ([]RecordDataLite, er
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for i := 0; i < len(records); i++ {
|
for i := range records {
|
||||||
records[i].SongId = hashToSongId[records[i].SongHash]
|
records[i].SongId = hashToSongId[records[i].SongHash]
|
||||||
}
|
}
|
||||||
return records, nil
|
return records, nil
|
||||||
@ -425,7 +425,15 @@ func GetSongIdsByHash(hashs []string) (hashToSongId map[string]string, err error
|
|||||||
var response map[string]struct {
|
var response map[string]struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
}
|
}
|
||||||
|
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)
|
err = json.Unmarshal(body, &response)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user