[MM-63436] Replace Exif parser dependency (#30479)
* Replace Exif parser dependency * Improve forward seeking logic * Fix linting * Stop decoding upon finding tag * Use latest version of imagemeta dependency * Don't skip TIFF reader tests * Log improvements --------- Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
2454de5b4a
Коммит
f8e16780ef
@@ -650,7 +650,6 @@ func (a *App) getLinkMetadata(c request.CTX, requestURL string, timestamp int64,
|
||||
var err error
|
||||
if looksLikeAPermalink(requestURL, a.GetSiteURL()) && *a.Config().ServiceSettings.EnablePermalinkPreviews {
|
||||
permalink, err = a.getLinkMetadataForPermalink(c, requestURL)
|
||||
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
@@ -784,7 +783,7 @@ func (a *App) getLinkMetadataForURL(c request.CTX, requestURL string) (*opengrap
|
||||
|
||||
if err == nil {
|
||||
// Parse the data
|
||||
og, image, err = a.parseLinkMetadata(requestURL, body, contentType)
|
||||
og, image, err = a.parseLinkMetadata(c, requestURL, body, contentType)
|
||||
}
|
||||
og = model.TruncateOpenGraph(og) // remove unwanted length of texts
|
||||
|
||||
@@ -878,7 +877,7 @@ func peekContentType(p *bufio.Reader) string {
|
||||
return http.DetectContentType(byt)
|
||||
}
|
||||
|
||||
func (a *App) parseLinkMetadata(requestURL string, body io.Reader, contentType string) (*opengraph.OpenGraph, *model.PostImage, error) {
|
||||
func (a *App) parseLinkMetadata(rctx request.CTX, requestURL string, body io.Reader, contentType string) (*opengraph.OpenGraph, *model.PostImage, error) {
|
||||
if contentType == "" {
|
||||
bufRd := bufio.NewReader(body)
|
||||
// If the content-type is missing we try to detect it from the actual data.
|
||||
@@ -893,7 +892,7 @@ func (a *App) parseLinkMetadata(requestURL string, body io.Reader, contentType s
|
||||
|
||||
return nil, image, nil
|
||||
} else if strings.HasPrefix(contentType, "image") {
|
||||
image, err := parseImages(io.LimitReader(body, MaxMetadataImageSize))
|
||||
image, err := parseImages(rctx, requestURL, io.LimitReader(body, MaxMetadataImageSize))
|
||||
return nil, image, err
|
||||
} else if strings.HasPrefix(contentType, "text/html") {
|
||||
og := a.parseOpenGraphMetadata(requestURL, body, contentType)
|
||||
@@ -909,7 +908,7 @@ func (a *App) parseLinkMetadata(requestURL string, body io.Reader, contentType s
|
||||
return nil, nil, nil
|
||||
}
|
||||
|
||||
func parseImages(body io.Reader) (*model.PostImage, error) {
|
||||
func parseImages(rctx request.CTX, requestURL string, body io.Reader) (*model.PostImage, error) {
|
||||
// Store any data that is read for the config for any further processing
|
||||
buf := &bytes.Buffer{}
|
||||
t := io.TeeReader(body, buf)
|
||||
@@ -927,12 +926,14 @@ func parseImages(body io.Reader) (*model.PostImage, error) {
|
||||
}
|
||||
|
||||
if format == "jpeg" {
|
||||
if imageOrientation, err := imaging.GetImageOrientation(io.MultiReader(buf, body)); err == nil &&
|
||||
if imageOrientation, err := imaging.GetImageOrientation(io.MultiReader(buf, body), format); err == nil &&
|
||||
(imageOrientation == imaging.RotatedCWMirrored ||
|
||||
imageOrientation == imaging.RotatedCCW ||
|
||||
imageOrientation == imaging.RotatedCCWMirrored ||
|
||||
imageOrientation == imaging.RotatedCW) {
|
||||
image.Width, image.Height = image.Height, image.Width
|
||||
} else if err != nil {
|
||||
rctx.Logger().Warn("Failed to get image orientation", mlog.Err(err), mlog.String("request_url", requestURL))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user