Add status.im and medium.com to link unfurling
This commit is contained in:
parent
add5040b48
commit
6ac1c43926
|
@ -59,6 +59,11 @@ var httpClient = http.Client{
|
|||
|
||||
func LinkPreviewWhitelist() []Site {
|
||||
return []Site{
|
||||
Site{
|
||||
Title: "Status",
|
||||
Address: "our.status.im",
|
||||
ImageSite: false,
|
||||
},
|
||||
Site{
|
||||
Title: "YouTube",
|
||||
Address: "youtube.com",
|
||||
|
@ -94,6 +99,11 @@ func LinkPreviewWhitelist() []Site {
|
|||
Address: "github.com",
|
||||
ImageSite: false,
|
||||
},
|
||||
Site{
|
||||
Title: "Medium",
|
||||
Address: "medium.com",
|
||||
ImageSite: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -136,7 +146,7 @@ func GetYoutubePreviewData(link string) (previewData LinkPreviewData, err error)
|
|||
return previewData, nil
|
||||
}
|
||||
|
||||
func GetGithubPreviewData(link string) (previewData LinkPreviewData, err error) {
|
||||
func GetGenericLinkPreviewData(link string) (previewData LinkPreviewData, err error) {
|
||||
// nolint: gosec
|
||||
res, err := httpClient.Get(link)
|
||||
|
||||
|
@ -256,8 +266,8 @@ func GetLinkPreviewData(link string) (previewData LinkPreviewData, err error) {
|
|||
switch hostname {
|
||||
case "youtube.com", "youtu.be", "www.youtube.com":
|
||||
return GetYoutubePreviewData(link)
|
||||
case "github.com":
|
||||
return GetGithubPreviewData(link)
|
||||
case "github.com", "our.status.im", "medium.com":
|
||||
return GetGenericLinkPreviewData(link)
|
||||
case "giphy.com", "media.giphy.com":
|
||||
return GetGiphyPreviewData(link)
|
||||
case "gph.is":
|
||||
|
|
|
@ -119,3 +119,33 @@ func TestGetTenorPreviewData(t *testing.T) {
|
|||
_, err = GetTenorPreviewData(invalidTenorLink)
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
func TestStatusLinkPreviewData(t *testing.T) {
|
||||
|
||||
statusSecurityAudit := LinkPreviewData{
|
||||
Site: "Our Status",
|
||||
Title: "What is a Security Audit, When You Should Get One, and How to Prepare.",
|
||||
ThumbnailURL: "https://our.status.im/content/images/2021/02/Security-Audit-Header.png",
|
||||
}
|
||||
|
||||
previewData, err := GetLinkPreviewData("https://our.status.im/what-is-a-security-audit-when-you-should-get-one-and-how-to-prepare/")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, statusSecurityAudit.Site, previewData.Site)
|
||||
require.Equal(t, statusSecurityAudit.Title, previewData.Title)
|
||||
require.Equal(t, statusSecurityAudit.ThumbnailURL, previewData.ThumbnailURL)
|
||||
}
|
||||
|
||||
func TestMediumLinkPreviewData(t *testing.T) {
|
||||
|
||||
statusSecurityAudit := LinkPreviewData{
|
||||
Site: "Medium",
|
||||
Title: "A Look at the Status.im ICO Token Distribution",
|
||||
ThumbnailURL: "https://miro.medium.com/max/700/1*Smc0y_TOL1XsofS1wxa3rg.jpeg",
|
||||
}
|
||||
|
||||
previewData, err := GetLinkPreviewData("https://medium.com/the-bitcoin-podcast-blog/a-look-at-the-status-im-ico-token-distribution-f5bcf7f00907")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, statusSecurityAudit.Site, previewData.Site)
|
||||
require.Equal(t, statusSecurityAudit.Title, previewData.Title)
|
||||
require.Equal(t, statusSecurityAudit.ThumbnailURL, previewData.ThumbnailURL)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue