Adding FileWillBeUploaded plugin hook (#9169)

* Adding file upload hook.

* Adding hook test for FileWillBeUploaded

* Some debugging fixes.

* Fix typo.

* Fixing double close

* Fix capitalization on docs.
Этот коммит содержится в:
Christopher Speller
2018-07-27 05:25:53 -07:00
коммит произвёл Joram Wilander
родитель 90e5e279c1
Коммит 026f0152a8
6 изменённых файлов: 203 добавлений и 9 удалений

Просмотреть файл

@@ -4,6 +4,7 @@
package plugin
import (
"io"
"net/http"
"github.com/mattermost/mattermost-server/model"
@@ -28,6 +29,7 @@ const (
UserHasJoinedTeamId = 11
UserHasLeftTeamId = 12
ChannelHasBeenCreatedId = 13
FileWillBeUploadedId = 14
TotalHooksId = iota
)
@@ -113,4 +115,11 @@ type Hooks interface {
// UserHasLeftTeam is invoked after the membership has been removed from the database.
// If actor is not nil, the user was removed from the team by the actor.
UserHasLeftTeam(c *Context, teamMember *model.TeamMember, actor *model.User)
// FileWillBeUploaded is invoked when a file is uploaded, but before it is committed to backing store.
// Read from file to retrieve the body of the uploaded file. You may modify the body of the file by writing to output.
// Returned FileInfo will be used instead of input FileInfo. Return nil to reject the file upload and include a text reason as the second argument.
// Note that this method will be called for files uploaded by plugins, including the plugin that uploaded the post.
// FileInfo.Size will be automatically set properly if you modify the file.
FileWillBeUploaded(c *Context, info *model.FileInfo, file io.Reader, output io.Writer) (*model.FileInfo, string)
}