mirror of
https://github.com/abraunegg/onedrive
synced 2024-05-13 03:06:40 +02:00
Use 'nextLink' value if present when searching for specific SharePoint site names (#1329)
* Use 'nextLink' value if present when searching for specific SharePoint site names * Update error output to provide more details why an error occurred if a SharePoint site lacks the details we need to perform the match
This commit is contained in:
parent
cefb3169fa
commit
b8717fbc53
|
@ -33,7 +33,7 @@ This client is a 'fork' of the [skilion](https://github.com/skilion/onedrive) cl
|
|||
## Frequently Asked Questions
|
||||
Refer to [Frequently Asked Questions](https://github.com/abraunegg/onedrive/wiki/Frequently-Asked-Questions)
|
||||
|
||||
## Have a question?
|
||||
## Have a question
|
||||
If you have a question or need something clarified, please raise a new disscussion post [here](https://github.com/abraunegg/onedrive/discussions)
|
||||
|
||||
## Reporting an Issue or Bug
|
||||
|
|
|
@ -780,10 +780,15 @@ final class OneDriveApi
|
|||
}
|
||||
|
||||
// https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/site_search?view=odsp-graph-online
|
||||
JSONValue o365SiteSearch(){
|
||||
JSONValue o365SiteSearch(const(char)[] nextLink){
|
||||
checkAccessTokenExpired();
|
||||
const(char)[] url;
|
||||
// configure URL to query
|
||||
if (nextLink.empty) {
|
||||
url = siteSearchUrl ~ "=*";
|
||||
} else {
|
||||
url = nextLink;
|
||||
}
|
||||
return get(url);
|
||||
}
|
||||
|
||||
|
|
87
src/sync.d
87
src/sync.d
|
@ -5393,17 +5393,49 @@ final class SyncEngine
|
|||
string webUrl;
|
||||
bool found = false;
|
||||
JSONValue siteQuery;
|
||||
string nextLink;
|
||||
string[] siteSearchResults;
|
||||
|
||||
log.log("Office 365 Library Name Query: ", o365SharedLibraryName);
|
||||
|
||||
for (;;) {
|
||||
try {
|
||||
siteQuery = onedrive.o365SiteSearch();
|
||||
siteQuery = onedrive.o365SiteSearch(nextLink);
|
||||
} catch (OneDriveException e) {
|
||||
log.error("ERROR: Query of OneDrive for Office 365 Library Name failed");
|
||||
if (e.httpStatusCode == 403) {
|
||||
// Forbidden - most likely authentication scope needs to be updated
|
||||
log.error("ERROR: Authentication scope needs to be updated. Use --logout and re-authenticate client.");
|
||||
return;
|
||||
}
|
||||
// HTTP request returned status code 429 (Too Many Requests)
|
||||
if (e.httpStatusCode == 429) {
|
||||
// HTTP request returned status code 429 (Too Many Requests). We need to leverage the response Retry-After HTTP header to ensure minimum delay until the throttle is removed.
|
||||
handleOneDriveThrottleRequest();
|
||||
log.vdebug("Retrying original request that generated the OneDrive HTTP 429 Response Code (Too Many Requests) - attempting to query OneDrive drive children");
|
||||
}
|
||||
// HTTP request returned status code 504 (Gateway Timeout) or 429 retry
|
||||
if ((e.httpStatusCode == 429) || (e.httpStatusCode == 504)) {
|
||||
// re-try the specific changes queries
|
||||
if (e.httpStatusCode == 504) {
|
||||
log.log("OneDrive returned a 'HTTP 504 - Gateway Timeout' when attempting to query Sharepoint Sites - retrying applicable request");
|
||||
log.vdebug("siteQuery = onedrive.o365SiteSearch(nextLink) previously threw an error - retrying");
|
||||
// The server, while acting as a proxy, did not receive a timely response from the upstream server it needed to access in attempting to complete the request.
|
||||
log.vdebug("Thread sleeping for 30 seconds as the server did not receive a timely response from the upstream server it needed to access in attempting to complete the request");
|
||||
Thread.sleep(dur!"seconds"(30));
|
||||
}
|
||||
// re-try original request - retried for 429 and 504
|
||||
try {
|
||||
log.vdebug("Retrying Query: siteQuery = onedrive.o365SiteSearch(nextLink)");
|
||||
siteQuery = onedrive.o365SiteSearch(nextLink);
|
||||
log.vdebug("Query 'siteQuery = onedrive.o365SiteSearch(nextLink)' performed successfully on re-try");
|
||||
} catch (OneDriveException e) {
|
||||
// display what the error is
|
||||
log.vdebug("Query Error: siteQuery = onedrive.o365SiteSearch(nextLink) on re-try after delay");
|
||||
// error was not a 504 this time
|
||||
displayOneDriveErrorMessage(e.msg, getFunctionName!({}));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
// display what the error is
|
||||
displayOneDriveErrorMessage(e.msg, getFunctionName!({}));
|
||||
|
@ -5455,21 +5487,34 @@ final class SyncEngine
|
|||
}
|
||||
}
|
||||
} else {
|
||||
// 'displayName' not present in JSON results
|
||||
log.error("ERROR: The results returned from OneDrive API do not contain the required items to match. Please check your permissions with your site administrator.");
|
||||
// 'displayName', 'id' or ''webUrl' not present in JSON results for a specific site
|
||||
string siteNameAvailable = "Site 'name' was restricted by OneDrive API permissions";
|
||||
bool displayNameAvailable = false;
|
||||
bool idAvailable = false;
|
||||
bool webUrlAvailable = false;
|
||||
if ("name" in searchResult) siteNameAvailable = searchResult["name"].str;
|
||||
if ("displayName" in searchResult) displayNameAvailable = true;
|
||||
if ("id" in searchResult) idAvailable = true;
|
||||
if ("webUrl" in searchResult) webUrlAvailable = true;
|
||||
|
||||
// Display error details for this site data
|
||||
log.error("\nERROR: SharePoint Site details not provided for: ", siteNameAvailable);
|
||||
log.error("ERROR: The SharePoint Site results returned from OneDrive API do not contain the required items to match. Please check your permissions with your site administrator.");
|
||||
log.error("ERROR: Your site security settings is preventing the following details from being accessed: 'displayName', 'id' and 'webUrl'");
|
||||
log.error("ERROR: To debug this further, please use --verbose --verbose to provide insight as to what details are actually returned.");
|
||||
return;
|
||||
log.vlog(" - Is 'displayName' available = ", displayNameAvailable);
|
||||
log.vlog(" - Is 'id' available = ", idAvailable);
|
||||
log.vlog(" - Is 'webUrl' available = ", webUrlAvailable);
|
||||
log.error("ERROR: To debug this further, please increase verbosity (--verbose or --verbose --verbose) to provide further insight as to what details are actually being returned.");
|
||||
}
|
||||
}
|
||||
|
||||
if(!found) {
|
||||
log.error("ERROR: The requested SharePoint site could not be found. Please check it's name and your permissions to access the site.");
|
||||
// List all sites returned to assist user
|
||||
log.log("\nThe following SharePoint site names were returned:");
|
||||
// The SharePoint site we are searching for was not found in this bundle set
|
||||
// Add to siteSearchResults so we can display what we did find
|
||||
string siteSearchResultsEntry;
|
||||
foreach (searchResult; siteQuery["value"].array) {
|
||||
// list the display name that we use to match against the user query
|
||||
log.log(" * ", searchResult["displayName"].str);
|
||||
siteSearchResultsEntry = " * " ~ searchResult["displayName"].str;
|
||||
siteSearchResults ~= siteSearchResultsEntry;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -5478,6 +5523,26 @@ final class SyncEngine
|
|||
log.error("ERROR: Increase logging verbosity to assist determining why.");
|
||||
return;
|
||||
}
|
||||
|
||||
// If a collection exceeds the default page size (200 items), the @odata.nextLink property is returned in the response
|
||||
// to indicate more items are available and provide the request URL for the next page of items.
|
||||
if ("@odata.nextLink" in siteQuery) {
|
||||
// Update nextLink to next set of SharePoint library names
|
||||
nextLink = siteQuery["@odata.nextLink"].str;
|
||||
log.vdebug("Setting nextLink to (@odata.nextLink): ", nextLink);
|
||||
} else break;
|
||||
}
|
||||
|
||||
// Was the intended target found?
|
||||
if(!found) {
|
||||
log.error("\nERROR: The requested SharePoint site could not be found. Please check it's name and your permissions to access the site.");
|
||||
// List all sites returned to assist user
|
||||
log.log("\nThe following SharePoint site names were returned:");
|
||||
foreach (searchResultEntry; siteSearchResults) {
|
||||
// list the display name that we use to match against the user query
|
||||
log.log(searchResultEntry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create an anonymous read-only shareable link for an existing file on OneDrive
|
||||
|
@ -6181,8 +6246,8 @@ final class SyncEngine
|
|||
// to indicate more items are available and provide the request URL for the next page of items.
|
||||
if ("@odata.nextLink" in thisLevelChildren) {
|
||||
// Update nextLink to next changeSet bundle
|
||||
log.vdebug("Setting nextLink to (@odata.nextLink): ", nextLink);
|
||||
nextLink = thisLevelChildren["@odata.nextLink"].str;
|
||||
log.vdebug("Setting nextLink to (@odata.nextLink): ", nextLink);
|
||||
} else break;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue