aboutsummaryrefslogtreecommitdiffstats
path: root/models/item
diff options
context:
space:
mode:
authorAdam Mathes <adam@trenchant.org>2018-04-24 21:12:44 -0700
committerAdam Mathes <adam@trenchant.org>2018-04-24 21:12:44 -0700
commit5d063b0f8f7dee735cc5eeb8e21c37a9f453bacd (patch)
tree8bd951c97eeb80ce191584c6094a12cb3ea13ee0 /models/item
parent0f46131d74bc2af6a5dd18f67546944981968c43 (diff)
downloadneko-5d063b0f8f7dee735cc5eeb8e21c37a9f453bacd.tar.gz
neko-5d063b0f8f7dee735cc5eeb8e21c37a9f453bacd.tar.bz2
neko-5d063b0f8f7dee735cc5eeb8e21c37a9f453bacd.zip
wip img proxy
Diffstat (limited to 'models/item')
-rw-r--r--models/item/item.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/models/item/item.go b/models/item/item.go
index 77ee02c..1e7e86a 100644
--- a/models/item/item.go
+++ b/models/item/item.go
@@ -3,11 +3,14 @@ package item
import (
"adammathes.com/neko/models"
"adammathes.com/neko/vlog"
+ "encoding/base64"
"fmt"
+ "github.com/PuerkitoBio/goquery"
"github.com/advancedlogic/GoOse"
"github.com/microcosm-cc/bluemonday"
"github.com/russross/blackfriday"
"log"
+ "strings"
)
type Item struct {
@@ -176,6 +179,7 @@ func Filter(max_id int64, feed_id int64, category string, unread_only bool, star
// but still may need to adjust rules
i.Title = p.Sanitize(i.Title)
i.Description = p.Sanitize(i.Description)
+ i.Description = rewriteImages(i.Description)
i.Url = p.Sanitize(i.Url)
i.FeedTitle = p.Sanitize(i.FeedTitle)
i.FeedUrl = p.Sanitize(i.FeedUrl)
@@ -196,3 +200,23 @@ func (i *Item) CleanHeaderImage() {
i.HeaderImage = ""
}
}
+
+func rewriteImages(s string) string {
+ doc, err := goquery.NewDocumentFromReader(strings.NewReader(s))
+ if err != nil {
+ panic("can not parse doc to rewrite")
+ }
+
+ doc.Find("img").Each(func(i int, img *goquery.Selection) {
+ if src, ok := img.Attr("src"); ok {
+ img.SetAttr("src", proxyURL(src))
+ }
+ })
+
+ output, _ := doc.Html()
+ return output
+}
+
+func proxyURL(url string) string {
+ return "/image/" + base64.URLEncoding.EncodeToString([]byte(url))
+}