mirror of
https://github.com/rclone/rclone.git
synced 2025-02-17 02:50:59 +01:00
onedrive: Support addressing site by server-relative URL (#4761)
This commit is contained in:
parent
a97effa27c
commit
ef2bfb9718
@ -12,6 +12,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path"
|
"path"
|
||||||
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -120,9 +121,18 @@ func init() {
|
|||||||
var opts rest.Opts
|
var opts rest.Opts
|
||||||
var finalDriveID string
|
var finalDriveID string
|
||||||
var siteID string
|
var siteID string
|
||||||
|
var relativePath string
|
||||||
switch config.Choose("Your choice",
|
switch config.Choose("Your choice",
|
||||||
[]string{"onedrive", "sharepoint", "driveid", "siteid", "search"},
|
[]string{"onedrive", "sharepoint", "url", "search", "driveid", "siteid", "path"},
|
||||||
[]string{"OneDrive Personal or Business", "Root Sharepoint site", "Type in driveID", "Type in SiteID", "Search a Sharepoint site"},
|
[]string{
|
||||||
|
"OneDrive Personal or Business",
|
||||||
|
"Root Sharepoint site",
|
||||||
|
"Sharepoint site name or URL (e.g. mysite or https://contoso.sharepoint.com/sites/mysite)",
|
||||||
|
"Search for a Sharepoint site",
|
||||||
|
"Type in driveID (advanced)",
|
||||||
|
"Type in SiteID (advanced)",
|
||||||
|
"Sharepoint server-relative path (advanced, e.g. /teams/hr)",
|
||||||
|
},
|
||||||
false) {
|
false) {
|
||||||
|
|
||||||
case "onedrive":
|
case "onedrive":
|
||||||
@ -143,6 +153,20 @@ func init() {
|
|||||||
case "siteid":
|
case "siteid":
|
||||||
fmt.Printf("Paste your Site ID here> ")
|
fmt.Printf("Paste your Site ID here> ")
|
||||||
siteID = config.ReadLine()
|
siteID = config.ReadLine()
|
||||||
|
case "url":
|
||||||
|
fmt.Println("Example: \"https://contoso.sharepoint.com/sites/mysite\" or \"mysite\"")
|
||||||
|
fmt.Printf("Paste your Site URL here> ")
|
||||||
|
siteURL := config.ReadLine()
|
||||||
|
re := regexp.MustCompile(`https://.*\.sharepoint.com/sites/(.*)`)
|
||||||
|
match := re.FindStringSubmatch(siteURL)
|
||||||
|
if len(match) == 2 {
|
||||||
|
relativePath = "/sites/" + match[1]
|
||||||
|
} else {
|
||||||
|
relativePath = "/sites/" + siteURL
|
||||||
|
}
|
||||||
|
case "path":
|
||||||
|
fmt.Printf("Enter server-relative URL here> ")
|
||||||
|
relativePath = config.ReadLine()
|
||||||
case "search":
|
case "search":
|
||||||
fmt.Printf("What to search for> ")
|
fmt.Printf("What to search for> ")
|
||||||
searchTerm := config.ReadLine()
|
searchTerm := config.ReadLine()
|
||||||
@ -169,6 +193,21 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if we use server-relative URL for finding the drive
|
||||||
|
if relativePath != "" {
|
||||||
|
opts = rest.Opts{
|
||||||
|
Method: "GET",
|
||||||
|
RootURL: graphURL,
|
||||||
|
Path: "/sites/root:" + relativePath,
|
||||||
|
}
|
||||||
|
site := siteResource{}
|
||||||
|
_, err := srv.CallJSON(ctx, &opts, nil, &site)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to query available site by relative path: %v", err)
|
||||||
|
}
|
||||||
|
siteID = site.SiteID
|
||||||
|
}
|
||||||
|
|
||||||
// if we have a siteID we need to ask for the drives
|
// if we have a siteID we need to ask for the drives
|
||||||
if siteID != "" {
|
if siteID != "" {
|
||||||
opts = rest.Opts{
|
opts = rest.Opts{
|
||||||
|
Loading…
Reference in New Issue
Block a user