diff --git a/src/onedrive.d b/src/onedrive.d index 693d1d19..dcba74bf 100644 --- a/src/onedrive.d +++ b/src/onedrive.d @@ -187,13 +187,11 @@ final class OneDriveApi del(url); } - // https://dev.onedrive.com/items/create.htm - JSONValue createByPath(const(char)[] parentPath, JSONValue item) + // https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_post_children + JSONValue createById(const(char)[] parentDriveId, const(char)[] parentId, JSONValue item) { checkAccessTokenExpired(); - string url = itemByPathUrl ~ encodeComponent(parentPath) ~ ":/children"; - // HACK - if (parentPath == ".") url = driveUrl ~ "/root/children"; + const(char)[] url = driveByIdUrl ~ parentDriveId ~ "/items/" ~ parentId ~ "/children"; http.addRequestHeader("Content-Type", "application/json"); return post(url, item.toString()); } diff --git a/src/sync.d b/src/sync.d index 3f073fe0..91c0ca18 100644 --- a/src/sync.d +++ b/src/sync.d @@ -1,6 +1,8 @@ -import std.algorithm; +import std.algorithm: find; import std.array: array; -import std.datetime, std.file, std.json, std.path; +import std.datetime; +import std.exception: enforce; +import std.file, std.json, std.path; import std.regex; import std.stdio, std.string; import config, itemdb, onedrive, selective, upload, util; @@ -427,6 +429,7 @@ final class SyncEngine { log.vlog("Uploading differences of ", path); Item item; + // TODO: SKIPS REMOTE FOLDER! if (itemdb.selectByPath(path, item)) { uploadDifferences(item); } @@ -571,10 +574,14 @@ final class SyncEngine private void uploadCreateDir(const(char)[] path) { - log.log("Creating remote directory: ", path); - JSONValue item = ["name": baseName(path).idup]; - item["folder"] = parseJSON("{}"); - auto res = onedrive.createByPath(path.dirName, item); + log.log("Uploading folder ", path); + Item parent; + enforce(itemdb.selectByPath(dirName(path), parent), "The parent item is not in the database"); + JSONValue driveItem = [ + "name": JSONValue(baseName(path)), + "folder": parseJSON("{}") + ]; + auto res = onedrive.createById(parent.driveId, parent.id, driveItem); saveItem(res); }