mirror of
https://github.com/abraunegg/onedrive
synced 2026-03-14 14:35:46 +01:00
Add 2 functions to check remoteItem JSON data is present (#3270)
* Add 2 functions to check for the presence of required remoteItem elements to create a Shared Folder DB entries * Use 2 new functions to ensure data is available to create the required Shared Folder entries
This commit is contained in:
parent
5b281e0c96
commit
61ee4ec15b
2 changed files with 44 additions and 11 deletions
42
src/sync.d
42
src/sync.d
|
|
@ -3051,22 +3051,42 @@ class SyncEngine {
|
|||
// Using the onlineParentData JSON data make a DB record for this parent item so that it exists in the database
|
||||
Item sharedFolderDatabaseTie;
|
||||
|
||||
// What account type is this? This needs to be configured correctly so this can be queried correctly
|
||||
if (appConfig.accountType == "personal") {
|
||||
// OneDrive Personal JSON has this structure that we need to use
|
||||
parentDriveId = onedriveJSONItem["remoteItem"]["parentReference"]["driveId"].str;
|
||||
parentObjectId = onedriveJSONItem["remoteItem"]["id"].str;
|
||||
} else {
|
||||
// OneDrive Business|Sharepoint JSON has this structure that we need to use
|
||||
parentDriveId = onedriveJSONItem["remoteItem"]["parentReference"]["driveId"].str;
|
||||
parentObjectId = onedriveJSONItem["remoteItem"]["id"].str;
|
||||
// A Shared Folder should have ["remoteItem"]["parentReference"] elements
|
||||
bool remoteItemElementsExist = false;
|
||||
|
||||
// Test that the required elements exist for Shared Folder DB entry creations to occur
|
||||
if (isItemRemote(onedriveJSONItem)) {
|
||||
// Required ["remoteItem"] element exists in the JSON data
|
||||
if ((hasRemoteParentDriveId(onedriveJSONItem)) && (hasRemoteItemId(onedriveJSONItem))) {
|
||||
// Required elements exist
|
||||
remoteItemElementsExist = true;
|
||||
// What account type is this? This needs to be configured correctly so this can be queried correctly
|
||||
// - The setting of this is the 'same' for account types, but previously this was shown to need different data. Future code optimisation potentially here.
|
||||
if (appConfig.accountType == "personal") {
|
||||
// OneDrive Personal JSON has this structure that we need to use
|
||||
parentDriveId = onedriveJSONItem["remoteItem"]["parentReference"]["driveId"].str;
|
||||
parentObjectId = onedriveJSONItem["remoteItem"]["id"].str;
|
||||
} else {
|
||||
// OneDrive Business|Sharepoint JSON has this structure that we need to use
|
||||
parentDriveId = onedriveJSONItem["remoteItem"]["parentReference"]["driveId"].str;
|
||||
parentObjectId = onedriveJSONItem["remoteItem"]["id"].str;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Issue #3115 - Validate driveId length
|
||||
// If the required elements do not exist, the Shared Folder DB elements cannot be created
|
||||
if (!remoteItemElementsExist) {
|
||||
// We cannot create the required entries in the database
|
||||
if (debugLogging) {addLogEntry("Unable to create 'root' and 'Shared Folder' DB Tie Records in a consistent manner - required elements missing from provided JSON record" , ["debug"]);}
|
||||
return;
|
||||
}
|
||||
|
||||
// Issue #3115 - Validate 'parentDriveId' length
|
||||
// What account type is this?
|
||||
if (appConfig.accountType == "personal") {
|
||||
// Test driveId length and validation if the driveId we are testing is not equal to appConfig.defaultDriveId
|
||||
// Test if the 'parentDriveId' is not equal to appConfig.defaultDriveId
|
||||
if (parentDriveId != appConfig.defaultDriveId) {
|
||||
// Test 'parentDriveId' for length and validation - 15 character API bug
|
||||
parentDriveId = testProvidedDriveIdForLengthIssue(parentDriveId);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
13
src/util.d
13
src/util.d
|
|
@ -1128,6 +1128,19 @@ bool isItemRemote(const ref JSONValue item) {
|
|||
return ("remoteItem" in item) != null;
|
||||
}
|
||||
|
||||
// Check if ["remoteItem"]["parentReference"]["driveId"] exists
|
||||
bool hasRemoteParentDriveId(const ref JSONValue item) {
|
||||
return ("remoteItem" in item) &&
|
||||
("parentReference" in item["remoteItem"]) &&
|
||||
("driveId" in item["remoteItem"]["parentReference"]);
|
||||
}
|
||||
|
||||
// Check if ["remoteItem"]["id"] exists
|
||||
bool hasRemoteItemId(const ref JSONValue item) {
|
||||
return ("remoteItem" in item) &&
|
||||
("id" in item["remoteItem"]);
|
||||
}
|
||||
|
||||
bool isItemFile(const ref JSONValue item) {
|
||||
return ("file" in item) != null;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue