This commit is contained in:
@@ -41,3 +41,18 @@ func (c *SongController) Stream(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
http.ServeFile(w, r, mediaFile.Path)
|
||||
}
|
||||
|
||||
func (c *SongController) Cover(w http.ResponseWriter, r *http.Request) {
|
||||
paramID := chi.URLParam(r, "id")
|
||||
id, err := strconv.Atoi(paramID)
|
||||
if err != nil {
|
||||
http.Error(w, "无效的歌曲 ID", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
coverPath, err := c.service.GetCover(id)
|
||||
if err != nil {
|
||||
http.Error(w, "获取封面异常", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
http.ServeFile(w, r, coverPath)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user