🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
fix(shares): honor path component of ShareURL config
Deluand7baf6ee7f95
diff --git a/core/publicurl/publicurl.go b/core/publicurl/publicurl.goindex c1b8e01c4..b0865e78b 100644--- a/core/publicurl/publicurl.go+++ b/core/publicurl/publicurl.go@@ -45,6 +45,9 @@ func PublicURL(req *http.Request, u string, params url.Values) string {}buildUrl.Scheme = shareUrl.SchemebuildUrl.Host = shareUrl.Host+ if basePath := strings.TrimRight(shareUrl.Path, "/"); basePath != "" {+ buildUrl.Path = path.Join(basePath, buildUrl.Path)+ }if len(params) > 0 {buildUrl.RawQuery = params.Encode()}diff --git a/core/publicurl/publicurl_test.go b/core/publicurl/publicurl_test.goindex 18f8f8129..a195fb9cd 100644--- a/core/publicurl/publicurl_test.go+++ b/core/publicurl/publicurl_test.go@@ -56,6 +56,31 @@ var _ = Describe("Public URL Utilities", func() {})})+ When("ShareURL includes a path", func() {+ BeforeEach(func() {+ conf.Server.ShareURL = "https://example.com/navi"+ })++ It("prepends the ShareURL path to the resource", func() {+ r, _ := http.NewRequest("GET", "http://localhost/test", nil)+ result := publicurl.PublicURL(r, "/share/img/hash", nil)+ Expect(result).To(Equal("https://example.com/navi/share/img/hash"))+ })++ It("prepends the ShareURL path and includes query parameters", func() {+ r, _ := http.NewRequest("GET", "http://localhost/test", nil)+ params := url.Values{"size": []string{"600"}}+ result := publicurl.PublicURL(r, "/share/img/hash", params)+ Expect(result).To(Equal("https://example.com/navi/share/img/hash?size=600"))+ })++ It("handles trailing slash in ShareURL path", func() {+ conf.Server.ShareURL = "https://example.com/navi/"+ result := publicurl.PublicURL(nil, "/share/img/hash", nil)+ Expect(result).To(Equal("https://example.com/navi/share/img/hash"))+ })+ })+When("ShareURL is not set", func() {BeforeEach(func() {conf.Server.ShareURL = ""