diff options
author | Wim <wim@42.be> | 2021-10-17 00:47:22 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-17 00:47:22 +0200 |
commit | 4dd8bae5c91fa4aef09d865d8fef1acd84f90925 (patch) | |
tree | ffad9b242daccaf8c86d1c1fbd59032302bd3be9 /vendor/github.com/mattermost/mattermost-server/v5/model/file_info.go | |
parent | 7ae45c42e712bd0e66c101f3f714c05aa1dc2104 (diff) | |
download | matterbridge-msglm-4dd8bae5c91fa4aef09d865d8fef1acd84f90925.tar.gz matterbridge-msglm-4dd8bae5c91fa4aef09d865d8fef1acd84f90925.tar.bz2 matterbridge-msglm-4dd8bae5c91fa4aef09d865d8fef1acd84f90925.zip |
Update dependencies (#1610)
* Update dependencies
* Update module to go 1.17
Diffstat (limited to 'vendor/github.com/mattermost/mattermost-server/v5/model/file_info.go')
-rw-r--r-- | vendor/github.com/mattermost/mattermost-server/v5/model/file_info.go | 38 |
1 files changed, 12 insertions, 26 deletions
diff --git a/vendor/github.com/mattermost/mattermost-server/v5/model/file_info.go b/vendor/github.com/mattermost/mattermost-server/v5/model/file_info.go index c622b8f2..2bad9023 100644 --- a/vendor/github.com/mattermost/mattermost-server/v5/model/file_info.go +++ b/vendor/github.com/mattermost/mattermost-server/v5/model/file_info.go @@ -4,19 +4,14 @@ package model import ( - "bytes" "encoding/json" "image" "image/gif" - "image/jpeg" "io" "mime" "net/http" "path/filepath" "strings" - - "github.com/disintegration/imaging" - "github.com/mattermost/mattermost-server/v5/mlog" ) const ( @@ -44,6 +39,7 @@ type FileInfo struct { Id string `json:"id"` CreatorId string `json:"user_id"` PostId string `json:"post_id,omitempty"` + ChannelId string `db:"-" json:"channel_id"` CreateAt int64 `json:"create_at"` UpdateAt int64 `json:"update_at"` DeleteAt int64 `json:"delete_at"` @@ -59,6 +55,7 @@ type FileInfo struct { HasPreviewImage bool `json:"has_preview_image,omitempty"` MiniPreview *[]byte `json:"mini_preview"` // declared as *[]byte to avoid postgres/mysql differences in deserialization Content string `json:"-"` + RemoteId *string `json:"remote_id"` } func (fi *FileInfo) ToJson() string { @@ -72,9 +69,8 @@ func FileInfoFromJson(data io.Reader) *FileInfo { var fi FileInfo if err := decoder.Decode(&fi); err != nil { return nil - } else { - return &fi } + return &fi } func FileInfosToJson(infos []*FileInfo) string { @@ -88,9 +84,8 @@ func FileInfosFromJson(data io.Reader) []*FileInfo { var infos []*FileInfo if err := decoder.Decode(&infos); err != nil { return nil - } else { - return infos } + return infos } func (fi *FileInfo) PreSave() { @@ -105,6 +100,10 @@ func (fi *FileInfo) PreSave() { if fi.UpdateAt < fi.CreateAt { fi.UpdateAt = fi.CreateAt } + + if fi.RemoteId == nil { + fi.RemoteId = NewString("") + } } func (fi *FileInfo) IsValid() *AppError { @@ -116,7 +115,7 @@ func (fi *FileInfo) IsValid() *AppError { return NewAppError("FileInfo.IsValid", "model.file_info.is_valid.user_id.app_error", nil, "id="+fi.Id, http.StatusBadRequest) } - if len(fi.PostId) != 0 && !IsValidId(fi.PostId) { + if fi.PostId != "" && !IsValidId(fi.PostId) { return NewAppError("FileInfo.IsValid", "model.file_info.is_valid.post_id.app_error", nil, "id="+fi.Id, http.StatusBadRequest) } @@ -157,19 +156,6 @@ func NewInfo(name string) *FileInfo { return info } -func GenerateMiniPreviewImage(img image.Image) *[]byte { - preview := imaging.Resize(img, 16, 16, imaging.Lanczos) - - buf := new(bytes.Buffer) - - if err := jpeg.Encode(buf, preview, &jpeg.Options{Quality: 90}); err != nil { - mlog.Error("Unable to encode image as mini preview jpg", mlog.Err(err)) - return nil - } - data := buf.Bytes() - return &data -} - func GetInfoForBytes(name string, data io.ReadSeeker, size int) (*FileInfo, *AppError) { info := &FileInfo{ Name: name, @@ -196,13 +182,13 @@ func GetInfoForBytes(name string, data io.ReadSeeker, size int) (*FileInfo, *App if info.MimeType == "image/gif" { // Just show the gif itself instead of a preview image for animated gifs data.Seek(0, io.SeekStart) - if gifConfig, err := gif.DecodeAll(data); err != nil { + gifConfig, err := gif.DecodeAll(data) + if err != nil { // Still return the rest of the info even though it doesn't appear to be an actual gif info.HasPreviewImage = true return info, NewAppError("GetInfoForBytes", "model.file_info.get.gif.app_error", nil, err.Error(), http.StatusBadRequest) - } else { - info.HasPreviewImage = len(gifConfig.Image) == 1 } + info.HasPreviewImage = len(gifConfig.Image) == 1 } else { info.HasPreviewImage = true } |