Add GetFileLink method to plugin API (#9665)
* add GetFileLink method to plugin API * Update plugin/api.go * add translations for new plugin API errors
Этот коммит содержится в:
коммит произвёл
Jesse Hallam
родитель
db1123b8b2
Коммит
3bc89083fc
@@ -369,6 +369,23 @@ func (api *PluginAPI) GetFileInfo(fileId string) (*model.FileInfo, *model.AppErr
|
|||||||
return api.app.GetFileInfo(fileId)
|
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) {
|
func (api *PluginAPI) ReadFile(path string) ([]byte, *model.AppError) {
|
||||||
return api.app.ReadFile(path)
|
return api.app.ReadFile(path)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4842,6 +4842,14 @@
|
|||||||
"id": "oauth.gitlab.tos.error",
|
"id": "oauth.gitlab.tos.error",
|
||||||
"translation": "GitLab's Terms of Service have updated. Please go to gitlab.com to accept them and then try logging into Mattermost again."
|
"translation": "GitLab's Terms of Service have updated. Please go to gitlab.com to accept them and then try logging into Mattermost again."
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "plugin_api.get_file_link.disabled.app_error",
|
||||||
|
"translation": "Public links have been disabled"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "plugin_api.get_file_link.no_post.app_error",
|
||||||
|
"translation": "Unable to get public link for file. File must be attached to a post that can be read."
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "plugin.api.update_user_status.bad_status",
|
"id": "plugin.api.update_user_status.bad_status",
|
||||||
"translation": "Unable to set the user status. Unknown user status."
|
"translation": "Unable to set the user status. Unknown user status."
|
||||||
|
|||||||
@@ -256,6 +256,11 @@ type API interface {
|
|||||||
// Minimum server version: 5.3
|
// Minimum server version: 5.3
|
||||||
GetFileInfo(fileId string) (*model.FileInfo, *model.AppError)
|
GetFileInfo(fileId string) (*model.FileInfo, *model.AppError)
|
||||||
|
|
||||||
|
// GetFileLink gets the public link to a file by fileId.
|
||||||
|
//
|
||||||
|
// Minimum server version: 5.6
|
||||||
|
GetFileLink(fileId string) (string, *model.AppError)
|
||||||
|
|
||||||
// ReadFileAtPath reads the file from the backend for a specific path
|
// ReadFileAtPath reads the file from the backend for a specific path
|
||||||
//
|
//
|
||||||
// Minimum server version: 5.3
|
// Minimum server version: 5.3
|
||||||
|
|||||||
@@ -2399,6 +2399,35 @@ func (s *apiRPCServer) GetFileInfo(args *Z_GetFileInfoArgs, returns *Z_GetFileIn
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Z_GetFileLinkArgs struct {
|
||||||
|
A string
|
||||||
|
}
|
||||||
|
|
||||||
|
type Z_GetFileLinkReturns struct {
|
||||||
|
A string
|
||||||
|
B *model.AppError
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *apiRPCClient) GetFileLink(fileId string) (string, *model.AppError) {
|
||||||
|
_args := &Z_GetFileLinkArgs{fileId}
|
||||||
|
_returns := &Z_GetFileLinkReturns{}
|
||||||
|
if err := g.client.Call("Plugin.GetFileLink", _args, _returns); err != nil {
|
||||||
|
log.Printf("RPC call to GetFileLink API failed: %s", err.Error())
|
||||||
|
}
|
||||||
|
return _returns.A, _returns.B
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *apiRPCServer) GetFileLink(args *Z_GetFileLinkArgs, returns *Z_GetFileLinkReturns) error {
|
||||||
|
if hook, ok := s.impl.(interface {
|
||||||
|
GetFileLink(fileId string) (string, *model.AppError)
|
||||||
|
}); ok {
|
||||||
|
returns.A, returns.B = hook.GetFileLink(args.A)
|
||||||
|
} else {
|
||||||
|
return encodableError(fmt.Errorf("API GetFileLink called but not implemented."))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
type Z_ReadFileArgs struct {
|
type Z_ReadFileArgs struct {
|
||||||
A string
|
A string
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -574,6 +574,29 @@ func (_m *API) GetFileInfo(fileId string) (*model.FileInfo, *model.AppError) {
|
|||||||
return r0, r1
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetFileLink provides a mock function with given fields: fileId
|
||||||
|
func (_m *API) GetFileLink(fileId string) (string, *model.AppError) {
|
||||||
|
ret := _m.Called(fileId)
|
||||||
|
|
||||||
|
var r0 string
|
||||||
|
if rf, ok := ret.Get(0).(func(string) string); ok {
|
||||||
|
r0 = rf(fileId)
|
||||||
|
} else {
|
||||||
|
r0 = ret.Get(0).(string)
|
||||||
|
}
|
||||||
|
|
||||||
|
var r1 *model.AppError
|
||||||
|
if rf, ok := ret.Get(1).(func(string) *model.AppError); ok {
|
||||||
|
r1 = rf(fileId)
|
||||||
|
} else {
|
||||||
|
if ret.Get(1) != nil {
|
||||||
|
r1 = ret.Get(1).(*model.AppError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return r0, r1
|
||||||
|
}
|
||||||
|
|
||||||
// GetGroupChannel provides a mock function with given fields: userIds
|
// GetGroupChannel provides a mock function with given fields: userIds
|
||||||
func (_m *API) GetGroupChannel(userIds []string) (*model.Channel, *model.AppError) {
|
func (_m *API) GetGroupChannel(userIds []string) (*model.Channel, *model.AppError) {
|
||||||
ret := _m.Called(userIds)
|
ret := _m.Called(userIds)
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user