1
mirror of https://github.com/rclone/rclone synced 2024-11-15 14:57:03 +01:00

rc: implement operations/publiclink the equivalent of rclone link

Fixes #3042
This commit is contained in:
Nick Craig-Wood 2019-03-11 16:59:27 +00:00
parent 1318be3b0a
commit 2b05bd9a08
3 changed files with 65 additions and 2 deletions

View File

@ -556,6 +556,21 @@ This takes the following parameters
Authentication 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 contents
This takes the following parameters

View File

@ -172,7 +172,7 @@ See the [` + op.name + ` command](/commands/rclone_` + op.name + `/) command for
}
}
// Mkdir a directory
// Run a single command, eg Mkdir
func 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 directory
func 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"] = bytes
return 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
}

View File

@ -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")
}