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);
}
// https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_delta
JSONValue viewChangesByPath(const(char)[] path, const(char)[] deltaLink)
// https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/driveitem_list_children
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();
const(char)[] url = deltaLink;
if (url == null) {
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";
}
// GET /drives/{drive-id}/items/{item-id}/children
const(char)[] url = driveByIdUrl ~ driveId ~ "/items/" ~ id ~ "/children";
return get(url);
}

View file

@ -181,13 +181,14 @@ final class SyncEngine
if (e.httpStatusCode == 404) {
// The directory was not found
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
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();
// Configure driveID and folderId
@ -288,17 +289,10 @@ final class SyncEngine
log.vlog("Applying changes of Path ID: " ~ id);
for (;;) {
try {
changes = onedrive.viewChangesById(driveId, id, deltaLink);
} catch (OneDriveException e) {
if (e.httpStatusCode == 410) {
log.vlog("Delta link expired, resyncing...");
deltaLink = null;
continue;
} else {
throw e;
}
}
// Will provide a JSON of children of the item id
changes = onedrive.viewChildrenById(driveId, id);
// For each 'value' item (child resource ..
foreach (item; changes["value"].array) {
bool isRoot = (id == defaultRootId); // fix for https://github.com/skilion/onedrive/issues/269
// Apply the change