From 52dc120a2f181e98864bf604f5fc00e202699fbf Mon Sep 17 00:00:00 2001 From: abraunegg Date: Wed, 7 May 2025 19:36:55 +1000 Subject: [PATCH] Fix getRemainingFreeSpaceOnline() (#3264) * In some API JSON responses, the API data detailing remaining free space online is returned in an inconsistent manner. Update getRemainingFreeSpaceOnline() function to handle this so that the client has a reliable 'quotaAvailable' status to use when uploading new files --- src/sync.d | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/sync.d b/src/sync.d index ae3e2e09..f4f94d03 100644 --- a/src/sync.d +++ b/src/sync.d @@ -6784,11 +6784,27 @@ class SyncEngine { if ("remaining" in quota) { // Issue #2806 // If this is a negative value, quota["remaining"].integer can potentially convert to a huge positive number. Convert a different way. - string tempQuotaRemainingOnlineString = to!string(quota["remaining"]); - long tempQuotaRemainingOnlineValue = to!long(tempQuotaRemainingOnlineString); - - // Update quotaRemainingOnline to use the converted value - quotaRemainingOnline = tempQuotaRemainingOnlineValue; + string tempQuotaRemainingOnlineString; + // is quota["remaining"] an integer type? + if (quota["remaining"].type() == JSONType.integer) { + // extract as integer and convert to string + tempQuotaRemainingOnlineString = to!string(quota["remaining"].integer); + } + + // is quota["remaining"] an string type? + if (quota["remaining"].type() == JSONType.string) { + // extract as string + tempQuotaRemainingOnlineString = quota["remaining"].str; + } + + // Fallback + if (tempQuotaRemainingOnlineString.empty) { + // tempQuotaRemainingOnlineString was not set, set to zero as a string + tempQuotaRemainingOnlineString = "0"; + } + + // Update quotaRemainingOnline to use the converted string value + quotaRemainingOnline = to!long(tempQuotaRemainingOnlineString); // Set the applicable 'quotaAvailable' value quotaAvailable = quotaRemainingOnline > 0;