mirror of
https://github.com/navidrome/navidrome.git
synced 2026-04-03 06:41:01 +00:00
Close stream when downloading files, fix fd leak
This commit is contained in:
parent
05c6cdea1a
commit
b8c5e49dd3
@ -127,11 +127,17 @@ func (api *Router) Download(w http.ResponseWriter, r *http.Request) (*responses.
|
|||||||
switch v := entity.(type) {
|
switch v := entity.(type) {
|
||||||
case *model.MediaFile:
|
case *model.MediaFile:
|
||||||
stream, err := api.streamer.NewStream(ctx, id, format, maxBitRate)
|
stream, err := api.streamer.NewStream(ctx, id, format, maxBitRate)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make sure the stream will be closed at the end, to avoid leakage
|
||||||
|
defer func() {
|
||||||
|
if err := stream.Close(); err != nil && log.CurrentLevel() >= log.LevelDebug {
|
||||||
|
log.Error("Error closing stream", "id", id, "file", stream.Name(), err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
disposition := fmt.Sprintf("attachment; filename=\"%s\"", stream.Name())
|
disposition := fmt.Sprintf("attachment; filename=\"%s\"", stream.Name())
|
||||||
w.Header().Set("Content-Disposition", disposition)
|
w.Header().Set("Content-Disposition", disposition)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user