wip for OneDrive Biz

This commit is contained in:
skilion 2017-03-12 19:40:38 +01:00
parent 1c7b726994
commit 0d69ed805d
3 changed files with 17 additions and 12 deletions

View file

@ -22,7 +22,7 @@ struct Item
final class ItemDatabase final class ItemDatabase
{ {
// increment this for every change in the db schema // increment this for every change in the db schema
immutable int itemDatabaseVersion = 2; immutable int itemDatabaseVersion = 3;
Database db; Database db;
Statement insertItemStmt; Statement insertItemStmt;
@ -38,7 +38,7 @@ final class ItemDatabase
id TEXT NOT NULL PRIMARY KEY, id TEXT NOT NULL PRIMARY KEY,
name TEXT NOT NULL, name TEXT NOT NULL,
type TEXT NOT NULL, type TEXT NOT NULL,
eTag TEXT NOT NULL, eTag TEXT,
cTag TEXT, cTag TEXT,
mtime TEXT NOT NULL, mtime TEXT NOT NULL,
parentId TEXT, parentId TEXT,

View file

@ -83,7 +83,7 @@ final class OneDriveApi
write(url, "\n\n", "Enter the response uri: "); write(url, "\n\n", "Enter the response uri: ");
readln(response); readln(response);
// match the authorization code // match the authorization code
auto c = matchFirst(response, r"(?:code=)(([\w\d]+-){4}[\w\d]+)"); auto c = matchFirst(response, r"(?:code=)([\w\d-]+)");
if (c.empty) { if (c.empty) {
log.log("Invalid uri"); log.log("Invalid uri");
return false; return false;
@ -105,7 +105,7 @@ final class OneDriveApi
{ {
checkAccessTokenExpired(); checkAccessTokenExpired();
const(char)[] url = itemByIdUrl ~ id ~ "/delta"; const(char)[] url = itemByIdUrl ~ id ~ "/delta";
url ~= "?select=id,name,eTag,cTag,deleted,file,folder,fileSystemInfo,remoteItem,parentReference"; url ~= "?select=id,name,eTag,cTag,deleted,file,folder,root,fileSystemInfo,remoteItem,parentReference";
if (statusToken) url ~= "&token=" ~ statusToken; if (statusToken) url ~= "&token=" ~ statusToken;
return get(url); return get(url);
} }
@ -117,7 +117,7 @@ final class OneDriveApi
string url = itemByPathUrl ~ encodeComponent(path) ~ ":/delta"; string url = itemByPathUrl ~ encodeComponent(path) ~ ":/delta";
// HACK // HACK
if (path == ".") url = driveUrl ~ "/root/delta"; if (path == ".") url = driveUrl ~ "/root/delta";
url ~= "?select=id,name,eTag,cTag,deleted,file,folder,fileSystemInfo,remoteItem,parentReference"; url ~= "?select=id,name,eTag,cTag,deleted,file,folder,root,fileSystemInfo,remoteItem,parentReference";
if (statusToken) url ~= "&token=" ~ statusToken; if (statusToken) url ~= "&token=" ~ statusToken;
return get(url); return get(url);
} }

View file

@ -24,6 +24,11 @@ private bool isItemDeleted(const ref JSONValue item)
return ("deleted" in item) || ("fileSystemInfo" !in item); return ("deleted" in item) || ("fileSystemInfo" !in item);
} }
private bool isItemRoot(const ref JSONValue item)
{
return ("root" in item) != null;
}
private bool testCrc32(string path, const(char)[] crc32) private bool testCrc32(string path, const(char)[] crc32)
{ {
if (crc32) { if (crc32) {
@ -150,16 +155,16 @@ final class SyncEngine
{ {
string id = item["id"].str; string id = item["id"].str;
string name = item["name"].str; string name = item["name"].str;
string eTag = item["eTag"].str;
string parentId = item["parentReference"]["id"].str;
// HACK: recognize the root directory
if (name == "root" && parentId[$ - 1] == '0' && parentId[$ - 2] == '!') {
parentId = null;
}
log.vlog(id, " ", name); log.vlog(id, " ", name);
// eTag and parentId do not exists for the root in OneDrive Biz
string eTag, parentId;
if (!isItemRoot(item)) {
eTag = item["eTag"].str;
parentId = item["parentReference"]["id"].str;
}
// skip unwanted items early // skip unwanted items early
if (skippedItems.find(parentId).length != 0) { if (skippedItems.find(parentId).length != 0) {
log.vlog("Filtered out"); log.vlog("Filtered out");