From 411a6cc472d7d813916ba8db691f1bfdf8f48b51 Mon Sep 17 00:00:00 2001 From: jackyzy823 Date: Tue, 9 Oct 2018 20:11:48 +0800 Subject: [PATCH] onedrive: add link sharing support #2178 --- backend/onedrive/api/types.go | 22 ++++++++++++++++++++++ backend/onedrive/onedrive.go | 27 +++++++++++++++++++++++++++ docs/content/overview.md | 2 +- 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/backend/onedrive/api/types.go b/backend/onedrive/api/types.go index 8c8d18126..d495ae656 100644 --- a/backend/onedrive/api/types.go +++ b/backend/onedrive/api/types.go @@ -250,6 +250,28 @@ type MoveItemRequest struct { FileSystemInfo *FileSystemInfoFacet `json:"fileSystemInfo,omitempty"` // File system information on client. Read-write. } +//CreateShareLinkRequest is the request to create a sharing link +//Always Type:view and Scope:anonymous for public sharing +type CreateShareLinkRequest struct { + Type string `json:"type"` //Link type in View, Edit or Embed + Scope string `json:"scope,omitempty"` //Optional. Scope in anonymousi, organization +} + +//CreateShareLinkResponse is the response from CreateShareLinkRequest +type CreateShareLinkResponse struct { + ID string `json:"id"` + Roles []string `json:"roles"` + Link struct { + Type string `json:"type"` + Scope string `json:"scope"` + WebURL string `json:"webUrl"` + Application struct { + ID string `json:"id"` + DisplayName string `json:"displayName"` + } `json:"application"` + } `json:"link"` +} + // AsyncOperationStatus provides information on the status of a asynchronous job progress. // // The following API calls return AsyncOperationStatus resources: diff --git a/backend/onedrive/onedrive.go b/backend/onedrive/onedrive.go index 66f58c3cb..cb4d852d5 100644 --- a/backend/onedrive/onedrive.go +++ b/backend/onedrive/onedrive.go @@ -1088,6 +1088,32 @@ func (f *Fs) Hashes() hash.Set { return hash.Set(hash.QuickXorHash) } +// PublicLink returns a link for downloading without accout. +func (f *Fs) PublicLink(remote string) (link string, err error) { + info, _, err := f.readMetaDataForPath(f.Root()) + if err != nil { + return "", err + } + opts := newOptsCall(info.ID, "POST", "/createLink") + + share := api.CreateShareLinkRequest{ + Type: "view", + Scope: "anonymous", + } + + var resp *http.Response + var result api.CreateShareLinkResponse + err = f.pacer.Call(func() (bool, error) { + resp, err = f.srv.CallJSON(&opts, &share, &result) + return shouldRetry(resp, err) + }) + if err != nil { + fmt.Println(err) + return "", err + } + return result.Link.WebURL, nil +} + // ------------------------------------------------------------ // Fs returns the parent Fs @@ -1540,6 +1566,7 @@ var ( _ fs.DirMover = (*Fs)(nil) _ fs.DirCacheFlusher = (*Fs)(nil) _ fs.Abouter = (*Fs)(nil) + _ fs.PublicLinker = (*Fs)(nil) _ fs.Object = (*Object)(nil) _ fs.MimeTyper = &Object{} _ fs.IDer = &Object{} diff --git a/docs/content/overview.md b/docs/content/overview.md index e046abe65..f4d7bc2a7 100644 --- a/docs/content/overview.md +++ b/docs/content/overview.md @@ -141,7 +141,7 @@ operations more efficient. | Jottacloud | Yes | Yes | Yes | Yes | No | Yes | No | Yes | Yes | | Mega | Yes | No | Yes | Yes | No | No | No | No [#2178](https://github.com/ncw/rclone/issues/2178) | Yes | | Microsoft Azure Blob Storage | Yes | Yes | No | No | No | Yes | No | No [#2178](https://github.com/ncw/rclone/issues/2178) | No | -| Microsoft OneDrive | Yes | Yes | Yes | Yes | No [#575](https://github.com/ncw/rclone/issues/575) | No | No | No [#2178](https://github.com/ncw/rclone/issues/2178) | Yes | +| Microsoft OneDrive | Yes | Yes | Yes | Yes | No [#575](https://github.com/ncw/rclone/issues/575) | No | No | Yes | Yes | | OpenDrive | Yes | Yes | Yes | Yes | No | No | No | No | No | | Openstack Swift | Yes † | Yes | No | No | No | Yes | Yes | No [#2178](https://github.com/ncw/rclone/issues/2178) | Yes | | pCloud | Yes | Yes | Yes | Yes | Yes | No | No | No [#2178](https://github.com/ncw/rclone/issues/2178) | Yes |