Преглед изворни кода

fix: video poster image URL is encoded twice when using `MEDIA_PROXY_MODE=all`

wangb пре 1 година
родитељ
комит
f847c3e754
2 измењених фајлова са 34 додато и 6 уклоњено
  1. 25 0
      internal/mediaproxy/media_proxy_test.go
  2. 9 6
      internal/mediaproxy/rewriter.go

+ 25 - 0
internal/mediaproxy/media_proxy_test.go

@@ -553,3 +553,28 @@ func TestProxyFilterVideoPoster(t *testing.T) {
 		t.Errorf(`Not expected output: got %s`, output)
 	}
 }
+
+func TestProxyFilterVideoPosterOnce(t *testing.T) {
+	os.Clearenv()
+	os.Setenv("PROXY_OPTION", "all")
+	os.Setenv("PROXY_MEDIA_TYPES", "image,video")
+	os.Setenv("PROXY_PRIVATE_KEY", "test")
+
+	var err error
+	parser := config.NewParser()
+	config.Opts, err = parser.ParseEnvironmentVariables()
+	if err != nil {
+		t.Fatalf(`Parsing failure: %v`, err)
+	}
+
+	r := mux.NewRouter()
+	r.HandleFunc("/proxy/{encodedDigest}/{encodedURL}", func(w http.ResponseWriter, r *http.Request) {}).Name("proxy")
+
+	input := `<video poster="https://example.com/img.png" src="https://example.com/video.mp4"></video>`
+	expected := `<video poster="/proxy/aDFfroYL57q5XsojIzATT6OYUCkuVSPXYJQAVrotnLw=/aHR0cHM6Ly9leGFtcGxlLmNvbS9pbWcucG5n" src="/proxy/0y3LR8zlx8S8qJkj1qWFOO6x3a-5yf2gLWjGIJV5yyc=/aHR0cHM6Ly9leGFtcGxlLmNvbS92aWRlby5tcDQ="></video>`
+	output := RewriteDocumentWithRelativeProxyURL(r, input)
+
+	if expected != output {
+		t.Errorf(`Not expected output: got %s`, output)
+	}
+}

+ 9 - 6
internal/mediaproxy/rewriter.go

@@ -4,6 +4,7 @@
 package mediaproxy // import "miniflux.app/v2/internal/mediaproxy"
 
 import (
+	"slices"
 	"strings"
 
 	"miniflux.app/v2/internal/config"
@@ -53,13 +54,15 @@ func genericProxyRewriter(router *mux.Router, proxifyFunction urlProxyRewriter,
 				}
 			})
 
-			doc.Find("video").Each(func(i int, video *goquery.Selection) {
-				if posterAttrValue, ok := video.Attr("poster"); ok {
-					if shouldProxy(posterAttrValue, proxyOption) {
-						video.SetAttr("poster", proxifyFunction(router, posterAttrValue))
+			if !slices.Contains(config.Opts.MediaProxyResourceTypes(), "video") {
+				doc.Find("video").Each(func(i int, video *goquery.Selection) {
+					if posterAttrValue, ok := video.Attr("poster"); ok {
+						if shouldProxy(posterAttrValue, proxyOption) {
+							video.SetAttr("poster", proxifyFunction(router, posterAttrValue))
+						}
 					}
-				}
-			})
+				})
+			}
 
 		case "audio":
 			doc.Find("audio, audio source").Each(func(i int, audio *goquery.Selection) {