1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-01 17:38:37 +00:00

Proxify image enclosures

This commit is contained in:
Frédéric Guillot 2017-12-01 22:29:18 -08:00
parent 1a90c059e7
commit fb2a73c91e
9 changed files with 56 additions and 30 deletions

View file

@ -16,7 +16,7 @@ import (
)
// ImageProxyFilter rewrites image tag URLs without HTTPS to local proxy URL
func ImageProxyFilter(r *mux.Router, data string) string {
func ImageProxyFilter(router *mux.Router, data string) string {
doc, err := goquery.NewDocumentFromReader(strings.NewReader(data))
if err != nil {
return data
@ -25,8 +25,7 @@ func ImageProxyFilter(r *mux.Router, data string) string {
doc.Find("img").Each(func(i int, img *goquery.Selection) {
if srcAttr, ok := img.Attr("src"); ok {
if !url.IsHTTPS(srcAttr) {
path := route.Path(r, "proxy", "encodedURL", base64.StdEncoding.EncodeToString([]byte(srcAttr)))
img.SetAttr("src", path)
img.SetAttr("src", Proxify(router, srcAttr))
}
}
})
@ -34,3 +33,8 @@ func ImageProxyFilter(r *mux.Router, data string) string {
output, _ := doc.Find("body").First().Html()
return output
}
// Proxify returns a proxified link.
func Proxify(router *mux.Router, link string) string {
return route.Path(router, "proxy", "encodedURL", base64.StdEncoding.EncodeToString([]byte(link)))
}