Return POST_EMBED_LINK for links that are not images nor og (#11723)

Этот коммит содержится в:
Miguel de la Cruz
2019-08-22 23:00:37 +02:00
коммит произвёл Ben Schumacher
родитель 5754ffc320
Коммит a9ed8fab28
3 изменённых файлов: 30 добавлений и 1 удалений

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

@@ -176,7 +176,10 @@ func (a *App) getEmbedForPost(post *model.Post, firstLink string, isNewPost bool
}, nil
}
return nil, nil
return &model.PostEmbed{
Type: model.POST_EMBED_LINK,
URL: firstLink,
}, nil
}
func (a *App) getImagesForPost(post *model.Post, imageURLs []string, isNewPost bool) map[string]*model.PostImage {

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

@@ -536,6 +536,13 @@ func TestGetEmbedForPost(t *testing.T) {
w.Header().Set("Content-Type", "image/png")
w.Write(file)
} else if r.URL.Path == "/other" {
w.Header().Set("Content-Type", "text/html")
w.Write([]byte(`
<html>
<head>
</head>
</html>`))
} else {
t.Fatal("Invalid path", r.URL.Path)
}
@@ -544,6 +551,7 @@ func TestGetEmbedForPost(t *testing.T) {
ogURL := server.URL + "/index.html"
imageURL := server.URL + "/image.png"
otherURL := server.URL + "/other"
t.Run("with link previews enabled", func(t *testing.T) {
th := Setup(t)
@@ -593,6 +601,16 @@ func TestGetEmbedForPost(t *testing.T) {
}, embed)
assert.Nil(t, err)
})
t.Run("should return a link embed", func(t *testing.T) {
embed, err := th.App.getEmbedForPost(&model.Post{}, otherURL, false)
assert.Equal(t, &model.PostEmbed{
Type: model.POST_EMBED_LINK,
URL: otherURL,
}, embed)
assert.Nil(t, err)
})
})
t.Run("with link previews disabled", func(t *testing.T) {
@@ -634,6 +652,13 @@ func TestGetEmbedForPost(t *testing.T) {
assert.Nil(t, embed)
assert.Nil(t, err)
})
t.Run("should not return a link embed", func(t *testing.T) {
embed, err := th.App.getEmbedForPost(&model.Post{}, otherURL, false)
assert.Nil(t, embed)
assert.Nil(t, err)
})
})
}

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

@@ -7,6 +7,7 @@ const (
POST_EMBED_IMAGE PostEmbedType = "image"
POST_EMBED_MESSAGE_ATTACHMENT PostEmbedType = "message_attachment"
POST_EMBED_OPENGRAPH PostEmbedType = "opengraph"
POST_EMBED_LINK PostEmbedType = "link"
)
type PostEmbedType string