cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject git commit: CB-2421 explicitly write the bytesSent, responseCode, result to the FileUploadResult pending release of cordova-plugin-file dependency, added some sanity checks for callbacks
Date Tue, 28 Jan 2014 23:24:21 GMT
Updated Branches:
  refs/heads/dev 4ca546b3d -> be4419406


CB-2421 explicitly write the bytesSent,responseCode,result to the FileUploadResult pending
release of cordova-plugin-file dependency, added some sanity checks for callbacks


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/be441940
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/tree/be441940
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/diff/be441940

Branch: refs/heads/dev
Commit: be44194066f20b1b927608005f76afb7d11994d6
Parents: 4ca546b
Author: Jesse MacFadyen <purplecabbage@gmail.com>
Authored: Tue Jan 28 15:23:10 2014 -0800
Committer: Jesse MacFadyen <purplecabbage@gmail.com>
Committed: Tue Jan 28 15:23:10 2014 -0800

----------------------------------------------------------------------
 www/windows8/FileTransferProxy.js | 32 +++++++++++++++++---------------
 1 file changed, 17 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/be441940/www/windows8/FileTransferProxy.js
----------------------------------------------------------------------
diff --git a/www/windows8/FileTransferProxy.js b/www/windows8/FileTransferProxy.js
index 6f5c0f9..5c09805 100644
--- a/www/windows8/FileTransferProxy.js
+++ b/www/windows8/FileTransferProxy.js
@@ -31,13 +31,8 @@ module.exports = {
         var server = options[1];
         var headers = options[8] || {};
 
-
-        var win = function (fileUploadResult) {
-            successCallback(fileUploadResult);
-        };
-
         if (filePath === null || typeof filePath === 'undefined') {
-            error(FileTransferError.FILE_NOT_FOUND_ERR);
+            error && error(FileTransferError.FILE_NOT_FOUND_ERR);
             return;
         }
 
@@ -58,27 +53,34 @@ module.exports = {
                             var dataReader = Windows.Storage.Streams.DataReader.fromBuffer(buffer);
                             var fileContent = dataReader.readString(buffer.length);
                             dataReader.close();
-                            win(new FileUploadResult(basicProperties.size, code, fileContent));
-
+                            var ftResult = new FileUploadResult(basicProperties.size, code,
fileContent);
+                            // for now we explicitly write the bytesSent,responseCode,result

+                            // in case cordova-plugin-file is not yet updated. -jm
+                            ftResult.bytesSent = basicProperties.size;
+                            ftResult.responseCode = code;
+                            ftResult.response = fileContent;
+                            successCallback && successCallback(ftResult);
                         });
 
                     });
                 }, function () {
-                    error(FileTransferError.INVALID_URL_ERR);
+                    error && error(FileTransferError.INVALID_URL_ERR);
                 });
             });
 
-        },function(){error(FileTransferError.FILE_NOT_FOUND_ERR);});
+        },function() {
+            error && error(FileTransferError.FILE_NOT_FOUND_ERR);
+        });
     },
 
-    download:function(win, error, options) {
+    download:function(successCallback, error, options) {
         var source = options[0];
         var target = options[1];
         var headers = options[4] || {};
 
 
         if (target === null || typeof target === undefined) {
-            error(FileTransferError.FILE_NOT_FOUND_ERR);
+            error && error(FileTransferError.FILE_NOT_FOUND_ERR);
             return;
         }
         if (String(target).substr(0, 8) == "file:///") {
@@ -87,7 +89,7 @@ module.exports = {
         var path = target.substr(0, String(target).lastIndexOf("\\"));
         var fileName = target.substr(String(target).lastIndexOf("\\") + 1);
         if (path === null || fileName === null) {
-            error(FileTransferError.FILE_NOT_FOUND_ERR);
+            error && error(FileTransferError.FILE_NOT_FOUND_ERR);
             return;
         }
 
@@ -106,9 +108,9 @@ module.exports = {
 
                 download = downloader.createDownload(uri, storageFile);
                 download.startAsync().then(function () {
-                    win(new FileEntry(storageFile.name, storageFile.path));
+                    successCallback && successCallback(new FileEntry(storageFile.name,
storageFile.path));
                 }, function () {
-                    error(FileTransferError.INVALID_URL_ERR);
+                    error && error(FileTransferError.INVALID_URL_ERR);
                 });
             });
         });


Mime
View raw message