create dir with parent id

This commit is contained in:
skilion 2017-12-31 13:18:11 +01:00
parent 95c952fe62
commit 6907daa5e8
2 changed files with 16 additions and 11 deletions

View file

@ -187,13 +187,11 @@ final class OneDriveApi
del(url); del(url);
} }
// https://dev.onedrive.com/items/create.htm // https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_post_children
JSONValue createByPath(const(char)[] parentPath, JSONValue item) JSONValue createById(const(char)[] parentDriveId, const(char)[] parentId, JSONValue item)
{ {
checkAccessTokenExpired(); checkAccessTokenExpired();
string url = itemByPathUrl ~ encodeComponent(parentPath) ~ ":/children"; const(char)[] url = driveByIdUrl ~ parentDriveId ~ "/items/" ~ parentId ~ "/children";
// HACK
if (parentPath == ".") url = driveUrl ~ "/root/children";
http.addRequestHeader("Content-Type", "application/json"); http.addRequestHeader("Content-Type", "application/json");
return post(url, item.toString()); return post(url, item.toString());
} }

View file

@ -1,6 +1,8 @@
import std.algorithm; import std.algorithm: find;
import std.array: array; 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.regex;
import std.stdio, std.string; import std.stdio, std.string;
import config, itemdb, onedrive, selective, upload, util; import config, itemdb, onedrive, selective, upload, util;
@ -427,6 +429,7 @@ final class SyncEngine
{ {
log.vlog("Uploading differences of ", path); log.vlog("Uploading differences of ", path);
Item item; Item item;
// TODO: SKIPS REMOTE FOLDER!
if (itemdb.selectByPath(path, item)) { if (itemdb.selectByPath(path, item)) {
uploadDifferences(item); uploadDifferences(item);
} }
@ -571,10 +574,14 @@ final class SyncEngine
private void uploadCreateDir(const(char)[] path) private void uploadCreateDir(const(char)[] path)
{ {
log.log("Creating remote directory: ", path); log.log("Uploading folder ", path);
JSONValue item = ["name": baseName(path).idup]; Item parent;
item["folder"] = parseJSON("{}"); enforce(itemdb.selectByPath(dirName(path), parent), "The parent item is not in the database");
auto res = onedrive.createByPath(path.dirName, item); JSONValue driveItem = [
"name": JSONValue(baseName(path)),
"folder": parseJSON("{}")
];
auto res = onedrive.createById(parent.driveId, parent.id, driveItem);
saveItem(res); saveItem(res);
} }