diff options
author | dmitrysamuylovpharo <dsamuylov@pharo.com> | 2018-08-02 10:37:31 -0400 |
---|---|---|
committer | Harrison Healey <harrisonmhealey@gmail.com> | 2018-08-02 10:37:31 -0400 |
commit | 7a731d2bd162419086f3aeec98ec41dfcaa16696 (patch) | |
tree | fb2dcfd52b5ee074c2ce9e3fbacefc3156c5bc75 /app/file.go | |
parent | b728b16f9083bf5c71e9c27ad074823e8e454b04 (diff) | |
download | chat-7a731d2bd162419086f3aeec98ec41dfcaa16696.tar.gz chat-7a731d2bd162419086f3aeec98ec41dfcaa16696.tar.bz2 chat-7a731d2bd162419086f3aeec98ec41dfcaa16696.zip |
Feature/fileinfo create copy (#9198)
* Initial implementation of a CopyFileInfos function that creates new FileInfo objects copied from provided FileIds with the provided user as the creator and not linked to a post yet. This can subsequently be used to copy existing attachments from another post to attach to a new post without having to re-upload the actual files
* added a unit test for the CopyFileInfos function
* resolving pull request suggestions
Diffstat (limited to 'app/file.go')
-rw-r--r-- | app/file.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/app/file.go b/app/file.go index 7dbcdd394..7a642a956 100644 --- a/app/file.go +++ b/app/file.go @@ -604,3 +604,33 @@ func (a *App) GetFileInfo(fileId string) (*model.FileInfo, *model.AppError) { return result.Data.(*model.FileInfo), nil } } + +func (a *App) CopyFileInfos(userId string, fileIds []string) ([]string, *model.AppError) { + newFileIds := []string{} + + now := model.GetMillis() + + for _, fileId := range fileIds { + fileInfo := &model.FileInfo{} + + if result := <-a.Srv.Store.FileInfo().Get(fileId); result.Err != nil { + return nil, result.Err + } else { + fileInfo = result.Data.(*model.FileInfo) + } + + fileInfo.Id = model.NewId() + fileInfo.CreatorId = userId + fileInfo.CreateAt = now + fileInfo.UpdateAt = now + fileInfo.PostId = "" + + if result := <-a.Srv.Store.FileInfo().Save(fileInfo); result.Err != nil { + return newFileIds, result.Err + } + + newFileIds = append(newFileIds, fileInfo.Id) + } + + return newFileIds, nil +} |