From af58afcffff5ac556d16f050a325ac0406897fcd Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Tue, 7 Feb 2012 17:03:44 -0800 Subject: Copy local library to cloud Adding functionality to copy a local library to the cloud. Currently creating directory structure. Need to add ability to copy files and ensure proper mime-type is set. --- js/io/system/chromeapi.js | 43 +++++++++++++++++++++++-- js/io/system/coreioapi.js | 13 +++++++- js/io/system/ninjalibrary.js | 77 ++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 127 insertions(+), 6 deletions(-) (limited to 'js') diff --git a/js/io/system/chromeapi.js b/js/io/system/chromeapi.js index 2fc8769c..fc93b22a 100644 --- a/js/io/system/chromeapi.js +++ b/js/io/system/chromeapi.js @@ -7,11 +7,10 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot /* ///////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// NOTES: + The init function starts up the file system API, and a size must be set, no unlimited available as of now. - Core API reference in NINJA: this.application.ninja.coreIoApi - //////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////// */ // @@ -123,6 +122,46 @@ exports.ChromeApi = Montage.create(Object.prototype, { } }, //////////////////////////////////////////////////////////////////// + // + fileDelete: { + enumerable: true, + value: function(filePath, callback) { + this.fileSystem.root.getFile(filePath, {create: false}, function(file) { + file.remove(function() { + if (callback) callback(true); + }); + }, function (e) {if (callback) callback(false)}); + } + }, + //////////////////////////////////////////////////////////////////// + // + fileContent: { + enumerable: true, + value: function() { + } + }, + //////////////////////////////////////////////////////////////////// + // + fileCopy: { + enumerable: true, + value: function() { + } + }, + //////////////////////////////////////////////////////////////////// + // + fileRename: { + enumerable: true, + value: function() { + } + }, + //////////////////////////////////////////////////////////////////// + // + fileMove: { + enumerable: true, + value: function() { + } + }, + //////////////////////////////////////////////////////////////////// //Creating directory from path, callback optional directoryNew: { enumerable: true, diff --git a/js/io/system/coreioapi.js b/js/io/system/coreioapi.js index 005eabf2..7edb469b 100755 --- a/js/io/system/coreioapi.js +++ b/js/io/system/coreioapi.js @@ -83,10 +83,21 @@ exports.CoreIoApi = Montage.create(Component, { handleSync: { enumerable: false, value: function (e) { - //Removing events console.log('Ninja Local Library: Ready'); + //Removing events this.ninjaLibrary.removeEventListener('sync', this, false); + this.ninjaLibrary.coreApi = this; //TODO: Add sync loading screen logic + + + + + //TODO: Remove test + this.ninjaLibrary.copyLibToCloud('Users/kgq387/Desktop/Ninja Cloud/Disk', 'montage0.6.0'); + + + + } }, //////////////////////////////////////////////////////////////////// diff --git a/js/io/system/ninjalibrary.js b/js/io/system/ninjalibrary.js index fa2e7d1f..0ab19401 100644 --- a/js/io/system/ninjalibrary.js +++ b/js/io/system/ninjalibrary.js @@ -8,8 +8,6 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot //////////////////////////////////////////////////////////////////////// NOTES: - Core API reference in NINJA: this.application.ninja.coreIoApi - //////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////// */ // @@ -36,6 +34,23 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { }, //////////////////////////////////////////////////////////////////// // + _coreApi: { + enumerable: false, + value: null + }, + //////////////////////////////////////////////////////////////////// + // + coreApi: { + enumerable: false, + get: function() { + return this._coreApi; + }, + set: function(value) { + this._coreApi = value; + } + }, + //////////////////////////////////////////////////////////////////// + // _libsToSync: { enumerable: false, value: 0 @@ -45,6 +60,62 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { _syncedLibs: { enumerable: false, value: 0 + }, + //////////////////////////////////////////////////////////////////// + // + copyLibToCloud: { + enumerable: false, + value: function (path, libName) { + // + if(this.coreApi.directoryExists({uri: '/'+path+'/'+libName+'/'}).status === 404) { + this.chromeApi.directoryContents(this.chromeApi.fileSystem.root, function (contents) { + for (var i in contents) { + if (libName === contents[i].name) { + //Getting contents of library to be copied + this.chromeApi.directoryContents(contents[i], function (lib) { + //Creating directory structure from subfolders + this.copyDirectoryToCloud(path, contents[i], function (status) {console.log(status)}); + }.bind(this)); + break; + } + } + }.bind(this)); + } else { + //Error + } + } + }, + //////////////////////////////////////////////////////////////////// + // + copyDirectoryToCloud: { + enumerable: true, + value: function(root, folder, callback) { + if (folder.name) { + var dir; + if (root) { + dir = root+'/'+folder.name; + } else { + dir = folder.name; + } + // + if (!this.coreApi.createDirectory({uri: '/'+dir+'/'})) { + //Error occured while creating folders + return; + } + } + // + if (folder.isDirectory) { + this.chromeApi.directoryContents(folder, function (contents) { + for (var i in contents) { + if (contents[i].isDirectory) { + this.copyDirectoryToCloud(dir, contents[i]); + } else if (contents[i].isFile){ + //File to copy + } + } + }.bind(this)); + } + } }, //////////////////////////////////////////////////////////////////// // @@ -81,7 +152,7 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { } } else { //TODO: Remove, currently manually removing copied libraries - this.chromeApi.directoryDelete(chromeLibs[i]); + //this.chromeApi.directoryDelete(chromeLibs[i]); } } -- cgit v1.2.3