diff --git a/service/beatleader/bind_bl.go b/service/beatleader/bind_bl.go index 276dde2..1ed5e9b 100644 --- a/service/beatleader/bind_bl.go +++ b/service/beatleader/bind_bl.go @@ -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 } diff --git a/service/scoresaber/bind_ss.go b/service/scoresaber/bind_ss.go index 04e58cb..300af36 100644 --- a/service/scoresaber/bind_ss.go +++ b/service/scoresaber/bind_ss.go @@ -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 }