sintaxi / dbox

NodeJS SDK for Dropbox API (THIS LIBRARY IS OBSOLETE!!)
514 stars 91 forks source link

Couple of fixes #86

Open radoslavpetranov opened 9 years ago

radoslavpetranov commented 9 years ago

Hi there,

Thank you for this great library. I'm using it on my windows dev machine and I couldn't get the readdir function to work. At first I was getting the following error:

var rx = RegExp("^" + scopePath, "i") SyntaxError: Invalid regular expression: /^\/: \ at end of pattern at new RegExp () at RegExp () at Object.parseJSON (f:\projects\test\node_modules\dbox\lib\helpers.j s:23:13) at Request._callback (f:\projects\test\node_modules\dbox\lib\dbox.js: 231:69) at Request.self.callback (f:\projects\test\node_modules\dbox\node_mod ules\request\main.js:119:22) ...

This was caused by some backslashes so in helpers.js I just replaced

var scopePath = path.join("/", scope)

with

var scopePath = path.join("/", scope).replace("\\", "/");

With this my server stopped crashing whenever I was running the readdir function but I still only got a status 400 and no reply from the function. Upon further inspection I realized you guys are using nodejs' path library to build URLs which works great on unix systems but doesn't work in windows because by default it will use the backslash. I tried doing .replace() again but that didn't work so I replaced

fullpath = path.join(obj.hostname)
fullpath = path.join(fullpath, obj.version || "1")
fullpath = path.join(fullpath, obj.action)
fullpath = path.join(fullpath, rootpath)
fullpath = path.join(fullpath, scopepath)
fullpath = path.join(fullpath, filepath)

with

var fullpath = [
    obj.hostname,
    obj.version || "1",
    obj.action,
    rootpath,
    scopepath,
    filepath
].join('/');

And with that the readdir function began working properly on windows as well.

Is there any chance these 2 fixes (or better ones) could make it into the repo so that we (windows devs) don't need to redo them after npm install / version changes / whatever?

Cheers and thanks for the great library!

radoslavpetranov commented 9 years ago

Oh and one more comment that wasn't mentioned (or at least I didn't see it) in the docs but may help someone: if you're still getting blank data and status 400 even after these changes, it means you probably setup your dropbox app to have permissions to all files in your dropbox instead only to the app folder. If you manually run the URL that dbox submits to the API you'll get

error: "App folder (sandbox) access attempt failed because this app is not configured to have an app folder. Should your access type be 'dropbox' instead?"

What this means, is that when you create your app in your code

var app   = dbox.app({
    "app_key": "aaaaaaaaaaaaaaaaaaaaaaa", 
    "app_secret": "bbbbbbbbbbbbbbbbbbb"
});

you need to also provide the root parameter and set that to 'dropbox' like so

var app   = dbox.app({
    "app_key": "aaaaaaaaaaaaaaaaaaaaaaa", 
    "app_secret": "bbbbbbbbbbbbbbbbbbb",
    root : 'dropbox'
});

Again, this is only needed if when creating your Dropbox app you picked the option giving you access to all files in your dropbox account. Hope this helps someone.