diff --git a/app/post_metadata_test.go b/app/post_metadata_test.go index 6ffa0f88a7..cd18bb8f41 100644 --- a/app/post_metadata_test.go +++ b/app/post_metadata_test.go @@ -19,6 +19,7 @@ import ( "time" "github.com/dyatlov/go-opengraph/opengraph" + ogimage "github.com/dyatlov/go-opengraph/opengraph/types/image" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -1157,7 +1158,7 @@ func TestGetImagesForPost(t *testing.T) { Type: model.PostEmbedOpengraph, URL: ogURL, Data: &opengraph.OpenGraph{ - Images: []*opengraph.Image{ + Images: []*ogimage.Image{ { URL: imageURL, }, @@ -1211,7 +1212,7 @@ func TestGetImagesForPost(t *testing.T) { Type: model.PostEmbedOpengraph, URL: ogURL, Data: &opengraph.OpenGraph{ - Images: []*opengraph.Image{ + Images: []*ogimage.Image{ { SecureURL: imageURL, }, @@ -1264,7 +1265,7 @@ func TestGetImagesForPost(t *testing.T) { Type: model.PostEmbedOpengraph, URL: ogURL, Data: &opengraph.OpenGraph{ - Images: []*opengraph.Image{ + Images: []*ogimage.Image{ { URL: server.URL + "/image.png", SecureURL: imageURL, @@ -2711,7 +2712,7 @@ func TestSanitizePostMetadataForUserAndChannel(t *testing.T) { Type: model.PostEmbedOpengraph, URL: "ogURL", Data: &opengraph.OpenGraph{ - Images: []*opengraph.Image{ + Images: []*ogimage.Image{ { URL: "imageURL", }, diff --git a/go.mod b/go.mod index 927f3669c6..c56622c063 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/dgryski/dgoogauth v0.0.0-20190221195224-5a805980a5f3 github.com/disintegration/imaging v1.6.2 - github.com/dyatlov/go-opengraph v0.0.0-20210112100619-dae8665a5b09 + github.com/dyatlov/go-opengraph/opengraph v0.0.0-20220524092352-606d7b1e5f8a github.com/francoispqt/gojay v1.2.13 github.com/fsnotify/fsnotify v1.5.4 github.com/getsentry/sentry-go v0.13.0 @@ -64,7 +64,7 @@ require ( github.com/yuin/goldmark v1.4.12 golang.org/x/crypto v0.0.0-20220507011949-2cf3adece122 golang.org/x/image v0.0.0-20220413100746-70e8d0d3baa9 - golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 + golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2 golang.org/x/sync v0.0.0-20210220032951-036812b2e83c golang.org/x/text v0.3.7 golang.org/x/tools v0.1.10 diff --git a/go.sum b/go.sum index 6de36c27ae..e81b0abdd4 100644 --- a/go.sum +++ b/go.sum @@ -467,8 +467,8 @@ github.com/dsnet/golib v0.0.0-20171103203638-1ea166775780/go.mod h1:Lj+Z9rebOhdf github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= -github.com/dyatlov/go-opengraph v0.0.0-20210112100619-dae8665a5b09 h1:AQLr//nh20BzN3hIWj2+/Gt3FwSs8Nwo/nz4hMIcLPg= -github.com/dyatlov/go-opengraph v0.0.0-20210112100619-dae8665a5b09/go.mod h1:nYia/MIs9OyvXXYboPmNOj0gVWo97Wx0sde+ZuKkoM4= +github.com/dyatlov/go-opengraph/opengraph v0.0.0-20220524092352-606d7b1e5f8a h1:etIrTD8BQqzColk9nKRusM9um5+1q0iOEJLqfBMIK64= +github.com/dyatlov/go-opengraph/opengraph v0.0.0-20220524092352-606d7b1e5f8a/go.mod h1:emQhSYTXqB0xxjLITTw4EaWZ+8IIQYw+kx9GqNUKdLg= github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M= github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc= github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs= @@ -1686,8 +1686,8 @@ golang.org/x/net v0.0.0-20211216030914-fe4d6282115f/go.mod h1:9nx3DQGgdP8bBQD5qx golang.org/x/net v0.0.0-20220111093109-d55c255bac03/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= -golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 h1:HVyaeDAYux4pnY+D/SiwmLOR36ewZ4iGQIIrtnuCjFA= -golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= +golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2 h1:NWy5+hlRbC7HK+PmcXVUmW1IMyFce7to56IUvhUFm7Y= +golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/oauth2 v0.0.0-20180227000427-d7d64896b5ff/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= diff --git a/model/link_metadata.go b/model/link_metadata.go index 66d1073980..dba54836d0 100644 --- a/model/link_metadata.go +++ b/model/link_metadata.go @@ -13,6 +13,7 @@ import ( "unicode/utf8" "github.com/dyatlov/go-opengraph/opengraph" + "github.com/dyatlov/go-opengraph/opengraph/types/image" ) const ( @@ -50,7 +51,7 @@ func truncateText(original string) string { return original } -func firstNImages(images []*opengraph.Image, maxImages int) []*opengraph.Image { +func firstNImages(images []*image.Image, maxImages int) []*image.Image { if maxImages < 0 { // don't break stuff, if it's weird, go for sane defaults maxImages = LinkMetadataMaxImages } diff --git a/model/link_metadata_test.go b/model/link_metadata_test.go index 49419d08fe..c67781503f 100644 --- a/model/link_metadata_test.go +++ b/model/link_metadata_test.go @@ -11,14 +11,20 @@ import ( "unicode/utf8" "github.com/dyatlov/go-opengraph/opengraph" + "github.com/dyatlov/go-opengraph/opengraph/types/article" + "github.com/dyatlov/go-opengraph/opengraph/types/audio" + "github.com/dyatlov/go-opengraph/opengraph/types/book" + "github.com/dyatlov/go-opengraph/opengraph/types/image" + "github.com/dyatlov/go-opengraph/opengraph/types/profile" + "github.com/dyatlov/go-opengraph/opengraph/types/video" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) const BigText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus maximus faucibus ex, vitae placerat neque feugiat ac. Nam tempus libero quis pellentesque feugiat. Cras tristique diam vel condimentum viverra. Proin molestie posuere leo. Nam pulvinar, ex quis tristique cursus, turpis ante commodo elit, a dapibus est ipsum id eros. Mauris tortor dolor, posuere ac velit vitae, faucibus viverra fusce." -func sampleImage(imageName string) *opengraph.Image { - return &opengraph.Image{ +func sampleImage(imageName string) *image.Image { + return &image.Image{ URL: fmt.Sprintf("http://example.com/%s", imageName), SecureURL: fmt.Sprintf("https://example.com/%s", imageName), Type: "png", @@ -180,7 +186,7 @@ func TestLinkMetadataDeserializeDataToConcreteType(t *testing.T) { og := &opengraph.OpenGraph{ URL: "http://example.com", Description: "Hello, world!", - Images: []*opengraph.Image{ + Images: []*image.Image{ { URL: "http://example.com/image.png", }, @@ -260,24 +266,24 @@ func TestTruncateText(t *testing.T) { func TestFirstNImages(t *testing.T) { t.Run("when empty, return an empty one", func(t *testing.T) { - empty := make([]*opengraph.Image, 0) + empty := make([]*image.Image, 0) assert.Exactly(t, firstNImages(empty, 1), empty, "Should be the same element") }) t.Run("when it contains one element, return the same array", func(t *testing.T) { - one := []*opengraph.Image{sampleImage("image.png")} + one := []*image.Image{sampleImage("image.png")} assert.Exactly(t, firstNImages(one, 1), one, "Should be the same element") }) t.Run("when it contains more than one element and asking for only one, return the first one", func(t *testing.T) { - two := []*opengraph.Image{sampleImage("image.png"), sampleImage("notme.png")} + two := []*image.Image{sampleImage("image.png"), sampleImage("notme.png")} assert.True(t, strings.HasSuffix(firstNImages(two, 1)[0].URL, "image.png"), "Should be the image element") }) t.Run("when it contains less than asked, return the original", func(t *testing.T) { - two := []*opengraph.Image{sampleImage("image.png"), sampleImage("notme.png")} + two := []*image.Image{sampleImage("image.png"), sampleImage("notme.png")} assert.Equal(t, two, firstNImages(two, 10), "should be the same pointer") }) t.Run("asking for negative images", func(t *testing.T) { - six := []*opengraph.Image{ + six := []*image.Image{ sampleImage("image.png"), sampleImage("another.png"), sampleImage("yetanother.jpg"), @@ -300,18 +306,18 @@ func TestTruncateOpenGraph(t *testing.T) { SiteName: BigText, Locale: "[EN-en]", LocalesAlternate: []string{"[EN-ca]", "[ES-es]"}, - Images: []*opengraph.Image{ + Images: []*image.Image{ sampleImage("image.png"), sampleImage("another.png"), sampleImage("yetanother.jpg"), sampleImage("metoo.gif"), sampleImage("fifth.ico"), sampleImage("notme.tiff")}, - Audios: []*opengraph.Audio{{}}, - Videos: []*opengraph.Video{{}}, - Article: &opengraph.Article{}, - Book: &opengraph.Book{}, - Profile: &opengraph.Profile{}, + Audios: []*audio.Audio{{}}, + Videos: []*video.Video{{}}, + Article: &article.Article{}, + Book: &book.Book{}, + Profile: &profile.Profile{}, } result := TruncateOpenGraph(&og) assert.Nil(t, result.Article, "No article stored") diff --git a/store/storetest/link_metadata_store.go b/store/storetest/link_metadata_store.go index 0a9376225a..ce7c0d6d7c 100644 --- a/store/storetest/link_metadata_store.go +++ b/store/storetest/link_metadata_store.go @@ -9,6 +9,7 @@ import ( "time" "github.com/dyatlov/go-opengraph/opengraph" + "github.com/dyatlov/go-opengraph/opengraph/types/image" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -205,7 +206,7 @@ func testLinkMetadataStoreTypes(t *testing.T, ss store.Store) { t.Run("should save and get opengraph data", func(t *testing.T) { og := &opengraph.OpenGraph{ URL: "http://example.com", - Images: []*opengraph.Image{ + Images: []*image.Image{ { URL: "http://example.com/image.png", },