diff --git a/cmd/gonicembed/main.go b/cmd/gonicembed/main.go index d5684b9..2000eb1 100644 --- a/cmd/gonicembed/main.go +++ b/cmd/gonicembed/main.go @@ -107,6 +107,7 @@ func processAssets(c *config, files []string) error { if err != nil { return errors.Wrap(err, "opening asset") } + defer data.Close() processAsset( c, &file{ diff --git a/server/ctrlsubsonic/ctrl.go b/server/ctrlsubsonic/ctrl.go index dbdc20a..2b2c684 100644 --- a/server/ctrlsubsonic/ctrl.go +++ b/server/ctrlsubsonic/ctrl.go @@ -83,6 +83,10 @@ type subsonicHandler func(r *http.Request) *spec.Response func (c *Controller) H(h subsonicHandler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { response := h(r) + if response == nil { + log.Println("error: non raw subsonic handler returned a nil response\n") + return + } if err := writeResp(w, r, response); err != nil { log.Printf("error writing subsonic response (normal handler): %v\n", err) } @@ -93,8 +97,10 @@ type subsonicHandlerRaw func(w http.ResponseWriter, r *http.Request) *spec.Respo func (c *Controller) HR(h subsonicHandlerRaw) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - // TODO: log if both response writer written and non nil spec return response := h(w, r) + if response == nil { + return + } if err := writeResp(w, r, response); err != nil { log.Printf("error writing subsonic response (raw handler): %v\n", err) } diff --git a/server/ctrlsubsonic/handlers_raw.go b/server/ctrlsubsonic/handlers_raw.go index e509836..9f0ed30 100644 --- a/server/ctrlsubsonic/handlers_raw.go +++ b/server/ctrlsubsonic/handlers_raw.go @@ -2,7 +2,6 @@ package ctrlsubsonic import ( "net/http" - "os" "path" "time" @@ -65,12 +64,7 @@ func (c *Controller) ServeStream(w http.ResponseWriter, r *http.Request) *spec.R track.Album.RightPath, track.Filename, ) - file, err := os.Open(absPath) - if err != nil { - return spec.NewError(0, "error while streaming media: %v", err) - } - stat, _ := file.Stat() - http.ServeContent(w, r, absPath, stat.ModTime(), file) + http.ServeFile(w, r, absPath) // // after we've served the file, mark the album as played user := r.Context().Value(key.User).(*model.User) diff --git a/server/ctrlsubsonic/testdata/db b/server/ctrlsubsonic/testdata/db index 6724d28..af72b97 100644 Binary files a/server/ctrlsubsonic/testdata/db and b/server/ctrlsubsonic/testdata/db differ