mirror of
https://github.com/rclone/rclone.git
synced 2024-11-23 00:43:49 +01:00
onedrive: enhance link creation with expiry, scope, type and password
This change makes the --expire flag in `rclone link` work. It also adds the new flags --onedrive-link-type --onedrive-link-scope --onedrive-link-password See: https://forum.rclone.org/t/create-share-link-within-the-organization-only/21498
This commit is contained in:
parent
feaacfd226
commit
d58fdb10db
@ -253,8 +253,10 @@ type MoveItemRequest struct {
|
|||||||
//CreateShareLinkRequest is the request to create a sharing link
|
//CreateShareLinkRequest is the request to create a sharing link
|
||||||
//Always Type:view and Scope:anonymous for public sharing
|
//Always Type:view and Scope:anonymous for public sharing
|
||||||
type CreateShareLinkRequest struct {
|
type CreateShareLinkRequest struct {
|
||||||
Type string `json:"type"` //Link type in View, Edit or Embed
|
Type string `json:"type"` // Link type in View, Edit or Embed
|
||||||
Scope string `json:"scope,omitempty"` //Optional. Scope in anonymous, organization
|
Scope string `json:"scope,omitempty"` // Scope in anonymous, organization
|
||||||
|
Password string `json:"password,omitempty"` // The password of the sharing link that is set by the creator. Optional and OneDrive Personal only.
|
||||||
|
Expiry *time.Time `json:"expirationDateTime,omitempty"` // A String with format of yyyy-MM-ddTHH:mm:ssZ of DateTime indicates the expiration time of the permission.
|
||||||
}
|
}
|
||||||
|
|
||||||
//CreateShareLinkResponse is the response from CreateShareLinkRequest
|
//CreateShareLinkResponse is the response from CreateShareLinkRequest
|
||||||
|
@ -295,6 +295,41 @@ modification time and removes all but the last version.
|
|||||||
|
|
||||||
**NB** Onedrive personal can't currently delete versions so don't use
|
**NB** Onedrive personal can't currently delete versions so don't use
|
||||||
this flag there.
|
this flag there.
|
||||||
|
`,
|
||||||
|
Advanced: true,
|
||||||
|
}, {
|
||||||
|
Name: "link_scope",
|
||||||
|
Default: "anonymous",
|
||||||
|
Help: `Set the scope of the links created by the link command.`,
|
||||||
|
Advanced: true,
|
||||||
|
Examples: []fs.OptionExample{{
|
||||||
|
Value: "anonymous",
|
||||||
|
Help: "Anyone with the link has access, without needing to sign in. This may include people outside of your organization. Anonymous link support may be disabled by an administrator.",
|
||||||
|
}, {
|
||||||
|
Value: "organization",
|
||||||
|
Help: "Anyone signed into your organization (tenant) can use the link to get access. Only available in OneDrive for Business and SharePoint.",
|
||||||
|
}},
|
||||||
|
}, {
|
||||||
|
Name: "link_type",
|
||||||
|
Default: "view",
|
||||||
|
Help: `Set the type of the links created by the link command.`,
|
||||||
|
Advanced: true,
|
||||||
|
Examples: []fs.OptionExample{{
|
||||||
|
Value: "view",
|
||||||
|
Help: "Creates a read-only link to the item.",
|
||||||
|
}, {
|
||||||
|
Value: "edit",
|
||||||
|
Help: "Creates a read-write link to the item.",
|
||||||
|
}, {
|
||||||
|
Value: "embed",
|
||||||
|
Help: "Creates an embeddable link to the item.",
|
||||||
|
}},
|
||||||
|
}, {
|
||||||
|
Name: "link_password",
|
||||||
|
Default: "",
|
||||||
|
Help: `Set the password for links created by the link command.
|
||||||
|
|
||||||
|
At the time of writing this only works with OneDrive personal paid accounts.
|
||||||
`,
|
`,
|
||||||
Advanced: true,
|
Advanced: true,
|
||||||
}, {
|
}, {
|
||||||
@ -355,6 +390,9 @@ type Options struct {
|
|||||||
ExposeOneNoteFiles bool `config:"expose_onenote_files"`
|
ExposeOneNoteFiles bool `config:"expose_onenote_files"`
|
||||||
ServerSideAcrossConfigs bool `config:"server_side_across_configs"`
|
ServerSideAcrossConfigs bool `config:"server_side_across_configs"`
|
||||||
NoVersions bool `config:"no_versions"`
|
NoVersions bool `config:"no_versions"`
|
||||||
|
LinkScope string `config:"link_scope"`
|
||||||
|
LinkType string `config:"link_type"`
|
||||||
|
LinkPassword string `config:"link_password"`
|
||||||
Enc encoder.MultiEncoder `config:"encoding"`
|
Enc encoder.MultiEncoder `config:"encoding"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1303,8 +1341,14 @@ func (f *Fs) PublicLink(ctx context.Context, remote string, expire fs.Duration,
|
|||||||
opts := newOptsCall(info.GetID(), "POST", "/createLink")
|
opts := newOptsCall(info.GetID(), "POST", "/createLink")
|
||||||
|
|
||||||
share := api.CreateShareLinkRequest{
|
share := api.CreateShareLinkRequest{
|
||||||
Type: "view",
|
Type: f.opt.LinkType,
|
||||||
Scope: "anonymous",
|
Scope: f.opt.LinkScope,
|
||||||
|
Password: f.opt.LinkPassword,
|
||||||
|
}
|
||||||
|
|
||||||
|
if expire < fs.Duration(time.Hour*24*365*100) {
|
||||||
|
expiry := time.Now().Add(time.Duration(expire))
|
||||||
|
share.Expiry = &expiry
|
||||||
}
|
}
|
||||||
|
|
||||||
var resp *http.Response
|
var resp *http.Response
|
||||||
|
Loading…
Reference in New Issue
Block a user