From 0c13629f1ec27944b63815d0cd1134d4dd70995b Mon Sep 17 00:00:00 2001 From: benweet Date: Thu, 28 Mar 2013 23:06:03 +0000 Subject: [PATCH] gdrive support --- js/gdrive.js | 9 ++++++--- js/main.js | 12 ++++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/js/gdrive.js b/js/gdrive.js index 259f259c..b95e13be 100644 --- a/js/gdrive.js +++ b/js/gdrive.js @@ -41,7 +41,7 @@ var gdrive = (function() { var method = 'POST'; if (fileId) { // If it's an update - path += fileId; + path += "/" + fileId; method = 'PUT'; } @@ -60,8 +60,11 @@ var gdrive = (function() { + boundary + '"', }, 'body' : multipartRequestBody, }); request.execute(function(file) { unsetWorkingIndicator(FLAG_GDRIVE_UPLOAD); - var fileSyncIndex = SYNC_PROVIDER_GDRIVE + file.id; - localStorage[fileSyncIndex + ".etag"] = file.etag; + var fileSyncIndex = undefined; + if(file.id) { + fileSyncIndex = SYNC_PROVIDER_GDRIVE + file.id; + localStorage[fileSyncIndex + ".etag"] = file.etag; + } if (callback) { callback(fileSyncIndex); } diff --git a/js/main.js b/js/main.js index 3ccbd9c4..648ebd90 100644 --- a/js/main.js +++ b/js/main.js @@ -59,7 +59,10 @@ var synchronizer = (function($) { // Try to find the provider if(fileSyncIndex.indexOf(SYNC_PROVIDER_GDRIVE) === 0) { var id = fileSyncIndex.substring(SYNC_PROVIDER_GDRIVE.length); - gdrive.updateFile(id, title, content, function() { + gdrive.updateFile(id, title, content, function(result) { + if(!result) { + showError("Error while uploading file on Google Drive"); + } sync(fileSyncIndexList, content, title); }); } else { @@ -140,7 +143,12 @@ var fileManager = (function($) { var title = localStorage[fileIndex + ".title"]; (function(fileIndex) { gdrive.createFile(title, content, function(fileSyncIndex) { - localStorage[fileIndex + ".sync"] += fileSyncIndex + ";"; + if(fileSyncIndex) { + localStorage[fileIndex + ".sync"] += fileSyncIndex + ";"; + } + else { + showError("Error while creating file on Google Drive"); + } }); })(fileIndex); });