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);
}
// 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());
}

View file

@ -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);
}