"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
rc: implement operations/publiclink the equivalent of `rclone link`
Nick Craig-Wood2b05bd9a083b
diff --git a/docs/content/rc.md b/docs/content/rc.mdindex a419d57a6..1869abb3d 100644--- a/docs/content/rc.md+++ b/docs/content/rc.md@@ -556,6 +556,21 @@ This takes the following parametersAuthentication is required for this call.+### operations/publiclink: Create or retrieve a public link to the given file or folder.++This takes the following parameters++- fs - a remote name string eg "drive:"+- remote - a path within that remote eg "dir"++Returns++- url - URL of the resource++See the [link command](/commands/rclone_link/) command for more information on the above.++Authentication is required for this call.+### operations/purge: Remove a directory or container and all of its contentsThis takes the following parametersdiff --git a/fs/operations/rc.go b/fs/operations/rc.goindex 259cb0906..ef2180701 100644--- a/fs/operations/rc.go+++ b/fs/operations/rc.go@@ -172,7 +172,7 @@ See the [` + op.name + ` command](/commands/rclone_` + op.name + `/) command for}}-// Mkdir a directory+// Run a single command, eg Mkdirfunc rcSingleCommand(in rc.Params, name string, noRemote bool) (out rc.Params, err error) {var (f fs.Fs@@ -240,7 +240,7 @@ See the [size command](/commands/rclone_size/) command for more information on t})}-// Mkdir a directory+// Size a directoryfunc rcSize(in rc.Params) (out rc.Params, err error) {f, err := rc.GetFs(in)if err != nil {@@ -255,3 +255,38 @@ func rcSize(in rc.Params) (out rc.Params, err error) {out["bytes"] = bytesreturn out, nil}++func init() {+ rc.Add(rc.Call{+ Path: "operations/publiclink",+ AuthRequired: true,+ Fn: rcPublicLink,+ Title: "Create or retrieve a public link to the given file or folder.",+ Help: `This takes the following parameters++- fs - a remote name string eg "drive:"+- remote - a path within that remote eg "dir"++Returns++- url - URL of the resource++See the [link command](/commands/rclone_link/) command for more information on the above.+`,+ })+}++// Make a public link+func rcPublicLink(in rc.Params) (out rc.Params, err error) {+ f, remote, err := rc.GetFsAndRemote(in)+ if err != nil {+ return nil, err+ }+ url, err := PublicLink(f, remote)+ if err != nil {+ return nil, err+ }+ out = make(rc.Params)+ out["url"] = url+ return out, nil+}diff --git a/fs/operations/rc_test.go b/fs/operations/rc_test.goindex d4649929b..bb7075a13 100644--- a/fs/operations/rc_test.go+++ b/fs/operations/rc_test.go@@ -356,3 +356,16 @@ func TestRcSize(t *testing.T) {"bytes": int64(120),}, out)}++// operations/publiclink: Create or retrieve a public link to the given file or folder.+func TestRcPublicLink(t *testing.T) {+ r, call := rcNewRun(t, "operations/publiclink")+ defer r.Finalise()+ in := rc.Params{+ "fs": r.FremoteName,+ "remote": "",+ }+ _, err := call.Fn(in)+ require.Error(t, err)+ assert.Contains(t, err.Error(), "doesn't support public links")+}