diff --git a/src/onedrive.d b/src/onedrive.d index 976d6951..1c731977 100644 --- a/src/onedrive.d +++ b/src/onedrive.d @@ -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); } diff --git a/src/sync.d b/src/sync.d index e47d9633..76be306d 100644 --- a/src/sync.d +++ b/src/sync.d @@ -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