forked from TrueCloudLab/rclone
rc: add NeedsRequest to call.
This commit is contained in:
parent
2121c0fa23
commit
d0de39ebcd
3 changed files with 11 additions and 5 deletions
|
@ -138,10 +138,11 @@ func rcMoveOrCopyFile(ctx context.Context, in rc.Params, cp bool) (out rc.Params
|
|||
|
||||
func init() {
|
||||
for _, op := range []struct {
|
||||
name string
|
||||
title string
|
||||
help string
|
||||
noRemote bool
|
||||
name string
|
||||
title string
|
||||
help string
|
||||
noRemote bool
|
||||
needsRequest bool
|
||||
}{
|
||||
{name: "mkdir", title: "Make a destination directory or container"},
|
||||
{name: "rmdir", title: "Remove an empty directory or container"},
|
||||
|
@ -160,6 +161,7 @@ func init() {
|
|||
rc.Add(rc.Call{
|
||||
Path: "operations/" + op.name,
|
||||
AuthRequired: true,
|
||||
NeedsRequest: op.needsRequest,
|
||||
Fn: func(ctx context.Context, in rc.Params) (rc.Params, error) {
|
||||
return rcSingleCommand(ctx, in, op.name, op.noRemote)
|
||||
},
|
||||
|
|
|
@ -248,7 +248,6 @@ func (s *Server) handlePost(w http.ResponseWriter, r *http.Request, path string)
|
|||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Find the call
|
||||
call := rc.Calls.Get(path)
|
||||
if call == nil {
|
||||
|
@ -261,6 +260,10 @@ func (s *Server) handlePost(w http.ResponseWriter, r *http.Request, path string)
|
|||
writeError(path, in, w, errors.Errorf("authentication must be set up on the rc server to use %q or the --rc-no-auth flag must be in use", path), http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
if call.NeedsRequest {
|
||||
// Add the request to RC
|
||||
in["_request"] = r
|
||||
}
|
||||
|
||||
// Check to see if it is async or not
|
||||
isAsync, err := in.GetBool("_async")
|
||||
|
|
|
@ -22,6 +22,7 @@ type Call struct {
|
|||
Title string // help for the function
|
||||
AuthRequired bool // if set then this call requires authorisation to be set
|
||||
Help string // multi-line markdown formatted help
|
||||
NeedsRequest bool // if set then this call will be passed the original request object as _request
|
||||
}
|
||||
|
||||
// Registry holds the list of all the registered remote control functions
|
||||
|
|
Loading…
Reference in a new issue