fix: video poster image URL is encoded twice when using MEDIA_PROXY_MODE=all
This commit is contained in:
parent
4ca19d123a
commit
f847c3e754
2 changed files with 34 additions and 6 deletions
|
@ -553,3 +553,28 @@ func TestProxyFilterVideoPoster(t *testing.T) {
|
||||||
t.Errorf(`Not expected output: got %s`, output)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
package mediaproxy // import "miniflux.app/v2/internal/mediaproxy"
|
package mediaproxy // import "miniflux.app/v2/internal/mediaproxy"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"miniflux.app/v2/internal/config"
|
"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 !slices.Contains(config.Opts.MediaProxyResourceTypes(), "video") {
|
||||||
if posterAttrValue, ok := video.Attr("poster"); ok {
|
doc.Find("video").Each(func(i int, video *goquery.Selection) {
|
||||||
if shouldProxy(posterAttrValue, proxyOption) {
|
if posterAttrValue, ok := video.Attr("poster"); ok {
|
||||||
video.SetAttr("poster", proxifyFunction(router, posterAttrValue))
|
if shouldProxy(posterAttrValue, proxyOption) {
|
||||||
|
video.SetAttr("poster", proxifyFunction(router, posterAttrValue))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
})
|
}
|
||||||
|
|
||||||
case "audio":
|
case "audio":
|
||||||
doc.Find("audio, audio source").Each(func(i int, audio *goquery.Selection) {
|
doc.Find("audio, audio source").Each(func(i int, audio *goquery.Selection) {
|
||||||
|
|
Loading…
Reference in a new issue