Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

rc: add NeedsRequest to call.

Chaitanyad0de39ebcd2c
diff --git a/fs/operations/rc.go b/fs/operations/rc.go
index 6482612bc..5bc0c7033 100644
--- a/fs/operations/rc.go
+++ b/fs/operations/rc.go
@@ -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)
},
diff --git a/fs/rc/rcserver/rcserver.go b/fs/rc/rcserver/rcserver.go
index 0bfff0c7b..7f324c21b 100644
--- a/fs/rc/rcserver/rcserver.go
+++ b/fs/rc/rcserver/rcserver.go
@@ -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")
diff --git a/fs/rc/registry.go b/fs/rc/registry.go
index eb452ce60..f2f5a1fb8 100644
--- a/fs/rc/registry.go
+++ b/fs/rc/registry.go
@@ -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