Add FileInfo and get file []byte in plugin api (#9269)
* Add FileInfo and get file []byte in plugin api * Regenerated plugin mocks * Rename ReadFileAtPath to ReadFile
Этот коммит содержится в:
коммит произвёл
Christopher Speller
родитель
c2f2fda8a1
Коммит
0aa0adb911
@@ -279,6 +279,14 @@ func (api *PluginAPI) CopyFileInfos(userId string, fileIds []string) ([]string,
|
||||
return api.app.CopyFileInfos(userId, fileIds)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) GetFileInfo(fileId string) (*model.FileInfo, *model.AppError) {
|
||||
return api.app.GetFileInfo(fileId)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) ReadFile(path string) ([]byte, *model.AppError) {
|
||||
return api.app.ReadFile(path)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) KVSet(key string, value []byte) *model.AppError {
|
||||
return api.app.SetPluginKey(api.id, key, value)
|
||||
}
|
||||
|
||||
@@ -163,6 +163,12 @@ type API interface {
|
||||
// actually duplicating the uploaded files.
|
||||
CopyFileInfos(userId string, fileIds []string) ([]string, *model.AppError)
|
||||
|
||||
// GetFileInfo gets a File Info for a specific fileId
|
||||
GetFileInfo(fileId string) (*model.FileInfo, *model.AppError)
|
||||
|
||||
// ReadFileAtPath reads the file from the backend for a specific path
|
||||
ReadFile(path string) ([]byte, *model.AppError)
|
||||
|
||||
// KVSet will store a key-value pair, unique per plugin.
|
||||
KVSet(key string, value []byte) *model.AppError
|
||||
|
||||
|
||||
@@ -1850,6 +1850,64 @@ func (s *apiRPCServer) CopyFileInfos(args *Z_CopyFileInfosArgs, returns *Z_CopyF
|
||||
return nil
|
||||
}
|
||||
|
||||
type Z_GetFileInfoArgs struct {
|
||||
A string
|
||||
}
|
||||
|
||||
type Z_GetFileInfoReturns struct {
|
||||
A *model.FileInfo
|
||||
B *model.AppError
|
||||
}
|
||||
|
||||
func (g *apiRPCClient) GetFileInfo(fileId string) (*model.FileInfo, *model.AppError) {
|
||||
_args := &Z_GetFileInfoArgs{fileId}
|
||||
_returns := &Z_GetFileInfoReturns{}
|
||||
if err := g.client.Call("Plugin.GetFileInfo", _args, _returns); err != nil {
|
||||
log.Printf("RPC call to GetFileInfo API failed: %s", err.Error())
|
||||
}
|
||||
return _returns.A, _returns.B
|
||||
}
|
||||
|
||||
func (s *apiRPCServer) GetFileInfo(args *Z_GetFileInfoArgs, returns *Z_GetFileInfoReturns) error {
|
||||
if hook, ok := s.impl.(interface {
|
||||
GetFileInfo(fileId string) (*model.FileInfo, *model.AppError)
|
||||
}); ok {
|
||||
returns.A, returns.B = hook.GetFileInfo(args.A)
|
||||
} else {
|
||||
return fmt.Errorf("API GetFileInfo called but not implemented.")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Z_ReadFileArgs struct {
|
||||
A string
|
||||
}
|
||||
|
||||
type Z_ReadFileReturns struct {
|
||||
A []byte
|
||||
B *model.AppError
|
||||
}
|
||||
|
||||
func (g *apiRPCClient) ReadFile(path string) ([]byte, *model.AppError) {
|
||||
_args := &Z_ReadFileArgs{path}
|
||||
_returns := &Z_ReadFileReturns{}
|
||||
if err := g.client.Call("Plugin.ReadFile", _args, _returns); err != nil {
|
||||
log.Printf("RPC call to ReadFile API failed: %s", err.Error())
|
||||
}
|
||||
return _returns.A, _returns.B
|
||||
}
|
||||
|
||||
func (s *apiRPCServer) ReadFile(args *Z_ReadFileArgs, returns *Z_ReadFileReturns) error {
|
||||
if hook, ok := s.impl.(interface {
|
||||
ReadFile(path string) ([]byte, *model.AppError)
|
||||
}); ok {
|
||||
returns.A, returns.B = hook.ReadFile(args.A)
|
||||
} else {
|
||||
return fmt.Errorf("API ReadFile called but not implemented.")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Z_KVSetArgs struct {
|
||||
A string
|
||||
B []byte
|
||||
|
||||
@@ -449,6 +449,31 @@ func (_m *API) GetDirectChannel(userId1 string, userId2 string) (*model.Channel,
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetFileInfo provides a mock function with given fields: fileId
|
||||
func (_m *API) GetFileInfo(fileId string) (*model.FileInfo, *model.AppError) {
|
||||
ret := _m.Called(fileId)
|
||||
|
||||
var r0 *model.FileInfo
|
||||
if rf, ok := ret.Get(0).(func(string) *model.FileInfo); ok {
|
||||
r0 = rf(fileId)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.FileInfo)
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
func (_m *API) GetGroupChannel(userIds []string) (*model.Channel, *model.AppError) {
|
||||
ret := _m.Called(userIds)
|
||||
@@ -907,6 +932,31 @@ func (_m *API) PublishWebSocketEvent(event string, payload map[string]interface{
|
||||
_m.Called(event, payload, broadcast)
|
||||
}
|
||||
|
||||
// ReadFile provides a mock function with given fields: path
|
||||
func (_m *API) ReadFile(path string) ([]byte, *model.AppError) {
|
||||
ret := _m.Called(path)
|
||||
|
||||
var r0 []byte
|
||||
if rf, ok := ret.Get(0).(func(string) []byte); ok {
|
||||
r0 = rf(path)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]byte)
|
||||
}
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(string) *model.AppError); ok {
|
||||
r1 = rf(path)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// RegisterCommand provides a mock function with given fields: command
|
||||
func (_m *API) RegisterCommand(command *model.Command) error {
|
||||
ret := _m.Called(command)
|
||||
|
||||
Ссылка в новой задаче
Block a user