Revert "MM-45000: Change dyatlov dependency (#20443)" (#20506)

This reverts commit 680b00047f.

Reverts the recent opengraph update to fix some issues with our plugins
Этот коммит содержится в:
Ashish Bhate
2022-06-20 20:34:41 +05:30
коммит произвёл GitHub
родитель 2cd83d2f8d
Коммит 7793aebfbb
6 изменённых файлов: 23 добавлений и 33 удалений

Просмотреть файл

@@ -19,7 +19,6 @@ 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"
@@ -1158,7 +1157,7 @@ func TestGetImagesForPost(t *testing.T) {
Type: model.PostEmbedOpengraph,
URL: ogURL,
Data: &opengraph.OpenGraph{
Images: []*ogimage.Image{
Images: []*opengraph.Image{
{
URL: imageURL,
},
@@ -1212,7 +1211,7 @@ func TestGetImagesForPost(t *testing.T) {
Type: model.PostEmbedOpengraph,
URL: ogURL,
Data: &opengraph.OpenGraph{
Images: []*ogimage.Image{
Images: []*opengraph.Image{
{
SecureURL: imageURL,
},
@@ -1265,7 +1264,7 @@ func TestGetImagesForPost(t *testing.T) {
Type: model.PostEmbedOpengraph,
URL: ogURL,
Data: &opengraph.OpenGraph{
Images: []*ogimage.Image{
Images: []*opengraph.Image{
{
URL: server.URL + "/image.png",
SecureURL: imageURL,
@@ -2712,7 +2711,7 @@ func TestSanitizePostMetadataForUserAndChannel(t *testing.T) {
Type: model.PostEmbedOpengraph,
URL: "ogURL",
Data: &opengraph.OpenGraph{
Images: []*ogimage.Image{
Images: []*opengraph.Image{
{
URL: "imageURL",
},

2
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/opengraph v0.0.0-20220524092352-606d7b1e5f8a
github.com/dyatlov/go-opengraph v0.0.0-20210112100619-dae8665a5b09
github.com/francoispqt/gojay v1.2.13
github.com/fsnotify/fsnotify v1.5.4
github.com/getsentry/sentry-go v0.13.0

5
go.sum
Просмотреть файл

@@ -476,8 +476,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/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/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/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=
@@ -1694,7 +1694,6 @@ 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-20220520000938-2e3eb7b945c2/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220614195744-fb05da6f9022 h1:0qjDla5xICC2suMtyRH/QqX3B1btXTfNsIt/i4LFgO0=
golang.org/x/net v0.0.0-20220614195744-fb05da6f9022/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/oauth2 v0.0.0-20180227000427-d7d64896b5ff/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=

Просмотреть файл

@@ -13,7 +13,6 @@ import (
"unicode/utf8"
"github.com/dyatlov/go-opengraph/opengraph"
"github.com/dyatlov/go-opengraph/opengraph/types/image"
)
const (
@@ -51,7 +50,7 @@ func truncateText(original string) string {
return original
}
func firstNImages(images []*image.Image, maxImages int) []*image.Image {
func firstNImages(images []*opengraph.Image, maxImages int) []*opengraph.Image {
if maxImages < 0 { // don't break stuff, if it's weird, go for sane defaults
maxImages = LinkMetadataMaxImages
}

Просмотреть файл

@@ -11,20 +11,14 @@ 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) *image.Image {
return &image.Image{
func sampleImage(imageName string) *opengraph.Image {
return &opengraph.Image{
URL: fmt.Sprintf("http://example.com/%s", imageName),
SecureURL: fmt.Sprintf("https://example.com/%s", imageName),
Type: "png",
@@ -186,7 +180,7 @@ func TestLinkMetadataDeserializeDataToConcreteType(t *testing.T) {
og := &opengraph.OpenGraph{
URL: "http://example.com",
Description: "Hello, world!",
Images: []*image.Image{
Images: []*opengraph.Image{
{
URL: "http://example.com/image.png",
},
@@ -266,24 +260,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([]*image.Image, 0)
empty := make([]*opengraph.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 := []*image.Image{sampleImage("image.png")}
one := []*opengraph.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 := []*image.Image{sampleImage("image.png"), sampleImage("notme.png")}
two := []*opengraph.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 := []*image.Image{sampleImage("image.png"), sampleImage("notme.png")}
two := []*opengraph.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 := []*image.Image{
six := []*opengraph.Image{
sampleImage("image.png"),
sampleImage("another.png"),
sampleImage("yetanother.jpg"),
@@ -306,18 +300,18 @@ func TestTruncateOpenGraph(t *testing.T) {
SiteName: BigText,
Locale: "[EN-en]",
LocalesAlternate: []string{"[EN-ca]", "[ES-es]"},
Images: []*image.Image{
Images: []*opengraph.Image{
sampleImage("image.png"),
sampleImage("another.png"),
sampleImage("yetanother.jpg"),
sampleImage("metoo.gif"),
sampleImage("fifth.ico"),
sampleImage("notme.tiff")},
Audios: []*audio.Audio{{}},
Videos: []*video.Video{{}},
Article: &article.Article{},
Book: &book.Book{},
Profile: &profile.Profile{},
Audios: []*opengraph.Audio{{}},
Videos: []*opengraph.Video{{}},
Article: &opengraph.Article{},
Book: &opengraph.Book{},
Profile: &opengraph.Profile{},
}
result := TruncateOpenGraph(&og)
assert.Nil(t, result.Article, "No article stored")

Просмотреть файл

@@ -9,7 +9,6 @@ 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"
@@ -206,7 +205,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: []*image.Image{
Images: []*opengraph.Image{
{
URL: "http://example.com/image.png",
},