Switch to using list_children for an item id's children

* Change how onedrive get's the children from a particular item id.
Previously view.delta was used to return the children, however
view.delta is not implemented on children when using OneDrive Business
accounts. By using list_children, we can get the children from any id
correctly when using either a 'personal' or 'business' account
This commit is contained in:
abraunegg 2018-04-19 14:31:35 +10:00
parent 77c0cdbe24
commit fedaedacd7
2 changed files with 14 additions and 21 deletions

View file

@ -114,16 +114,15 @@ final class OneDriveApi
return get(url); return get(url);
} }
// https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_delta // https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/driveitem_list_children
JSONValue viewChangesByPath(const(char)[] path, const(char)[] deltaLink) JSONValue viewChildrenById(const(char)[] driveId, const(char)[] id)
{ {
// Get a list of children for a given item id
// Returns a value array where each array element has the following:
// id,name,eTag,cTag,file,folder,fileSystemInfo,remoteItem,parentReference
checkAccessTokenExpired(); checkAccessTokenExpired();
const(char)[] url = deltaLink; // GET /drives/{drive-id}/items/{item-id}/children
if (url == null) { const(char)[] url = driveByIdUrl ~ driveId ~ "/items/" ~ id ~ "/children";
if (path == ".") url = driveUrl ~ "/root/delta";
else url = itemByPathUrl ~ encodeComponent(path) ~ ":/delta";
url ~= "?select=id,name,eTag,cTag,deleted,file,folder,root,fileSystemInfo,remoteItem,parentReference";
}
return get(url); return get(url);
} }

View file

@ -181,13 +181,14 @@ final class SyncEngine
if (e.httpStatusCode == 404) { if (e.httpStatusCode == 404) {
// The directory was not found // The directory was not found
log.vlog("ERROR: The requested single directory to sync was not found on OneDrive"); log.vlog("ERROR: The requested single directory to sync was not found on OneDrive");
return; // We are expecting this directory however as this is a single directory sync
uploadCreateDir(path);
} }
} }
// OK - it should exist, get the driveId and rootId for this folder // OK - it should exist, get the driveId and rootId for this folder
log.vlog("Checking for differences from OneDrive ..."); log.vlog("Checking for differences from OneDrive ...");
// If the OneDrive Root is not in the local database, creating a remote folder will fail // If the OneDrive Root is not in the local database, creating a remote folder in the selected path will fail
checkDatabaseForOneDriveRoot(); checkDatabaseForOneDriveRoot();
// Configure driveID and folderId // Configure driveID and folderId
@ -288,17 +289,10 @@ final class SyncEngine
log.vlog("Applying changes of Path ID: " ~ id); log.vlog("Applying changes of Path ID: " ~ id);
for (;;) { for (;;) {
try { // Will provide a JSON of children of the item id
changes = onedrive.viewChangesById(driveId, id, deltaLink); changes = onedrive.viewChildrenById(driveId, id);
} catch (OneDriveException e) {
if (e.httpStatusCode == 410) { // For each 'value' item (child resource ..
log.vlog("Delta link expired, resyncing...");
deltaLink = null;
continue;
} else {
throw e;
}
}
foreach (item; changes["value"].array) { foreach (item; changes["value"].array) {
bool isRoot = (id == defaultRootId); // fix for https://github.com/skilion/onedrive/issues/269 bool isRoot = (id == defaultRootId); // fix for https://github.com/skilion/onedrive/issues/269
// Apply the change // Apply the change