[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
@@ -770,11 +770,8 @@ func (t *UploadFileTask) init(a *App) {
|
||||
// upload, returning a rejection error. In this case FileInfo would have
|
||||
// contained the last "good" FileInfo before the execution of that plugin.
|
||||
func (a *App) UploadFileX(c request.CTX, channelID, name string, input io.Reader,
|
||||
opts ...func(*UploadFileTask)) (*model.FileInfo, *model.AppError) {
|
||||
c = c.WithLogger(c.Logger().With(
|
||||
mlog.String("file_name", name),
|
||||
))
|
||||
|
||||
opts ...func(*UploadFileTask),
|
||||
) (*model.FileInfo, *model.AppError) {
|
||||
t := &UploadFileTask{
|
||||
Logger: c.Logger(),
|
||||
ChannelId: filepath.Base(channelID),
|
||||
@@ -790,6 +787,12 @@ func (a *App) UploadFileX(c request.CTX, channelID, name string, input io.Reader
|
||||
o(t)
|
||||
}
|
||||
|
||||
c = c.WithLogger(c.Logger().With(
|
||||
mlog.String("file_name", name),
|
||||
mlog.String("channel_id", channelID),
|
||||
mlog.String("user_id", t.UserId),
|
||||
))
|
||||
|
||||
if *a.Config().FileSettings.DriverName == "" {
|
||||
return nil, t.newAppError("api.file.upload_file.storage.app_error", http.StatusNotImplemented)
|
||||
}
|
||||
@@ -880,14 +883,14 @@ func (t *UploadFileTask) preprocessImage() *model.AppError {
|
||||
}
|
||||
|
||||
// If we fail to decode, return "as is".
|
||||
w, h, err := imaging.GetDimensions(t.teeInput)
|
||||
cfg, format, err := t.imgDecoder.DecodeConfig(t.teeInput)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
t.fileinfo.Width = w
|
||||
t.fileinfo.Height = h
|
||||
t.fileinfo.Width = cfg.Width
|
||||
t.fileinfo.Height = cfg.Height
|
||||
|
||||
if err = checkImageResolutionLimit(w, h, t.maxImageRes); err != nil {
|
||||
if err = checkImageResolutionLimit(cfg.Width, cfg.Height, t.maxImageRes); err != nil {
|
||||
return t.newAppError("api.file.upload_file.large_image_detailed.app_error", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
@@ -899,12 +902,14 @@ func (t *UploadFileTask) preprocessImage() *model.AppError {
|
||||
// check the image orientation with goexif; consume the bytes we
|
||||
// already have first, then keep Tee-ing from input.
|
||||
// TODO: try to reuse exif's .Raw buffer rather than Tee-ing
|
||||
if t.imageOrientation, err = imaging.GetImageOrientation(io.MultiReader(bytes.NewReader(t.buf.Bytes()), t.teeInput)); err == nil &&
|
||||
if t.imageOrientation, err = imaging.GetImageOrientation(io.MultiReader(bytes.NewReader(t.buf.Bytes()), t.teeInput), format); err == nil &&
|
||||
(t.imageOrientation == imaging.RotatedCWMirrored ||
|
||||
t.imageOrientation == imaging.RotatedCCW ||
|
||||
t.imageOrientation == imaging.RotatedCCWMirrored ||
|
||||
t.imageOrientation == imaging.RotatedCW) {
|
||||
t.fileinfo.Width, t.fileinfo.Height = t.fileinfo.Height, t.fileinfo.Width
|
||||
} else if err != nil {
|
||||
t.Logger.Warn("Failed to get image orientation", mlog.Err(err))
|
||||
}
|
||||
|
||||
// For animated GIFs disable the preview; since we have to Decode gifs
|
||||
@@ -1045,12 +1050,14 @@ func (a *App) DoUploadFileExpectModification(c request.CTX, now time.Time, rawTe
|
||||
return nil, data, err
|
||||
}
|
||||
|
||||
if orientation, err := imaging.GetImageOrientation(bytes.NewReader(data)); err == nil &&
|
||||
if orientation, err := imaging.GetImageOrientation(bytes.NewReader(data), info.MimeType); err == nil &&
|
||||
(orientation == imaging.RotatedCWMirrored ||
|
||||
orientation == imaging.RotatedCCW ||
|
||||
orientation == imaging.RotatedCCWMirrored ||
|
||||
orientation == imaging.RotatedCW) {
|
||||
info.Width, info.Height = info.Height, info.Width
|
||||
} else if err != nil {
|
||||
c.Logger().Warn("Failed to get image orientation", mlog.Err(err))
|
||||
}
|
||||
|
||||
info.Id = model.NewId()
|
||||
@@ -1161,7 +1168,7 @@ func prepareImage(rctx request.CTX, imgDecoder *imaging.Decoder, imgData io.Read
|
||||
imgData.Seek(0, io.SeekStart)
|
||||
|
||||
// Flip the image to be upright
|
||||
orientation, err := imaging.GetImageOrientation(imgData)
|
||||
orientation, err := imaging.GetImageOrientation(imgData, imgType)
|
||||
if err != nil {
|
||||
rctx.Logger().Debug("GetImageOrientation failed", mlog.Err(err))
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user