MM-11272 Add OpenGraph and image dimension metadata to posts (#9313)
* Move OpenGraph code into its own file * Move OpenGraph image proxying to app layer * Move test file code out of api4 package * MM-11272 Add OpenGraph and image dimension metadata to posts
Этот коммит содержится в:
@@ -6,7 +6,6 @@ package api4
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/dyatlov/go-opengraph/opengraph"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
)
|
||||
@@ -27,22 +26,6 @@ func (api *API) InitOpenGraph() {
|
||||
})
|
||||
}
|
||||
|
||||
func OpenGraphDataWithProxyAddedToImageURLs(ogdata *opengraph.OpenGraph, toProxyURL func(string) string) *opengraph.OpenGraph {
|
||||
for _, image := range ogdata.Images {
|
||||
var url string
|
||||
if image.SecureURL != "" {
|
||||
url = image.SecureURL
|
||||
} else {
|
||||
url = image.URL
|
||||
}
|
||||
|
||||
image.URL = ""
|
||||
image.SecureURL = toProxyURL(url)
|
||||
}
|
||||
|
||||
return ogdata
|
||||
}
|
||||
|
||||
func getOpenGraphMetadata(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !*c.App.Config().ServiceSettings.EnableLinkPreviews {
|
||||
c.Err = model.NewAppError("getOpenGraphMetadata", "api.post.link_preview_disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
@@ -65,12 +48,6 @@ func getOpenGraphMetadata(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
og := c.App.GetOpenGraphMetadata(url)
|
||||
|
||||
// If image proxy enabled modify open graph data to feed though proxy
|
||||
if toProxyURL := c.App.ImageProxyAdder(); toProxyURL != nil {
|
||||
og = OpenGraphDataWithProxyAddedToImageURLs(og, toProxyURL)
|
||||
}
|
||||
|
||||
ogJSON, err := og.ToJSON()
|
||||
openGraphDataCache.AddWithExpiresInSecs(props["url"], ogJSON, 3600) // Cache would expire after 1 hour
|
||||
if err != nil {
|
||||
|
||||
Ссылка в новой задаче
Block a user