mirror of
https://github.com/abraunegg/onedrive
synced 2024-05-05 07:23:21 +02:00
fixed acces to json nested objects
This commit is contained in:
parent
21666230aa
commit
f7e4b2f1e3
|
@ -72,7 +72,7 @@ final class OneDriveApi
|
||||||
JSONValue response = get(itemByIdUrl ~ id ~ "/?select=name,parentReference");
|
JSONValue response = get(itemByIdUrl ~ id ~ "/?select=name,parentReference");
|
||||||
string path;
|
string path;
|
||||||
try {
|
try {
|
||||||
path = response["parentReference"].object["path"].str;
|
path = response["parentReference"]["path"].str;
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
// root does not have parentReference
|
// root does not have parentReference
|
||||||
return "";
|
return "";
|
||||||
|
|
17
src/sync.d
17
src/sync.d
|
@ -1,4 +1,3 @@
|
||||||
import core.exception: RangeError;
|
|
||||||
import std.exception: ErrnoException;
|
import std.exception: ErrnoException;
|
||||||
import std.algorithm, std.datetime, std.file, std.json, std.path, std.regex;
|
import std.algorithm, std.datetime, std.file, std.json, std.path, std.regex;
|
||||||
import std.stdio, std.string;
|
import std.stdio, std.string;
|
||||||
|
@ -109,7 +108,7 @@ final class SyncEngine
|
||||||
{
|
{
|
||||||
string id = item["id"].str;
|
string id = item["id"].str;
|
||||||
string name = item["name"].str;
|
string name = item["name"].str;
|
||||||
string parentId = item["parentReference"].object["id"].str;
|
string parentId = item["parentReference"]["id"].str;
|
||||||
|
|
||||||
// HACK: recognize the root directory
|
// HACK: recognize the root directory
|
||||||
if (name == "root" && parentId[$ - 1] == '0' && parentId[$ - 2] == '!') {
|
if (name == "root" && parentId[$ - 1] == '0' && parentId[$ - 2] == '!') {
|
||||||
|
@ -174,16 +173,14 @@ final class SyncEngine
|
||||||
|
|
||||||
string eTag = item["eTag"].str;
|
string eTag = item["eTag"].str;
|
||||||
string cTag = item["cTag"].str;
|
string cTag = item["cTag"].str;
|
||||||
string mtime = item["fileSystemInfo"].object["lastModifiedDateTime"].str;
|
string mtime = item["fileSystemInfo"]["lastModifiedDateTime"].str;
|
||||||
|
|
||||||
string crc32;
|
string crc32;
|
||||||
if (type == ItemType.file) {
|
if (type == ItemType.file) {
|
||||||
try {
|
try {
|
||||||
crc32 = item["file"].object["hashes"].object["crc32Hash"].str;
|
crc32 = item["file"]["hashes"]["crc32Hash"].str;
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
if (verbose) writeln("The hash is not available");
|
if (verbose) writeln("The hash is not available");
|
||||||
} catch (RangeError e) {
|
|
||||||
if (verbose) writeln("The crc32 hash is not available");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -499,16 +496,14 @@ final class SyncEngine
|
||||||
string name = item["name"].str;
|
string name = item["name"].str;
|
||||||
string eTag = item["eTag"].str;
|
string eTag = item["eTag"].str;
|
||||||
string cTag = item["cTag"].str;
|
string cTag = item["cTag"].str;
|
||||||
string mtime = item["fileSystemInfo"].object["lastModifiedDateTime"].str;
|
string mtime = item["fileSystemInfo"]["lastModifiedDateTime"].str;
|
||||||
string parentId = item["parentReference"].object["id"].str;
|
string parentId = item["parentReference"]["id"].str;
|
||||||
string crc32;
|
string crc32;
|
||||||
if (type == ItemType.file) {
|
if (type == ItemType.file) {
|
||||||
try {
|
try {
|
||||||
crc32 = item["file"].object["hashes"].object["crc32Hash"].str;
|
crc32 = item["file"]["hashes"]["crc32Hash"].str;
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
// swallow exception
|
// swallow exception
|
||||||
} catch (RangeError e) {
|
|
||||||
// swallow exception
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
itemdb.upsert(id, name, type, eTag, cTag, mtime, parentId, crc32);
|
itemdb.upsert(id, name, type, eTag, cTag, mtime, parentId, crc32);
|
||||||
|
|
Loading…
Reference in a new issue