diff options
author | Charles Kenney <Charlesc.kenney@gmail.com> | 2018-10-17 20:31:51 -0400 |
---|---|---|
committer | Jesse Hallam <jesse.hallam@gmail.com> | 2018-10-17 20:31:51 -0400 |
commit | 3bc89083fca64a1d096cc897f13d0a9b68433a8f (patch) | |
tree | 1a3b8f81f45dd39564f80288fea2ac0970bc75f9 /app | |
parent | db1123b8b28739ab78e46d8ec21f9aaa00ab520d (diff) | |
download | chat-3bc89083fca64a1d096cc897f13d0a9b68433a8f.tar.gz chat-3bc89083fca64a1d096cc897f13d0a9b68433a8f.tar.bz2 chat-3bc89083fca64a1d096cc897f13d0a9b68433a8f.zip |
Add GetFileLink method to plugin API (#9665)
* add GetFileLink method to plugin API
* Update plugin/api.go
* add translations for new plugin API errors
Diffstat (limited to 'app')
-rw-r--r-- | app/plugin_api.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/app/plugin_api.go b/app/plugin_api.go index 3574c0298..32e3d6303 100644 --- a/app/plugin_api.go +++ b/app/plugin_api.go @@ -369,6 +369,23 @@ func (api *PluginAPI) GetFileInfo(fileId string) (*model.FileInfo, *model.AppErr return api.app.GetFileInfo(fileId) } +func (api *PluginAPI) GetFileLink(fileId string) (string, *model.AppError) { + if !api.app.Config().FileSettings.EnablePublicLink { + return "", model.NewAppError("GetFileLink", "plugin_api.get_file_link.disabled.app_error", nil, "", http.StatusNotImplemented) + } + + info, err := api.app.GetFileInfo(fileId) + if err != nil { + return "", err + } + + if len(info.PostId) == 0 { + return "", model.NewAppError("GetFileLink", "plugin_api.get_file_link.no_post.app_error", nil, "file_id="+info.Id, http.StatusBadRequest) + } + + return api.app.GeneratePublicLink(api.app.GetSiteURL(), info), nil +} + func (api *PluginAPI) ReadFile(path string) ([]byte, *model.AppError) { return api.app.ReadFile(path) } |