[MM-54770] Add ability to export profile pictures and fix importing them (#25042)
* add ability to export pp and fix import * remove unused nopSeeker * remove debug log * fix shadow vars * generate a warning instead of an error when unable to export profile picture * fix merge conflicts --------- Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
@@ -619,18 +619,34 @@ func (a *App) importUser(rctx request.CTX, data *imports.UserImportData, dryRun
|
||||
}
|
||||
|
||||
if data.ProfileImage != nil {
|
||||
var file io.ReadCloser
|
||||
var file io.ReadSeeker
|
||||
var err error
|
||||
if data.ProfileImageData != nil {
|
||||
file, err = data.ProfileImageData.Open()
|
||||
// *zip.File does not support Seek, and we need a seeker to reset the cursor position after checking the picture dimension
|
||||
var f io.ReadCloser
|
||||
f, err = data.ProfileImageData.Open()
|
||||
if err != nil {
|
||||
rctx.Logger().Warn("Unable to open the profile image data.", mlog.Err(err))
|
||||
} else {
|
||||
limitedReader := io.LimitReader(f, *a.Config().FileSettings.MaxFileSize)
|
||||
var b []byte
|
||||
b, err = io.ReadAll(limitedReader)
|
||||
if err != nil {
|
||||
rctx.Logger().Warn("Unable to read all bytes from profile picture.", mlog.Err(err))
|
||||
} else {
|
||||
file = bytes.NewReader(b)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
file, err = os.Open(*data.ProfileImage)
|
||||
if err != nil {
|
||||
rctx.Logger().Warn("Unable to open the profile image.", mlog.Err(err))
|
||||
} else {
|
||||
defer file.(*os.File).Close()
|
||||
}
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
rctx.Logger().Warn("Unable to open the profile image.", mlog.Err(err))
|
||||
} else {
|
||||
defer file.Close()
|
||||
if file != nil {
|
||||
if limitErr := checkImageLimits(file, *a.Config().FileSettings.MaxImageResolution); limitErr != nil {
|
||||
return model.NewAppError("SetProfileImage", "api.user.upload_profile_user.check_image_limits.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user