chore: remove tenor since the api no longer returns a url (#2439)
This commit is contained in:
parent
ded81b7a51
commit
dad02df69b
|
@ -33,15 +33,6 @@ type GiphyOembedData struct {
|
||||||
Width int `json:"width"`
|
Width int `json:"width"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type TenorOembedData struct {
|
|
||||||
ProviderName string `json:"provider_name"`
|
|
||||||
ThumbnailURL string `json:"thumbnail_url"`
|
|
||||||
AuthorName string `json:"author_name"`
|
|
||||||
Title string `json:"title"`
|
|
||||||
Height int `json:"height"`
|
|
||||||
Width int `json:"width"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type LinkPreviewData struct {
|
type LinkPreviewData struct {
|
||||||
Site string `json:"site" meta:"og:site_name"`
|
Site string `json:"site" meta:"og:site_name"`
|
||||||
Title string `json:"title" meta:"og:title"`
|
Title string `json:"title" meta:"og:title"`
|
||||||
|
@ -60,7 +51,6 @@ type Site struct {
|
||||||
const YoutubeOembedLink = "https://www.youtube.com/oembed?format=json&url=%s"
|
const YoutubeOembedLink = "https://www.youtube.com/oembed?format=json&url=%s"
|
||||||
const TwitterOembedLink = "https://publish.twitter.com/oembed?url=%s"
|
const TwitterOembedLink = "https://publish.twitter.com/oembed?url=%s"
|
||||||
const GiphyOembedLink = "https://giphy.com/services/oembed?url=%s"
|
const GiphyOembedLink = "https://giphy.com/services/oembed?url=%s"
|
||||||
const TenorOembedLink = "https://tenor.com/oembed?url=%s"
|
|
||||||
|
|
||||||
var httpClient = http.Client{
|
var httpClient = http.Client{
|
||||||
Timeout: 30 * time.Second,
|
Timeout: 30 * time.Second,
|
||||||
|
@ -88,11 +78,6 @@ func LinkPreviewWhitelist() []Site {
|
||||||
Address: "twitter.com",
|
Address: "twitter.com",
|
||||||
ImageSite: false,
|
ImageSite: false,
|
||||||
},
|
},
|
||||||
Site{
|
|
||||||
Title: "Tenor GIFs",
|
|
||||||
Address: "tenor.com",
|
|
||||||
ImageSite: true,
|
|
||||||
},
|
|
||||||
Site{
|
Site{
|
||||||
Title: "GIPHY GIFs shortener",
|
Title: "GIPHY GIFs shortener",
|
||||||
Address: "gph.is",
|
Address: "gph.is",
|
||||||
|
@ -279,41 +264,6 @@ func GetGiphyShortURLPreviewData(shortURL string) (data LinkPreviewData, err err
|
||||||
return GetGiphyPreviewData(longURL)
|
return GetGiphyPreviewData(longURL)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetTenorOembed(url string) (data TenorOembedData, err error) {
|
|
||||||
oembedLink := fmt.Sprintf(TenorOembedLink, url)
|
|
||||||
|
|
||||||
jsonBytes, err := GetURLContent(oembedLink)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return data, fmt.Errorf("can't get bytes from Tenor oembed response at %s", oembedLink)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = json.Unmarshal(jsonBytes, &data)
|
|
||||||
if err != nil {
|
|
||||||
return data, fmt.Errorf("can't unmarshall json %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return data, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetTenorPreviewData(link string) (previewData LinkPreviewData, err error) {
|
|
||||||
oembedData, err := GetTenorOembed(link)
|
|
||||||
if err != nil {
|
|
||||||
return previewData, err
|
|
||||||
}
|
|
||||||
|
|
||||||
previewData.Title = oembedData.Title
|
|
||||||
if len(previewData.Title) == 0 {
|
|
||||||
previewData.Title = oembedData.AuthorName
|
|
||||||
}
|
|
||||||
previewData.Site = oembedData.ProviderName
|
|
||||||
previewData.ThumbnailURL = oembedData.ThumbnailURL
|
|
||||||
previewData.Height = oembedData.Height
|
|
||||||
previewData.Width = oembedData.Width
|
|
||||||
|
|
||||||
return previewData, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetLinkPreviewData(link string) (previewData LinkPreviewData, err error) {
|
func GetLinkPreviewData(link string) (previewData LinkPreviewData, err error) {
|
||||||
url, err := url.Parse(link)
|
url, err := url.Parse(link)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -331,8 +281,6 @@ func GetLinkPreviewData(link string) (previewData LinkPreviewData, err error) {
|
||||||
return GetGiphyPreviewData(link)
|
return GetGiphyPreviewData(link)
|
||||||
case "gph.is":
|
case "gph.is":
|
||||||
return GetGiphyShortURLPreviewData(link)
|
return GetGiphyShortURLPreviewData(link)
|
||||||
case "tenor.com":
|
|
||||||
return GetTenorPreviewData(link)
|
|
||||||
case "twitter.com":
|
case "twitter.com":
|
||||||
return GetTwitterPreviewData(link)
|
return GetTwitterPreviewData(link)
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -97,28 +97,6 @@ func TestGetGiphyShortURLPreviewData(t *testing.T) {
|
||||||
require.Equal(t, bostonDynamicsEthGifData.Title, previewData.Title)
|
require.Equal(t, bostonDynamicsEthGifData.Title, previewData.Title)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetTenorPreviewData(t *testing.T) {
|
|
||||||
validTenorLink := "https://tenor.com/view/robot-lol-slip-banana-peels-gif-5665377"
|
|
||||||
previewData, err := GetTenorPreviewData(validTenorLink)
|
|
||||||
|
|
||||||
gifData := LinkPreviewData{
|
|
||||||
Site: "Tenor",
|
|
||||||
Title: "robot",
|
|
||||||
ThumbnailURL: "https://media.tenor.com/images/fba19655163e2796d19eeeb3ae7318a0/raw",
|
|
||||||
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.Height, previewData.Height)
|
|
||||||
require.Equal(t, gifData.Width, previewData.Width)
|
|
||||||
|
|
||||||
invalidTenorLink := "https://giphy.com/gifs/this-gif-does-not-exist-44444"
|
|
||||||
_, err = GetTenorPreviewData(invalidTenorLink)
|
|
||||||
require.Error(t, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestStatusLinkPreviewData(t *testing.T) {
|
func TestStatusLinkPreviewData(t *testing.T) {
|
||||||
|
|
||||||
statusSecurityAudit := LinkPreviewData{
|
statusSecurityAudit := LinkPreviewData{
|
||||||
|
|
Loading…
Reference in New Issue