From 3bc89083fca64a1d096cc897f13d0a9b68433a8f Mon Sep 17 00:00:00 2001 From: Charles Kenney Date: Wed, 17 Oct 2018 20:31:51 -0400 Subject: Add GetFileLink method to plugin API (#9665) * add GetFileLink method to plugin API * Update plugin/api.go * add translations for new plugin API errors --- app/plugin_api.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'app') 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) } -- cgit v1.2.3-1-g7c22