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

This commit is contained in:
Jesse MacFadyen
2014-12-05 15:58:16 -08:00
parent 7fbab9fa1c
commit 71bd73ec9c
+17 -17
View File
@@ -76,7 +76,7 @@ exec(win, fail, 'FileTransfer', 'upload',
var uploadId = options[9]; var uploadId = options[9];
if (filePath === null || typeof filePath === 'undefined') { 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; return;
} }
@@ -111,7 +111,7 @@ exec(win, fail, 'FileTransfer', 'upload',
var uploadOp = fileTransferOps[uploadId]; var uploadOp = fileTransferOps[uploadId];
if (uploadOp && uploadOp.state == FileTransferOperation.CANCELLED) { if (uploadOp && uploadOp.state == FileTransferOperation.CANCELLED) {
// Here we should call errorCB with ABORT_ERR error // 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; return;
} }
@@ -131,30 +131,30 @@ exec(win, fail, 'FileTransfer', 'upload',
fileTransferOps[uploadId].promise = uploadOperation; fileTransferOps[uploadId].promise = uploadOperation;
} catch (e) { } catch (e) {
// it will fail if URL is malformed, so we handle this situation // 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; return;
} }
uploadOperation.then(function (response) { uploadOperation.then(function (response) {
storageFile.getBasicPropertiesAsync().done(function(basicProperties) { storageFile.getBasicPropertiesAsync().done(function(basicProperties) {
var ftResult = new FileUploadResult(basicProperties.size, response.status, response.responseText); var ftResult = new FileUploadResult(basicProperties.size, response.status, response.responseText);
successCallback && successCallback(ftResult); successCallback(ftResult);
}); });
}, function(err) { }, function(err) {
if ('status' in 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 { } 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) { }, function(evt) {
// progress event handler, calls successCallback with empty ProgressEvent // progress event handler, calls successCallback with empty ProgressEvent
// We can't specify ProgressEvent data here since evt not provides any helpful information // We can't specify ProgressEvent data here since evt not provides any helpful information
var progressEvent = new ProgressEvent('progress'); var progressEvent = new ProgressEvent('progress');
successCallback && successCallback(progressEvent, { keepCallback: true }); successCallback(progressEvent, { keepCallback: true });
}); });
}); });
}, function(err) { }, 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] || {}; var headers = options[4] || {};
if (target === null || typeof target === undefined) { if (target === null || typeof target === undefined) {
errorCallback && errorCallback(new FTErr(FTErr.FILE_NOT_FOUND_ERR); errorCallback(new FTErr(FTErr.FILE_NOT_FOUND_ERR);
return; return;
} }
if (String(target).substr(0, 8) == "file:///") { 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 path = target.substr(0, String(target).lastIndexOf("\\"));
var fileName = target.substr(String(target).lastIndexOf("\\") + 1); var fileName = target.substr(String(target).lastIndexOf("\\") + 1);
if (path === null || fileName === null) { if (path === null || fileName === null) {
errorCallback && errorCallback(new FTErr(FTErr.FILE_NOT_FOUND_ERR)); errorCallback(new FTErr(FTErr.FILE_NOT_FOUND_ERR));
return; return;
} }
@@ -198,7 +198,7 @@ exec(win, fail, 'FileTransfer', 'upload',
var downloadOp = fileTransferOps[downloadId]; var downloadOp = fileTransferOps[downloadId];
if (downloadOp && downloadOp.state == FileTransferOperation.CANCELLED) { if (downloadOp && downloadOp.state == FileTransferOperation.CANCELLED) {
// Here we should call errorCB with ABORT_ERR error // 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; return;
} }
@@ -214,7 +214,7 @@ exec(win, fail, 'FileTransfer', 'upload',
download = downloader.createDownload(uri, storageFile); download = downloader.createDownload(uri, storageFile);
} catch (e) { } catch (e) {
// so we handle this and call errorCallback // so we handle this and call errorCallback
errorCallback && errorCallback(new FTErr(FTErr.INVALID_URL_ERR)); errorCallback(new FTErr(FTErr.INVALID_URL_ERR));
return; return;
} }
@@ -236,7 +236,7 @@ exec(win, fail, 'FileTransfer', 'upload',
.replace(appData.temporaryFolder.path, 'ms-appdata:///temp') .replace(appData.temporaryFolder.path, 'ms-appdata:///temp')
.replace('\\', '/'); .replace('\\', '/');
successCallback && successCallback(new FileEntry(storageFile.name, storageFile.path, null, nativeURI)); successCallback(new FileEntry(storageFile.name, storageFile.path, null, nativeURI));
}, function(error) { }, function(error) {
var getTransferError = new WinJS.Promise(function (resolve) { var getTransferError = new WinJS.Promise(function (resolve) {
@@ -270,7 +270,7 @@ exec(win, fail, 'FileTransfer', 'upload',
// Cleanup, remove incompleted file // Cleanup, remove incompleted file
storageFile.deleteAsync().then(function() { storageFile.deleteAsync().then(function() {
errorCallback && errorCallback(fileTransferError); errorCallback(fileTransferError);
}); });
}); });
@@ -283,15 +283,15 @@ exec(win, fail, 'FileTransfer', 'upload',
}); });
progressEvent.lengthComputable = true; progressEvent.lengthComputable = true;
successCallback && successCallback(progressEvent, { keepCallback: true }); successCallback(progressEvent, { keepCallback: true });
}); });
}, function(error) { }, 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) { 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) { Windows.Storage.StorageFolder.getFolderFromPathAsync(path).then(downloadCallback, function (error) {