Skip to content

Commit

Permalink
fixes up delta call
Browse files Browse the repository at this point in the history
  • Loading branch information
sintaxi committed Feb 27, 2013
1 parent 2b4a01c commit 512638f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 25 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
node_modules
test/config/sandbox/app.json
test/config/sandbox/access_token.json
test/config/full/app.json
test/config/full/access_token.json
test/config/dropbox/app.json
test/config/dropbox/access_token.json
tmp
*.swp
*.*~
Expand Down
15 changes: 9 additions & 6 deletions lib/dbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,24 @@ exports.app = function(config){
"url": "https://api.dropbox.com/1/delta",
"body": body
}

return request(opts, function(e, r, b){
var status = e ? null : r.statusCode
var output = helpers.parseJSON(b)
if(output.hasOwnProperty("entries")){


if(output && output.hasOwnProperty("entries")){
output["entries"].forEach(function(entry){
entries.push(entry)
})
})
}

if(output.hasOwnProperty("has_more")){
if(output && output.hasOwnProperty("has_more") && output.has_more == true){
args["cursor"] = output.cursor
fetch(args)
}else{
output["entries"] = entries
if(output){
output["entries"] = entries
}
// console.log("MADE IT:", status, output)
cb(status, output)
}
})
Expand Down
21 changes: 13 additions & 8 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ module.exports = function(config){
},

parseJSON: function(str) {
var rx = RegExp("^" + path.join("/", scope), "i")
var scopePath = path.join("/", scope)
var rx = RegExp("^" + scopePath, "i")

try {
var obj = JSON.parse(str)
Expand All @@ -40,24 +41,28 @@ module.exports = function(config){

// replace entries paths from delta call
if(obj.hasOwnProperty("entries") && obj["entries"].length){
var entries = []

var resultSet = []

for (var i = 0; i < obj["entries"].length; i++) {
// readdir
if(obj["entries"][i][0].match(rx)){
if(obj["entries"][i][0].match(rx) && obj["entries"][i][0] != scopePath){
var fpath = obj["entries"][i][0].replace(rx, "")
var entry = obj["entries"][i][1]
if(entry.hasOwnProperty("path")) entry.path = entry.path.replace(rx, "")
entries.push([ obj["entries"][i][0].replace(rx, ""), entry ])
if(entry && entry.hasOwnProperty("path")){
entry.path = entry.path.replace(rx, "")
}
// console.log("pushing", fpath, entry)
resultSet.push([ fpath, entry ])
}
}
obj['entries'] = entries

// console.log("resultSet..", resultSet)
obj['entries'] = resultSet
}

}

} catch (e) {
console.log("INVALID", e)
var obj = {}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"keywords": ["dropbox", "sdk", "s3"],
"main": "./lib/dbox.js",
"scripts": {
"test": "./node_modules/.bin/mocha -t 30000 test/all.js"
"test": "./node_modules/.bin/mocha -t 120000 test/all.js"
},
"repository": {
"type": "git",
Expand Down
14 changes: 6 additions & 8 deletions test/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,12 @@ describe("all", function(){
})
})

// it("should get delta results", function(done) {
// client.delta(function(status, reply){
// console.log("delta")
// console.log(reply)
// status.should.eql(200)
// done()
// })
// })
it("should get delta results", function(done) {
client.delta(function(status, reply){
status.should.eql(200)
done()
})
})

it("should remove renamed file", function(done) {
client.rm("myrenamedfile.txt", function(status, reply){
Expand Down

0 comments on commit 512638f

Please sign in to comment.