Skip to content

Commit

Permalink
richcontent: Use at biggest large image for embedding
Browse files Browse the repository at this point in the history
  • Loading branch information
robertabcd committed Dec 24, 2021
1 parent e7724ac commit cc8a67e
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions richcontent/url_based_finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,20 @@ func handleSameSchemeImage(ctx context.Context, urlBytes []byte, match MatchIndi
}

func handleImgurSingle(ctx context.Context, urlBytes []byte, match MatchIndices) ([]Component, error) {
ext, _ := extcache.FromContext(ctx)
if ext == nil {
cache, _ := extcache.FromContext(ctx)
if cache == nil {
return handleImgurMulti(ctx, urlBytes, match)
}
id := string(match.ByteSliceOf(urlBytes, 1)) + "." + string(match.ByteSliceOf(urlBytes, 2))
escapedId := url.PathEscape(id)
src, err := ext.Generate("https://i.imgur.com/" + escapedId)
id := string(match.ByteSliceOf(urlBytes, 1))
ext := string(match.ByteSliceOf(urlBytes, 2))
// Use at biggest large image.
if n := len(id); n > 0 && id[n-1] == 'h' {
id = id[:n-1] + "l"
} else {
id += "l"
}
escapedId := url.PathEscape(id + "." + ext)
src, err := cache.Generate("https://i.imgur.com/" + escapedId)
if err != nil {
return nil, nil // Silently ignore
}
Expand Down

0 comments on commit cc8a67e

Please sign in to comment.