forked from TrueCloudLab/rclone
rc: implement operations/publiclink the equivalent of rclone link
Fixes #3042
This commit is contained in:
parent
1318be3b0a
commit
2b05bd9a08
3 changed files with 65 additions and 2 deletions
|
@ -556,6 +556,21 @@ This takes the following parameters
|
||||||
|
|
||||||
Authentication is required for this call.
|
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
|
### operations/purge: Remove a directory or container and all of its contents
|
||||||
|
|
||||||
This takes the following parameters
|
This takes the following parameters
|
||||||
|
|
|
@ -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) {
|
func rcSingleCommand(in rc.Params, name string, noRemote bool) (out rc.Params, err error) {
|
||||||
var (
|
var (
|
||||||
f fs.Fs
|
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) {
|
func rcSize(in rc.Params) (out rc.Params, err error) {
|
||||||
f, err := rc.GetFs(in)
|
f, err := rc.GetFs(in)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -255,3 +255,38 @@ func rcSize(in rc.Params) (out rc.Params, err error) {
|
||||||
out["bytes"] = bytes
|
out["bytes"] = bytes
|
||||||
return out, nil
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -356,3 +356,16 @@ func TestRcSize(t *testing.T) {
|
||||||
"bytes": int64(120),
|
"bytes": int64(120),
|
||||||
}, out)
|
}, 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")
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue