From 026f0152a8fdc81d9d96c9d62321a78ef65d837b Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Fri, 27 Jul 2018 05:25:53 -0700 Subject: 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. --- plugin/hooks.go | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'plugin/hooks.go') diff --git a/plugin/hooks.go b/plugin/hooks.go index 5200291f2..944909077 100644 --- a/plugin/hooks.go +++ b/plugin/hooks.go @@ -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) } -- cgit v1.2.3-1-g7c22