Skip to content

Commit

Permalink
Refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
ibrkhalil committed Aug 2, 2023
1 parent fab8dea commit dd91560
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions protocol/linkpreview/linkpreview.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,33 +163,20 @@ func (u OEmbedUnfurler) newOEmbedURL() (*neturl.URL, error) {
}

func handlePhotoOembedType(preview *common.LinkPreview, response OEmbedBaseResponse) {
if response.URL != "" {
preview.Thumbnail.URL = response.URL
}
}

func handleVideoOembedType(preview *common.LinkPreview, response OEmbedBaseResponse) {
if response.ThumbnailURL != "" {

preview.Thumbnail.URL = response.ThumbnailURL
}
if response.Width != 0 {
preview.Thumbnail.Width = response.ThumbnailWidth
}
if response.Height != 0 {
preview.Thumbnail.Height = response.ThumbnailHeight
}
}

func handleRichOembedType(preview *common.LinkPreview, response OEmbedBaseResponse) {
if response.ThumbnailURL != "" {
preview.Thumbnail.URL = response.ThumbnailURL
}
if response.Width != 0 {

preview.Thumbnail.Width = response.Width
}
if response.Height != 0 {
preview.Thumbnail.Height = response.Height
}
preview.Thumbnail.URL = response.ThumbnailURL
}

func (u OEmbedUnfurler) unfurl() (common.LinkPreview, error) {
Expand Down Expand Up @@ -230,6 +217,7 @@ func (u OEmbedUnfurler) unfurl() (common.LinkPreview, error) {

case "rich":
handleRichOembedType(&preview, oembedResponse)

default:
return preview, fmt.Errorf("unexpected oembed type: %v", oembedResponse.Type)
}
Expand Down

0 comments on commit dd91560

Please sign in to comment.