From 75a2a677584e3c3b05ebd0fbba7d6f1c34bee353 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20Lindstr=C3=B8m=20Nielsen?= Date: Sat, 20 Oct 2012 13:58:35 -0700 Subject: [PATCH 1/6] Updated readdir --- dbox.js | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/dbox.js b/dbox.js index 6d43c60..9d562a9 100644 --- a/dbox.js +++ b/dbox.js @@ -170,11 +170,24 @@ exports.app = function(config){ // // Recursively loads a dropbox folder // - readdir: function (path, callback) { + readdir: function (path, args, cb) { var results = [], REQUEST_CONCURRENCY_DELAY = 200, callbacks = 0, - self = this; + errors = 0, + self = this, + opts = { + files: args.files !== null ? args.dir : true, + dirs: args.dirs !== null ? args.dir : true, + mime_type: (args.mime_type === null ? new RegExp(".+","i") : + (args.mime_type instanceof RegExp ? args.mime_type : + new RegExp( (args.mime_type.indexOf('/') >= 0 ? args.mime_type : args.mime_type + "/.+" ), "i" ))) + }; + + if(cb == null){ + cb = args + } + // // Remark: REQUEST_CONCURRENCY_DELAY represents the millisecond, // delay between outgoing requests to dropbox @@ -190,29 +203,28 @@ exports.app = function(config){ // // If we have found any contents on this level of the folder // - if (reply.contents) { + if (reply !== null && reply.contents) { reply.contents.forEach(function (item) { // // Add the item into our results array // - results.push(item.path); + if ((item.is_dir && opts.dirs) || (!item.is_dir && opts.files && opts.mime_type.test(item.mime_type))) results.push(item); // // If we have encountered another folder, we are going to recurse on it // - if (item.is_dir) { - load(item.path); - } + if (item.is_dir) load(item.path); }); + } else { + errors++; } callbacks--; if (callbacks === 0) { - callback(status, results); + cb(errors, results); } }); }, REQUEST_CONCURRENCY_DELAY) } - console.log('warn: recursively loading data from dropbox...this may take some time'); - load(path, results); + load(path); }, revisions: function(path, args, cb){ From ebe21ef7e9b860b35a6462447718ab4cfce94916 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20Lindstr=C3=B8m=20Nielsen?= Date: Mon, 14 Jan 2013 18:18:07 -0800 Subject: [PATCH 2/6] changed a little bug with the names of the app/access_token files --- test/all.js | 1 + test/config/helpers.js | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/test/all.js b/test/all.js index 437a3f6..45bf329 100644 --- a/test/all.js +++ b/test/all.js @@ -9,6 +9,7 @@ describe("all", function(){ var client, ref; before(function(done){ + this.timeout(20000); //To give the testrunner time for accepting the dropbox access helpers.auth(app, function(access_token){ client = app.client(access_token) done() diff --git a/test/config/helpers.js b/test/config/helpers.js index 995305d..991f5fc 100644 --- a/test/config/helpers.js +++ b/test/config/helpers.js @@ -2,11 +2,11 @@ var fs = require("fs") var prompt = require("prompt") exports.auth = function(app, callback){ - var token = JSON.parse(fs.readFileSync(__dirname + "/access_token.json")) - var client = app.client(token) + var app_setup = JSON.parse(fs.readFileSync(__dirname + "/app.json")) + var client = app.client(app_setup) client.account(function(status, account){ if(status == 200){ - callback(token) + callback(app_setup) }else{ app.requesttoken(function(status, request_token){ prompt.start() From 6089d7496e9853b4289db995878d033998a12058 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20Lindstr=C3=B8m=20Nielsen?= Date: Mon, 14 Jan 2013 18:35:26 -0800 Subject: [PATCH 3/6] if there exists an access_token this will tried to be used otherwise it creates a new --- test/config/app.json.sample | 3 ++- test/config/helpers.js | 44 ++++++++++++++++++++++--------------- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/test/config/app.json.sample b/test/config/app.json.sample index 048e3a8..a70cc26 100644 --- a/test/config/app.json.sample +++ b/test/config/app.json.sample @@ -1,4 +1,5 @@ { "app_key": "", - "app_secret": "" + "app_secret": "", + "root": "sandbox" } \ No newline at end of file diff --git a/test/config/helpers.js b/test/config/helpers.js index 991f5fc..fb23e1e 100644 --- a/test/config/helpers.js +++ b/test/config/helpers.js @@ -2,24 +2,32 @@ var fs = require("fs") var prompt = require("prompt") exports.auth = function(app, callback){ - var app_setup = JSON.parse(fs.readFileSync(__dirname + "/app.json")) - var client = app.client(app_setup) - client.account(function(status, account){ - if(status == 200){ - callback(app_setup) - }else{ - app.requesttoken(function(status, request_token){ - prompt.start() - prompt.get(['please authorize application at the following url and enter when done\n' + request_token.authorize_url], function (err, result) { - if (err) { return 1 } - app.accesstoken(request_token, function(status, access_token){ - fs.writeFile(__dirname + "/access_token.json", JSON.stringify(access_token), function(err){ - if (err) throw err; - callback(access_token) - }) + var makeNewAccessToken = function() { + app.requesttoken(function(status, request_token){ + prompt.start() + prompt.get(['please authorize application at the following url and enter when done\n' + request_token.authorize_url], function (err, result) { + if (err) { return 1 } + app.accesstoken(request_token, function(status, access_token){ + fs.writeFile(__dirname + "/access_token.json", JSON.stringify(access_token), function(err){ + if (err) throw err; + callback(access_token) }) }) - }) - } - }) + }) + }) + } + + if (fs.existsSync(__dirname + "/access_token.json")) { + var access_token = JSON.parse(fs.readFileSync(__dirname + "/access_token.json")) + var client = app.client(access_token) + client.account(function(status, account){ + if(status == 200){ + callback(access_token) + }else{ + makeNewAccessToken(); + } + }) + } else { + makeNewAccessToken(); + } } \ No newline at end of file From c7cc76921cc5e8e01218b96c659d429cc0541c79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20Lindstr=C3=B8m=20Nielsen?= Date: Mon, 14 Jan 2013 18:46:31 -0800 Subject: [PATCH 4/6] doc'ed root param --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 11c4395..c9415be 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,9 @@ Creating a functional `dbox` client is a four step process. ### Step 1 var dbox = require("dbox") - var app = dbox.app({ "app_key": "umdez34678ck01fx", "app_secret": "tjm89017sci88o6" }) + var app = dbox.app({ "app_key": "umdez34678ck01fx", "app_secret": "tjm89017sci88o6"[, "root": "sandbox"] }) + +_NB_: the root parameter is to change between the two different dropbox app types there are. `sandbox` means 'App folder' and `dropbox` means 'Full Dropbox', default is `sandbox`. ### Step 2 From efd48e35bef0577ce6651caec5f21051e1718b98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20Lindstr=C3=B8m=20Nielsen?= Date: Mon, 14 Jan 2013 18:50:31 -0800 Subject: [PATCH 5/6] removed the conflicts --- dbox.js | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/dbox.js b/dbox.js index c846502..cce0da9 100644 --- a/dbox.js +++ b/dbox.js @@ -179,18 +179,7 @@ exports.app = function(config){ // Loads a dropbox folder // (recursive by default) // -<<<<<<< HEAD readdir: function (path, args, cb) { -======= - readdir: function (path, options, callback) { - if (arguments.length < 3) { - callback = options; - options = options || {}; - } - options.recursive = (options.recursive !== false); // default true - options.details = (options.details === true); // default false - ->>>>>>> 3e9e257584c8738d61b600ba8abf2794a39b1ce5 var results = [], REQUEST_CONCURRENCY_DELAY = 200, callbacks = 0, From 3f611777eecf6a385327cc62f3b316f46ac86513 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20Lindstr=C3=B8m=20Nielsen?= Date: Mon, 14 Jan 2013 18:52:00 -0800 Subject: [PATCH 6/6] removed the conflicts2 --- dbox.js | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/dbox.js b/dbox.js index cce0da9..f6ab0aa 100644 --- a/dbox.js +++ b/dbox.js @@ -179,24 +179,18 @@ exports.app = function(config){ // Loads a dropbox folder // (recursive by default) // - readdir: function (path, args, cb) { + readdir: function (path, options, callback) { + if (arguments.length < 3) { + callback = options; + options = options || {}; + } + options.recursive = (options.recursive !== false); // default true + options.details = (options.details === true); // default false + var results = [], REQUEST_CONCURRENCY_DELAY = 200, callbacks = 0, - errors = 0, - self = this, - opts = { - files: args.files !== null ? args.dir : true, - dirs: args.dirs !== null ? args.dir : true, - mime_type: (args.mime_type === null ? new RegExp(".+","i") : - (args.mime_type instanceof RegExp ? args.mime_type : - new RegExp( (args.mime_type.indexOf('/') >= 0 ? args.mime_type : args.mime_type + "/.+" ), "i" ))) - }; - - if(cb == null){ - cb = args - } - + self = this; // // Remark: REQUEST_CONCURRENCY_DELAY represents the millisecond, // delay between outgoing requests to dropbox @@ -212,28 +206,28 @@ exports.app = function(config){ // // If we have found any contents on this level of the folder // - if (reply !== null && reply.contents) { + if (reply.contents) { reply.contents.forEach(function (item) { // // Add the item into our results array (details or path) // - if ((item.is_dir && opts.dirs) || (!item.is_dir && opts.files && opts.mime_type.test(item.mime_type))) results.push(item); + results.push(options.details ? item : item.path); // // If we have encountered another folder, we can recurse on it // - if (item.is_dir) load(item.path); + if (item.is_dir && options.recursive) { + load(item.path); + } }); - } else { - errors++; } callbacks--; if (callbacks === 0) { - cb(errors, results); + callback(status, results); } }); }, REQUEST_CONCURRENCY_DELAY) } - load(path); + load(path, results); }, revisions: function(path, args, cb){ @@ -495,4 +489,3 @@ exports.app = function(config){ } } -