[MM-61464] Fix errcheck issues in server/channels/app/post_metadata.go (#29204)
Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
d6a89c69c2
Коммит
c682f649b5
@@ -127,7 +127,6 @@ issues:
|
||||
channels/app/plugin_test.go|\
|
||||
channels/app/post.go|\
|
||||
channels/app/post_helpers_test.go|\
|
||||
channels/app/post_metadata.go|\
|
||||
channels/app/post_test.go|\
|
||||
channels/app/security_update_check.go|\
|
||||
channels/app/server.go|\
|
||||
|
||||
@@ -641,7 +641,7 @@ func (a *App) getLinkMetadata(c request.CTX, requestURL string, timestamp int64,
|
||||
if !isNewPost {
|
||||
og, image, ok = a.getLinkMetadataFromDatabase(requestURL, timestamp)
|
||||
if ok && previewedPostPropVal == "" {
|
||||
cacheLinkMetadata(requestURL, timestamp, og, image, nil)
|
||||
cacheLinkMetadata(c, requestURL, timestamp, og, image, nil)
|
||||
return og, image, nil, nil
|
||||
}
|
||||
}
|
||||
@@ -664,7 +664,7 @@ func (a *App) getLinkMetadata(c request.CTX, requestURL string, timestamp int64,
|
||||
}
|
||||
|
||||
// Write back to cache and database, even if there was an error and the results are nil
|
||||
cacheLinkMetadata(requestURL, timestamp, og, image, permalink)
|
||||
cacheLinkMetadata(c, requestURL, timestamp, og, image, permalink)
|
||||
|
||||
return og, image, permalink, err
|
||||
}
|
||||
@@ -726,7 +726,9 @@ func (a *App) getLinkMetadataFromOEmbed(c request.CTX, requestURL string, provid
|
||||
}
|
||||
|
||||
defer func() {
|
||||
io.Copy(io.Discard, res.Body)
|
||||
if _, err = io.Copy(io.Discard, res.Body); err != nil {
|
||||
c.Logger().Warn("error discarding oEmbed response body", mlog.Err(err))
|
||||
}
|
||||
res.Body.Close()
|
||||
}()
|
||||
|
||||
@@ -769,7 +771,9 @@ func (a *App) getLinkMetadataForURL(c request.CTX, requestURL string) (*opengrap
|
||||
|
||||
if body != nil {
|
||||
defer func() {
|
||||
io.Copy(io.Discard, body)
|
||||
if _, err = io.Copy(io.Discard, body); err != nil {
|
||||
c.Logger().Warn("error discarding OG image response body", mlog.Err(err))
|
||||
}
|
||||
body.Close()
|
||||
}()
|
||||
}
|
||||
@@ -851,14 +855,16 @@ func (a *App) saveLinkMetadataToDatabase(requestURL string, timestamp int64, og
|
||||
}
|
||||
}
|
||||
|
||||
func cacheLinkMetadata(requestURL string, timestamp int64, og *opengraph.OpenGraph, image *model.PostImage, permalink *model.Permalink) {
|
||||
func cacheLinkMetadata(rctx request.CTX, requestURL string, timestamp int64, og *opengraph.OpenGraph, image *model.PostImage, permalink *model.Permalink) {
|
||||
metadata := linkMetadataCache{
|
||||
OpenGraph: og,
|
||||
PostImage: image,
|
||||
Permalink: permalink,
|
||||
}
|
||||
|
||||
platform.LinkCache().SetWithExpiry(strconv.FormatInt(model.GenerateLinkMetadataHash(requestURL, timestamp), 16), metadata, platform.LinkCacheDuration)
|
||||
if err := platform.LinkCache().SetWithExpiry(strconv.FormatInt(model.GenerateLinkMetadataHash(requestURL, timestamp), 16), metadata, platform.LinkCacheDuration); err != nil {
|
||||
rctx.Logger().Warn("Failed to cache link metadata", mlog.String("request_url", requestURL), mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
// peekContentType peeks at the first 512 bytes of p, and attempts to detect
|
||||
|
||||
@@ -2119,7 +2119,7 @@ func TestGetLinkMetadata(t *testing.T) {
|
||||
timestamp := int64(1547510400000)
|
||||
title := "from cache"
|
||||
|
||||
cacheLinkMetadata(requestURL, timestamp, &opengraph.OpenGraph{Title: title}, nil, nil)
|
||||
cacheLinkMetadata(th.Context, requestURL, timestamp, &opengraph.OpenGraph{Title: title}, nil, nil)
|
||||
|
||||
t.Run("should use cache if cached entry exists", func(t *testing.T) {
|
||||
_, _, _, ok := getLinkMetadataFromCache(requestURL, timestamp)
|
||||
@@ -2484,7 +2484,7 @@ func TestGetLinkMetadata(t *testing.T) {
|
||||
requestURL := server.URL + "/error?name=" + t.Name()
|
||||
timestamp := int64(1547510400000)
|
||||
|
||||
cacheLinkMetadata(requestURL, timestamp, &opengraph.OpenGraph{Title: "cached"}, nil, nil)
|
||||
cacheLinkMetadata(th.Context, requestURL, timestamp, &opengraph.OpenGraph{Title: "cached"}, nil, nil)
|
||||
|
||||
og, img, _, err := th.App.getLinkMetadata(th.Context, requestURL, timestamp, true, "")
|
||||
assert.NotNil(t, og)
|
||||
|
||||
Ссылка в новой задаче
Block a user