Skip to content

Commit

Permalink
richcontent: Remove imgur embedding
Browse files Browse the repository at this point in the history
  • Loading branch information
robertabcd committed Dec 24, 2021
1 parent af79802 commit b34ddb9
Showing 1 changed file with 1 addition and 14 deletions.
15 changes: 1 addition & 14 deletions richcontent/url_based_finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"html"
"net/url"
"regexp"
"strings"

"github.com/ptt/pttweb/extcache"
"golang.org/x/net/context"
Expand Down Expand Up @@ -39,7 +38,6 @@ type UrlPattern struct {
var defaultUrlPatterns = []*UrlPattern{
newUrlPattern(`^https?://(?:www\.youtube\.com/watch\?(?:.+&)*v=|youtu\.be/)([\w\-]+)`, handleYoutube),
newUrlPattern(`^https?://i\.imgur\.com/([\w]+)\.((?i)png|jpeg|jpg|gif)$`, handleImgurSingle), // Note: cuz some users use http
newUrlPattern(`^https?://imgur\.com/([,\w]+)(?:\#(\d+))?[^/]*$`, handleImgurMulti),
newUrlPattern(`^http://picmoe\.net/d\.php\?id=(\d+)`, handlePicmoe),
newUrlPattern(`\.(?i:png|jpeg|jpg|gif)$`, handleGenericImage),
}
Expand Down Expand Up @@ -73,7 +71,7 @@ func handleSameSchemeImage(ctx context.Context, urlBytes []byte, match MatchIndi
func handleImgurSingle(ctx context.Context, urlBytes []byte, match MatchIndices) ([]Component, error) {
cache, _ := extcache.FromContext(ctx)
if cache == nil {
return handleImgurMulti(ctx, urlBytes, match)
return nil, nil
}
id := string(match.ByteSliceOf(urlBytes, 1))
ext := string(match.ByteSliceOf(urlBytes, 2))
Expand All @@ -91,17 +89,6 @@ func handleImgurSingle(ctx context.Context, urlBytes []byte, match MatchIndices)
return []Component{MakeComponent(imageHtmlTag(src))}, nil
}

func handleImgurMulti(ctx context.Context, urlBytes []byte, match MatchIndices) ([]Component, error) {
var comps []Component
for _, id := range strings.Split(string(match.ByteSliceOf(urlBytes, 1)), ",") {
escapedId := url.PathEscape(id)
comps = append(comps, MakeComponent(
fmt.Sprintf(`<blockquote class="imgur-embed-pub" lang="en" data-id="%s"><a href="//imgur.com/%s"></a></blockquote><script async src="//s.imgur.com/min/embed.js" charset="utf-8"></script>`, escapedId, escapedId),
))
}
return comps, nil
}

func handlePicmoe(ctx context.Context, urlBytes []byte, match MatchIndices) ([]Component, error) {
link := fmt.Sprintf(`http://picmoe.net/src/%ss.jpg`, string(match.ByteSliceOf(urlBytes, 1)))
return []Component{MakeComponent(imageHtmlTag(link))}, nil
Expand Down

0 comments on commit b34ddb9

Please sign in to comment.