From 7532c9d8ccae7beb0193f82130ea1c5e7bb754d6 Mon Sep 17 00:00:00 2001 From: abraunegg Date: Sat, 19 Jan 2019 13:01:41 +1100 Subject: [PATCH] Update handling of --get-O365-drive-id for multi matching (#354) * Update handling of --get-O365-drive-id to print out all 'site names' that match the explicit search entry rather than just the last match * Add webUrl for site to output so that the 'right' site drive_id can be identified * Update O365 readme with updated output --- README.Office365.md | 6 ++++-- src/sync.d | 16 +++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/README.Office365.md b/README.Office365.md index 03fba139..cfed3db4 100644 --- a/README.Office365.md +++ b/README.Office365.md @@ -8,8 +8,10 @@ onedrive --get-O365-drive-id '' 3. This will return the following: ```bash Initializing the Synchronization Engine ... -Office 365 Library Name: ab-github-odtest -drive_id: b!6H.....l7vVxU5 +Office 365 Library Name Query: +SiteName: +drive_id: b!6H_y8B...xU5 +URL: ``` ## Configuring the onedrive client diff --git a/src/sync.d b/src/sync.d index 8d97abde..e478959f 100644 --- a/src/sync.d +++ b/src/sync.d @@ -1924,24 +1924,30 @@ final class SyncEngine string site_id; string drive_id; + string webUrl; + bool found = false; JSONValue siteQuery = onedrive.o365SiteSearch(encodeComponent(o365SharedLibraryName)); + log.log("Office 365 Library Name Query: ", o365SharedLibraryName); + foreach (searchResult; siteQuery["value"].array) { // Need an 'exclusive' match here with o365SharedLibraryName as entered if (o365SharedLibraryName == searchResult["displayName"].str){ // 'displayName' matches search request site_id = searchResult["id"].str; + webUrl = searchResult["webUrl"].str; JSONValue siteDriveQuery = onedrive.o365SiteDrives(site_id); foreach (driveResult; siteDriveQuery["value"].array) { - drive_id = driveResult["id"].str; + // Display results + found = true; + writeln("SiteName: ", searchResult["displayName"].str); + writeln("drive_id: ", driveResult["id"].str); + writeln("URL: ", webUrl); } } } - log.log("Office 365 Library Name: ", o365SharedLibraryName); - if(drive_id != null) { - log.log("drive_id: ", drive_id); - } else { + if(!found) { writeln("ERROR: This site could not be found. Please check it's name and your permissions to access the site."); } }