From 99233ec318e01723a2483a68e356d6ec4df524b7 Mon Sep 17 00:00:00 2001 From: sentriz Date: Mon, 1 Apr 2024 22:10:30 +0100 Subject: [PATCH 1/4] use signal.NotifyContext when shutting down --- cmd/gonic/gonic.go | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/cmd/gonic/gonic.go b/cmd/gonic/gonic.go index 3235e1d..9b0eb34 100644 --- a/cmd/gonic/gonic.go +++ b/cmd/gonic/gonic.go @@ -298,7 +298,9 @@ func main() { mux.HandleFunc("/debug/pprof/trace", pprof.Trace) } - errgrp, ctx := errgroup.WithContext(context.Background()) + ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + defer cancel() + errgrp, ctx := errgroup.WithContext(ctx) errgrp.Go(func() error { defer logJob("http")() @@ -315,7 +317,10 @@ func main() { if *confTLSCert != "" && *confTLSKey != "" { return server.ListenAndServeTLS(*confTLSCert, *confTLSKey) } - return server.ListenAndServe() + if err := server.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) { + return err + } + return nil }) errgrp.Go(func() error { @@ -439,20 +444,7 @@ func main() { return nil }) - errShutdown := errors.New("shutdown") - - errgrp.Go(func() error { - sigChan := make(chan os.Signal, 1) - signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM) - select { - case <-ctx.Done(): - return nil - case <-sigChan: - return errShutdown - } - }) - - if err := errgrp.Wait(); err != nil && !errors.Is(err, errShutdown) { + if err := errgrp.Wait(); err != nil { log.Panic(err) } From 8a0fa05c7cdcb98066c263fea72af0715864bea5 Mon Sep 17 00:00:00 2001 From: sentriz Date: Thu, 4 Apr 2024 10:04:58 +0100 Subject: [PATCH 2/4] fix(taglib): support lower case filenames again fixes #491 --- tags/taglib/taglib.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tags/taglib/taglib.go b/tags/taglib/taglib.go index d0f5f2d..e8e0cce 100644 --- a/tags/taglib/taglib.go +++ b/tags/taglib/taglib.go @@ -13,7 +13,7 @@ import ( type TagLib struct{} func (TagLib) CanRead(absPath string) bool { - switch ext := filepath.Ext(absPath); ext { + switch ext := strings.ToLower(filepath.Ext(absPath)); ext { case ".mp3", ".flac", ".aac", ".m4a", ".m4b", ".ogg", ".opus", ".wma", ".wav", ".wv": return true } From cc4c57be9816e2b85fe8b280f891a9b6e42a0941 Mon Sep 17 00:00:00 2001 From: sentriz Date: Sun, 7 Apr 2024 17:53:12 +0100 Subject: [PATCH 3/4] check errors when creating request related #494 --- lastfm/client.go | 6 +++++- listenbrainz/listenbrainz.go | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lastfm/client.go b/lastfm/client.go index b718726..6cf3d97 100644 --- a/lastfm/client.go +++ b/lastfm/client.go @@ -291,7 +291,11 @@ func (c *Client) GetCurrentUser(user *db.User) (User, error) { } func (c *Client) makeRequest(method string, params url.Values) (LastFM, error) { - req, _ := http.NewRequest(method, BaseURL, nil) + req, err := http.NewRequest(method, BaseURL, nil) + if err != nil { + return LastFM{}, fmt.Errorf("create request: %w", err) + } + req.URL.RawQuery = params.Encode() resp, err := c.httpClient.Do(req) diff --git a/listenbrainz/listenbrainz.go b/listenbrainz/listenbrainz.go index 61db7e5..8d1da45 100644 --- a/listenbrainz/listenbrainz.go +++ b/listenbrainz/listenbrainz.go @@ -75,7 +75,11 @@ func (c *Client) Scrobble(user db.User, track scrobble.Track, stamp time.Time, s submitURL := fmt.Sprintf("%s%s", user.ListenBrainzURL, submitPath) authHeader := fmt.Sprintf("Token %s", user.ListenBrainzToken) - req, _ := http.NewRequest(http.MethodPost, submitURL, &payloadBuf) + req, err := http.NewRequest(http.MethodPost, submitURL, &payloadBuf) + if err != nil { + return fmt.Errorf("create submit request: %w", err) + } + req.Header.Add("Content-Type", "application/json") req.Header.Add("Authorization", authHeader) From 7b21e82aaf511d36300fd9cf2dae32a1196a4f77 Mon Sep 17 00:00:00 2001 From: sentriz Date: Sun, 7 Apr 2024 18:19:56 +0100 Subject: [PATCH 4/4] fix(admin): better handing of resolve proxy path escaping fixes #493 --- cmd/gonic/gonic.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmd/gonic/gonic.go b/cmd/gonic/gonic.go index 9b0eb34..625c348 100644 --- a/cmd/gonic/gonic.go +++ b/cmd/gonic/gonic.go @@ -10,6 +10,7 @@ import ( "log" "net/http" "net/http/pprof" + "net/url" "os" "os/signal" "path" @@ -244,7 +245,9 @@ func main() { scrobblers := []scrobble.Scrobbler{lastfmClient, listenbrainzClient} resolveProxyPath := func(in string) string { - return path.Join(*confProxyPrefix, in) + url, _ := url.Parse(in) + url.Path = path.Join(*confProxyPrefix, url.Path) + return url.String() } ctrlAdmin, err := ctrladmin.New(dbc, sessDB, scannr, podcast, lastfmClient, resolveProxyPath)