Skip to content

Commit

Permalink
Merge branch 'master' into fix-issue-3012
Browse files Browse the repository at this point in the history
  • Loading branch information
abraunegg authored Dec 10, 2024
2 parents d2196f7 + 6634284 commit dde5766
Show file tree
Hide file tree
Showing 4 changed files with 201 additions and 49 deletions.
22 changes: 21 additions & 1 deletion docs/application-config-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Before reading this document, please ensure you are running application version
- [classify_as_big_delete](#classify_as_big_delete)
- [cleanup_local_files](#cleanup_local_files)
- [connect_timeout](#connect_timeout)
- [create_new_file_version](#create_new_file_version)
- [data_timeout](#data_timeout)
- [debug_https](#debug_https)
- [disable_download_validation](#disable_download_validation)
Expand Down Expand Up @@ -204,6 +205,23 @@ _**Default Value:**_ 10

_**Config Example:**_ `connect_timeout = "15"`

### create_new_file_version
_**Description:**_ This setting controls how the application handles the Microsoft SharePoint *feature* which modifies all PDF, MS Office & HTML files post upload, effectively breaking the integrity of your data online. By default, when the application determines that this *feature* has modified your file post upload, the now online modified file will be downloaded. When this option is enabled, rather than downloading the file, a new online file version is created which negates the download of the modified file.

_**Value Type:**_ Boolean

_**Default Value:**_ False

_**Config Example:**_ `create_new_file_version = "false"` or `create_new_file_version = "true"`

_**CLI Option Use:**_ *None - this is a config file option only*

> [!IMPORTANT]
> If you enable 'disable_upload_validation' via `disable_upload_validation = "true"` there is zero facility to determine if a file was modified post upload. As such, the application will default to the state that the upload integrity check has failed. When `create_new_file_version = "false"` your uploaded file will be downloaded *regardless* of the online modification state.
> [!WARNING]
> When this option is set to 'true', new file versions will be created online which will count towards your Microsoft OneDrive Quota.
### data_timeout
_**Description:**_ This setting controls the timeout duration, in seconds, for when data is not received on an active connection to Microsoft OneDrive over HTTPS when using the curl library, before that connection is timeout out.

Expand Down Expand Up @@ -515,6 +533,8 @@ _**Default Value:**_ False

_**Config Example:**_ `permanent_delete = "true"`

_**CLI Option Use:**_ *None - this is a config file option only*

> [!IMPORTANT]
> The Microsoft OneDrive API for this capability is also very narrow:
> | Account Type | Config Option is Supported |
Expand Down Expand Up @@ -772,7 +792,7 @@ _**Default Value:**_ False

_**Config Example:**_ `sync_business_shared_items = "false"` or `sync_business_shared_items = "true"`

_**CLI Option Use:**_ *none* - this is a config file option only
_**CLI Option Use:**_ *None - this is a config file option only*

> [!NOTE]
> This option is considered a 'Client Side Filtering Rule' and if configured, is utilised for all sync operations. After changing this option, you will be required to perform a resync.
Expand Down
5 changes: 5 additions & 0 deletions src/config.d
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,11 @@ class ApplicationConfig {
boolValues["cleanup_local_files"] = false;
// - Perform a permanentDelete on deletion activities
boolValues["permanent_delete"] = false;
// - Controls how the application handles the Microsoft SharePoint 'feature' of modifying all PDF, MS Office & HTML files with added XML content post upload
// There are 2 ways to solve this:
// 1. Download the modified file immediately after upload as per v2.4.x (default)
// 2. Create a new online version of the file, which then contributes to the users 'quota'
boolValues["create_new_file_version"] = false;

// Webhook Feature Options
boolValues["webhook_enabled"] = false;
Expand Down
13 changes: 7 additions & 6 deletions src/onedrive.d
Original file line number Diff line number Diff line change
Expand Up @@ -663,14 +663,15 @@ class OneDriveApi {
// https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_createuploadsession
//JSONValue createUploadSession(string parentDriveId, string parentId, string filename, string eTag = null, JSONValue item = null) {
JSONValue createUploadSession(string parentDriveId, string parentId, string filename, const(char)[] eTag = null, JSONValue item = null) {
// string[string] requestHeaders;
string[string] requestHeaders;
string url = driveByIdUrl ~ parentDriveId ~ "/items/" ~ parentId ~ ":/" ~ encodeComponent(filename) ~ ":/createUploadSession";
// eTag If-Match header addition commented out for the moment
// At some point, post the creation of this upload session the eTag is being 'updated' by OneDrive, thus when uploadFragment() is used
// this generates a 412 Precondition Failed and then a 416 Requested Range Not Satisfiable
// This needs to be investigated further as to why this occurs
// if (eTag) requestHeaders["If-Match"] = eTag;
return post(url, item.toString());

if (eTag) requestHeaders["If-Match"] = to!string(eTag);
return post(url, item.toString(), requestHeaders);
}

// https://dev.onedrive.com/items/upload_large_files.htm
Expand Down Expand Up @@ -823,7 +824,7 @@ class OneDriveApi {
JSONValue response;

try {
response = post(tokenUrl, postData, true, "application/x-www-form-urlencoded");
response = post(tokenUrl, postData, null, true, "application/x-www-form-urlencoded");
} catch (OneDriveException exception) {
// an error was generated
if ((exception.httpStatusCode == 400) || (exception.httpStatusCode == 401)) {
Expand Down Expand Up @@ -1141,10 +1142,10 @@ class OneDriveApi {
}, validateJSONResponse, callingFunction, lineno);
}

private JSONValue post(const(char)[] url, const(char)[] postData, bool skipToken = false, const(char)[] contentType = "application/json", string callingFunction=__FUNCTION__, int lineno=__LINE__) {
private JSONValue post(const(char)[] url, const(char)[] postData, string[string] requestHeaders=null, bool skipToken = false, const(char)[] contentType = "application/json", string callingFunction=__FUNCTION__, int lineno=__LINE__) {
bool validateJSONResponse = true;
return oneDriveErrorHandlerWrapper((CurlResponse response) {
connect(HTTP.Method.post, url, skipToken, response);
connect(HTTP.Method.post, url, skipToken, response, requestHeaders);
curlEngine.setContent(contentType, postData);
return curlEngine.execute();
}, validateJSONResponse, callingFunction, lineno);
Expand Down
Loading

0 comments on commit dde5766

Please sign in to comment.