mirror of
https://github.com/abraunegg/onedrive
synced 2024-05-22 07:36:36 +02:00
wip for OneDrive Biz
This commit is contained in:
parent
1c7b726994
commit
0d69ed805d
|
@ -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,
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
19
src/sync.d
19
src/sync.d
|
@ -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");
|
||||||
|
|
Loading…
Reference in a new issue