Handle media.giphy.com and expose dimensions of gifs
This commit is contained in:
parent
757dbcd98e
commit
0feab5c6a7
|
@ -22,12 +22,16 @@ type GiphyOembedData struct {
|
|||
ProviderName string `json:"provider_name"`
|
||||
Title string `json:"title"`
|
||||
URL string `json:"url"`
|
||||
Height int `json:"height"`
|
||||
Width int `json:"width"`
|
||||
}
|
||||
|
||||
type TenorOembedData struct {
|
||||
ProviderName string `json:"provider_name"`
|
||||
ThumbnailURL string `json:"thumbnail_url"`
|
||||
AuthorName string `json:"author_name"`
|
||||
Height int `json:"height"`
|
||||
Width int `json:"width"`
|
||||
}
|
||||
|
||||
type LinkPreviewData struct {
|
||||
|
@ -35,6 +39,8 @@ type LinkPreviewData struct {
|
|||
Title string `json:"title" meta:"og:title"`
|
||||
ThumbnailURL string `json:"thumbnailUrl" meta:"og:image"`
|
||||
ContentType string `json:"contentType"`
|
||||
Height int `json:"height"`
|
||||
Width int `json:"width"`
|
||||
}
|
||||
|
||||
type Site struct {
|
||||
|
@ -172,6 +178,8 @@ func GetGiphyPreviewData(link string) (previewData LinkPreviewData, err error) {
|
|||
previewData.Title = oembedData.Title
|
||||
previewData.Site = oembedData.ProviderName
|
||||
previewData.ThumbnailURL = oembedData.URL
|
||||
previewData.Height = oembedData.Height
|
||||
previewData.Width = oembedData.Width
|
||||
|
||||
return previewData, nil
|
||||
}
|
||||
|
@ -231,6 +239,8 @@ func GetTenorPreviewData(link string) (previewData LinkPreviewData, err error) {
|
|||
previewData.Title = oembedData.AuthorName // Tenor Oembed service doesn't return title of the Gif
|
||||
previewData.Site = oembedData.ProviderName
|
||||
previewData.ThumbnailURL = oembedData.ThumbnailURL
|
||||
previewData.Height = oembedData.Height
|
||||
previewData.Width = oembedData.Width
|
||||
|
||||
return previewData, nil
|
||||
}
|
||||
|
@ -248,7 +258,7 @@ func GetLinkPreviewData(link string) (previewData LinkPreviewData, err error) {
|
|||
return GetYoutubePreviewData(link)
|
||||
case "github.com":
|
||||
return GetGithubPreviewData(link)
|
||||
case "giphy.com":
|
||||
case "giphy.com", "media.giphy.com":
|
||||
return GetGiphyPreviewData(link)
|
||||
case "gph.is":
|
||||
return GetGiphyShortURLPreviewData(link)
|
||||
|
|
|
@ -44,10 +44,14 @@ func TestGetGiphyPreviewData(t *testing.T) {
|
|||
Site: "GIPHY",
|
||||
Title: "Boston Dynamics Yes GIF by FullMag - Find & Share on GIPHY",
|
||||
ThumbnailURL: "https://media1.giphy.com/media/lcG3qwtTKSNI2i5vst/giphy.gif",
|
||||
Height: 480,
|
||||
Width: 480,
|
||||
}
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, bostonDynamicsEthGifData.Site, previewData.Site)
|
||||
require.Equal(t, bostonDynamicsEthGifData.Title, previewData.Title)
|
||||
require.Equal(t, bostonDynamicsEthGifData.Height, previewData.Height)
|
||||
require.Equal(t, bostonDynamicsEthGifData.Width, previewData.Width)
|
||||
|
||||
// Giphy oembed returns links to different servers: https://media1.giphy.com, https://media2.giphy.com and so on
|
||||
// We don't care about the server as long as other parts are equal, so we split at "." and ignore the first item
|
||||
|
@ -101,11 +105,15 @@ func TestGetTenorPreviewData(t *testing.T) {
|
|||
Site: "Tenor",
|
||||
Title: "Annihere",
|
||||
ThumbnailURL: "https://media.tenor.com/images/975f6b95d188c277ebba62d9b5511685/tenor.gif",
|
||||
Height: 400,
|
||||
Width: 600,
|
||||
}
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, gifData.Site, previewData.Site)
|
||||
require.Equal(t, gifData.Title, previewData.Title)
|
||||
require.Equal(t, gifData.ThumbnailURL, previewData.ThumbnailURL)
|
||||
require.Equal(t, gifData.Height, previewData.Height)
|
||||
require.Equal(t, gifData.Width, previewData.Width)
|
||||
|
||||
invalidTenorLink := "https://giphy.com/gifs/this-gif-does-not-exist-44444"
|
||||
_, err = GetTenorPreviewData(invalidTenorLink)
|
||||
|
|
Loading…
Reference in New Issue