mirror of
https://github.com/abraunegg/onedrive
synced 2024-05-09 17:26:47 +02:00
create dir with parent id
This commit is contained in:
parent
95c952fe62
commit
6907daa5e8
|
@ -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());
|
||||
}
|
||||
|
|
19
src/sync.d
19
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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue