summaryrefslogtreecommitdiffstats
path: root/plugin/hooks.go
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2018-07-27 05:25:53 -0700
committerJoram Wilander <jwawilander@gmail.com>2018-07-27 08:25:53 -0400
commit026f0152a8fdc81d9d96c9d62321a78ef65d837b (patch)
treef986df6073db16b6ce3ca0bfeb3cfe328960125d /plugin/hooks.go
parent90e5e279c175b238d58432acb5eb6422ddfe22e7 (diff)
downloadchat-026f0152a8fdc81d9d96c9d62321a78ef65d837b.tar.gz
chat-026f0152a8fdc81d9d96c9d62321a78ef65d837b.tar.bz2
chat-026f0152a8fdc81d9d96c9d62321a78ef65d837b.zip
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.
Diffstat (limited to 'plugin/hooks.go')
-rw-r--r--plugin/hooks.go9
1 files changed, 9 insertions, 0 deletions
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)
}