You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2014/12/06 01:14:20 UTC

[1/2] cordova-plugin-file-transfer git commit: exec guarentees that proxy is called with success/error function so there is no need to constantly check that it exists

Repository: cordova-plugin-file-transfer
Updated Branches:
  refs/heads/master 7fbab9fa1 -> e6e44aaa2


exec guarentees that proxy is called with success/error function so there is no need to constantly check that it exists


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/commit/71bd73ec
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/tree/71bd73ec
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/diff/71bd73ec

Branch: refs/heads/master
Commit: 71bd73ec9cdcdb5a2afbc9167b938668ca9b87d2
Parents: 7fbab9f
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Fri Dec 5 15:58:16 2014 -0800
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Fri Dec 5 15:58:16 2014 -0800

----------------------------------------------------------------------
 src/windows/FileTransferProxy.js | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/71bd73ec/src/windows/FileTransferProxy.js
----------------------------------------------------------------------
diff --git a/src/windows/FileTransferProxy.js b/src/windows/FileTransferProxy.js
index 82e7965..130f903 100644
--- a/src/windows/FileTransferProxy.js
+++ b/src/windows/FileTransferProxy.js
@@ -76,7 +76,7 @@ exec(win, fail, 'FileTransfer', 'upload',
         var uploadId = options[9];
 
         if (filePath === null || typeof filePath === 'undefined') {
-            errorCallback && errorCallback(new FTErr(FTErr.FILE_NOT_FOUND_ERR,null,server));
+            errorCallback(new FTErr(FTErr.FILE_NOT_FOUND_ERR,null,server));
             return;
         }
 
@@ -111,7 +111,7 @@ exec(win, fail, 'FileTransfer', 'upload',
                 var uploadOp = fileTransferOps[uploadId];
                 if (uploadOp && uploadOp.state == FileTransferOperation.CANCELLED) {
                     // Here we should call errorCB with ABORT_ERR error
-                    errorCallback && errorCallback(new FTErr(FTErr.ABORT_ERR, filePath, server));
+                    errorCallback(new FTErr(FTErr.ABORT_ERR, filePath, server));
                     return;
                 }
 
@@ -131,30 +131,30 @@ exec(win, fail, 'FileTransfer', 'upload',
                     fileTransferOps[uploadId].promise = uploadOperation;
                 } catch (e) {
                     // it will fail if URL is malformed, so we handle this situation
-                    errorCallback && errorCallback(new FTErr(FTErr.INVALID_URL_ERR, filePath, server, null, null, e));
+                    errorCallback(new FTErr(FTErr.INVALID_URL_ERR, filePath, server, null, null, e));
                     return;
                 }
 
                 uploadOperation.then(function (response) {
                     storageFile.getBasicPropertiesAsync().done(function(basicProperties) {
                         var ftResult = new FileUploadResult(basicProperties.size, response.status, response.responseText);
-                        successCallback && successCallback(ftResult);
+                        successCallback(ftResult);
                     });
                 }, function(err) {
                     if ('status' in err) {
-                        errorCallback && errorCallback(new FTErr(FTErr.CONNECTION_ERR, filePath, server, err.status, err.responseText, err));
+                        errorCallback(new FTErr(FTErr.CONNECTION_ERR, filePath, server, err.status, err.responseText, err));
                     } else {
-                        errorCallback && errorCallback(new FTErr(FTErr.INVALID_URL_ERR, filePath, server, null, null, err));
+                        errorCallback(new FTErr(FTErr.INVALID_URL_ERR, filePath, server, null, null, err));
                     }
                 }, function(evt) {
                     // progress event handler, calls successCallback with empty ProgressEvent
                     // We can't specify ProgressEvent data here since evt not provides any helpful information
                     var progressEvent = new ProgressEvent('progress');
-                    successCallback && successCallback(progressEvent, { keepCallback: true });
+                    successCallback(progressEvent, { keepCallback: true });
                 });
             });
         }, function(err) {
-            errorCallback && errorCallback(new FTErr(FTErr.FILE_NOT_FOUND_ERR, server, server, null, null, err));
+            errorCallback(new FTErr(FTErr.FILE_NOT_FOUND_ERR, server, server, null, null, err));
         });
     },
 
@@ -166,7 +166,7 @@ exec(win, fail, 'FileTransfer', 'upload',
         var headers = options[4] || {};
 
         if (target === null || typeof target === undefined) {
-            errorCallback && errorCallback(new FTErr(FTErr.FILE_NOT_FOUND_ERR);
+            errorCallback(new FTErr(FTErr.FILE_NOT_FOUND_ERR);
             return;
         }
         if (String(target).substr(0, 8) == "file:///") {
@@ -182,7 +182,7 @@ exec(win, fail, 'FileTransfer', 'upload',
         var path = target.substr(0, String(target).lastIndexOf("\\"));
         var fileName = target.substr(String(target).lastIndexOf("\\") + 1);
         if (path === null || fileName === null) {
-            errorCallback && errorCallback(new FTErr(FTErr.FILE_NOT_FOUND_ERR));
+            errorCallback(new FTErr(FTErr.FILE_NOT_FOUND_ERR));
             return;
         }
 
@@ -198,7 +198,7 @@ exec(win, fail, 'FileTransfer', 'upload',
                 var downloadOp = fileTransferOps[downloadId];
                 if (downloadOp && downloadOp.state == FileTransferOperation.CANCELLED) {
                     // Here we should call errorCB with ABORT_ERR error
-                    errorCallback && errorCallback(new FTErr(FTErr.ABORT_ERR, source, target));
+                    errorCallback(new FTErr(FTErr.ABORT_ERR, source, target));
                     return;
                 }
 
@@ -214,7 +214,7 @@ exec(win, fail, 'FileTransfer', 'upload',
                     download = downloader.createDownload(uri, storageFile);
                 } catch (e) {
                     // so we handle this and call errorCallback
-                    errorCallback && errorCallback(new FTErr(FTErr.INVALID_URL_ERR));
+                    errorCallback(new FTErr(FTErr.INVALID_URL_ERR));
                     return;
                 }
 
@@ -236,7 +236,7 @@ exec(win, fail, 'FileTransfer', 'upload',
                         .replace(appData.temporaryFolder.path, 'ms-appdata:///temp')
                         .replace('\\', '/');
 
-                    successCallback && successCallback(new FileEntry(storageFile.name, storageFile.path, null, nativeURI));
+                    successCallback(new FileEntry(storageFile.name, storageFile.path, null, nativeURI));
                 }, function(error) {
 
                     var getTransferError = new WinJS.Promise(function (resolve) {
@@ -270,7 +270,7 @@ exec(win, fail, 'FileTransfer', 'upload',
 
                         // Cleanup, remove incompleted file
                         storageFile.deleteAsync().then(function() {
-                            errorCallback && errorCallback(fileTransferError);
+                            errorCallback(fileTransferError);
                         });
                     });
 
@@ -283,15 +283,15 @@ exec(win, fail, 'FileTransfer', 'upload',
                     });
                     progressEvent.lengthComputable = true;
 
-                    successCallback && successCallback(progressEvent, { keepCallback: true });
+                    successCallback(progressEvent, { keepCallback: true });
                 });
             }, function(error) {
-                errorCallback && errorCallback(new FTErr(FTErr.FILE_NOT_FOUND_ERR, source, target, null, null, error));
+                errorCallback(new FTErr(FTErr.FILE_NOT_FOUND_ERR, source, target, null, null, error));
             });
         };
         
         var fileNotFoundErrorCallback = function(error) {
-            errorCallback && errorCallback(new FTErr(FTErr.FILE_NOT_FOUND_ERR, source, target, null, null, error));
+            errorCallback(new FTErr(FTErr.FILE_NOT_FOUND_ERR, source, target, null, null, error));
         };
 
         Windows.Storage.StorageFolder.getFolderFromPathAsync(path).then(downloadCallback, function (error) {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


[2/2] cordova-plugin-file-transfer git commit: removed unneeded String() casting all over the place, fixed my own missing ) error

Posted by pu...@apache.org.
removed unneeded String() casting all over the place, fixed my own missing ) error


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/commit/e6e44aaa
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/tree/e6e44aaa
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/diff/e6e44aaa

Branch: refs/heads/master
Commit: e6e44aaa2f184f62b9c156c4fc163a9d51f145a1
Parents: 71bd73e
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Fri Dec 5 16:13:49 2014 -0800
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Fri Dec 5 16:13:49 2014 -0800

----------------------------------------------------------------------
 src/windows/FileTransferProxy.js | 47 ++++++++++++++++++-----------------
 1 file changed, 24 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/e6e44aaa/src/windows/FileTransferProxy.js
----------------------------------------------------------------------
diff --git a/src/windows/FileTransferProxy.js b/src/windows/FileTransferProxy.js
index 130f903..57c9ccd 100644
--- a/src/windows/FileTransferProxy.js
+++ b/src/windows/FileTransferProxy.js
@@ -31,8 +31,10 @@ var appData = Windows.Storage.ApplicationData.current;
 
 // Some private helper functions, hidden by the module
 function cordovaPathToNative(path) {
+
+    var cleanPath = String(path);
     // turn / into \\
-    var cleanPath = path.replace(/\//g, '\\');
+    cleanPath = cleanPath.replace(/\//g, '\\');
     // turn  \\ into \
     cleanPath = cleanPath.replace(/\\\\/g, '\\');
     // strip end \\ characters
@@ -41,8 +43,7 @@ function cordovaPathToNative(path) {
 }
 
 function nativePathToCordova(path) {
-    var cleanPath = path.replace(/\\/g, '/');
-    return cleanPath;
+    return String(path).replace(/\\/g, '/');
 }
 
 var fileTransferOps = [];
@@ -75,18 +76,17 @@ exec(win, fail, 'FileTransfer', 'upload',
         var headers = options[8] || {};
         var uploadId = options[9];
 
-        if (filePath === null || typeof filePath === 'undefined') {
+        if (!filePath || (typeof filePath != 'string')) {
             errorCallback(new FTErr(FTErr.FILE_NOT_FOUND_ERR,null,server));
             return;
         }
 
-        if (String(filePath).substr(0, 8) == "file:///") {
-            filePath = appData.localFolder.path + String(filePath).substr(8).split("/").join("\\");
-        } else if (String(filePath).indexOf('ms-appdata:///') === 0) {
+        if (filePath.substr(0, 8) == "file:///") {
+            filePath = appData.localFolder.path + filePath.substr(8).split("/").join("\\");
+        } else if (filePath.indexOf('ms-appdata:///') === 0) {
             // Handle 'ms-appdata' scheme
-            filePath = filePath.toString()
-                .replace('ms-appdata:///local', appData.localFolder.path)
-                .replace('ms-appdata:///temp', appData.temporaryFolder.path);
+            filePath = filePath.replace('ms-appdata:///local', appData.localFolder.path)
+                               .replace('ms-appdata:///temp', appData.temporaryFolder.path);
         }
         // normalize path separators
         filePath = cordovaPathToNative(filePath);
@@ -94,7 +94,8 @@ exec(win, fail, 'FileTransfer', 'upload',
         // Create internal download operation object
         fileTransferOps[uploadId] = new FileTransferOperation(FileTransferOperation.PENDING, null);
 
-        Windows.Storage.StorageFile.getFileFromPathAsync(filePath).then(function (storageFile) {
+        Windows.Storage.StorageFile.getFileFromPathAsync(filePath)
+        .then(function (storageFile) {
 
             if(!fileName) {
                 fileName = storageFile.name;
@@ -105,7 +106,8 @@ exec(win, fail, 'FileTransfer', 'upload',
                 mimeType = storageFile.contentType;
             }
 
-            storageFile.openAsync(Windows.Storage.FileAccessMode.read).then(function (stream) {
+            storageFile.openAsync(Windows.Storage.FileAccessMode.read)
+            .then(function (stream) {
 
                 // check if upload isn't already cancelled
                 var uploadOp = fileTransferOps[uploadId];
@@ -165,22 +167,21 @@ exec(win, fail, 'FileTransfer', 'upload',
         var downloadId = options[3];
         var headers = options[4] || {};
 
-        if (target === null || typeof target === undefined) {
-            errorCallback(new FTErr(FTErr.FILE_NOT_FOUND_ERR);
+        if (!target) {
+            errorCallback(new FTErr(FTErr.FILE_NOT_FOUND_ERR));
             return;
         }
-        if (String(target).substr(0, 8) == "file:///") {
-            target = appData.localFolder.path + String(target).substr(8).split("/").join("\\");
-        } else if (String(target).indexOf('ms-appdata:///') === 0) {
+        if (target.substr(0, 8) == "file:///") {
+            target = appData.localFolder.path + target.substr(8).split("/").join("\\");
+        } else if (target.indexOf('ms-appdata:///') === 0) {
             // Handle 'ms-appdata' scheme
-            target = target.toString()
-                .replace('ms-appdata:///local', appData.localFolder.path)
-                .replace('ms-appdata:///temp', appData.temporaryFolder.path);
+            target = target.replace('ms-appdata:///local', appData.localFolder.path)
+                           .replace('ms-appdata:///temp', appData.temporaryFolder.path);
         }
-        target = cordovaPathToNative(target);
+        target = cordovaPathToNative(target); // again?
 
-        var path = target.substr(0, String(target).lastIndexOf("\\"));
-        var fileName = target.substr(String(target).lastIndexOf("\\") + 1);
+        var path = target.substr(0, target.lastIndexOf("\\"));
+        var fileName = target.substr(target.lastIndexOf("\\") + 1);
         if (path === null || fileName === null) {
             errorCallback(new FTErr(FTErr.FILE_NOT_FOUND_ERR));
             return;


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org