Truncate data from OpenGraph metadata (#10532)
* Truncate strings from OpenGraph metada * remove unwanted opengraph fields, limit to 1 image * test helper functions * Add truncating test * fix typo * change test into not comparing for the pointer value * truncate only once * only shorten fields that were already present * set maximum of 5 images * fix original tests * fix test * limit to 5 images * fix typo * place functions below types, simplify function commentaries * Rewrite how to empty opengraph's structure
Этот коммит содержится в:
коммит произвёл
Jesús Espino
родитель
88202a76d9
Коммит
ad69002f9e
@@ -379,6 +379,7 @@ func (a *App) getLinkMetadata(requestURL string, timestamp int64, isNewPost bool
|
||||
// Parse the data
|
||||
og, image, err = a.parseLinkMetadata(requestURL, body, contentType)
|
||||
}
|
||||
og = model.TruncateOpenGraph(og) // remove unwanted length of texts
|
||||
|
||||
// Write back to cache and database, even if there was an error and the results are nil
|
||||
cacheLinkMetadata(requestURL, timestamp, og, image)
|
||||
|
||||
@@ -230,7 +230,7 @@ func TestPreparePostForClient(t *testing.T) {
|
||||
|
||||
clientPost := th.App.PreparePostForClient(post, false, false)
|
||||
|
||||
t.Run("pupulates emojis", func(t *testing.T) {
|
||||
t.Run("populates emojis", func(t *testing.T) {
|
||||
assert.ElementsMatch(t, []*model.Emoji{emoji1, emoji2, emoji3, emoji4}, clientPost.Metadata.Emojis, "should've populated post.Emojis")
|
||||
})
|
||||
|
||||
@@ -331,26 +331,18 @@ func TestPreparePostForClient(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
|
||||
clientPost := th.App.PreparePostForClient(post, false, false)
|
||||
firstEmbed := clientPost.Metadata.Embeds[0]
|
||||
ogData := firstEmbed.Data.(*opengraph.OpenGraph)
|
||||
|
||||
t.Run("populates embeds", func(t *testing.T) {
|
||||
assert.ElementsMatch(t, []*model.PostEmbed{
|
||||
{
|
||||
Type: model.POST_EMBED_OPENGRAPH,
|
||||
URL: "https://github.com/hmhealey/test-files",
|
||||
Data: &opengraph.OpenGraph{
|
||||
Description: "Contribute to hmhealey/test-files development by creating an account on GitHub.",
|
||||
SiteName: "GitHub",
|
||||
Title: "hmhealey/test-files",
|
||||
Type: "object",
|
||||
URL: "https://github.com/hmhealey/test-files",
|
||||
Images: []*opengraph.Image{
|
||||
{
|
||||
URL: "https://avatars1.githubusercontent.com/u/3277310?s=400&v=4",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}, clientPost.Metadata.Embeds)
|
||||
assert.Equal(t, firstEmbed.Type, model.POST_EMBED_OPENGRAPH)
|
||||
assert.Equal(t, firstEmbed.URL, "https://github.com/hmhealey/test-files")
|
||||
assert.Equal(t, ogData.Description, "Contribute to hmhealey/test-files development by creating an account on GitHub.")
|
||||
assert.Equal(t, ogData.SiteName, "GitHub")
|
||||
assert.Equal(t, ogData.Title, "hmhealey/test-files")
|
||||
assert.Equal(t, ogData.Type, "object")
|
||||
assert.Equal(t, ogData.URL, "https://github.com/hmhealey/test-files")
|
||||
assert.Equal(t, ogData.Images[0].URL, "https://avatars1.githubusercontent.com/u/3277310?s=400&v=4")
|
||||
})
|
||||
|
||||
t.Run("populates image dimensions", func(t *testing.T) {
|
||||
|
||||
Ссылка в новой задаче
Block a user