spread2json
Advanced tools
Comparing version 0.3.2 to 0.3.3
@@ -11,2 +11,3 @@ /** | ||
var _ = require('lodash'); | ||
var async = require('async'); | ||
var googleapis = require('googleapis'); | ||
@@ -69,2 +70,4 @@ var xml2json = require('xml2json'); | ||
var BATCH_LIMIT = 40000; | ||
/** | ||
@@ -405,3 +408,3 @@ * xml escape | ||
var entryXML = _.map(entry, function(v) { | ||
var entryXmlList = _.map(entry, function(v) { | ||
return BATCH_TEMPLATE.ENTRY({ | ||
@@ -414,13 +417,34 @@ key: key, | ||
}); | ||
}).join(''); | ||
var opts = { | ||
uri: URLS.BATCH(key, worksheetId), | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/atom+xml', | ||
'If-Match': '*' | ||
}, | ||
body: BATCH_TEMPLATE.BODY({ key: key, worksheetId: worksheetId, entry: entryXML }) | ||
}; | ||
return this.request(opts, callback); | ||
}); | ||
if (entryXmlList.length < BATCH_LIMIT) { | ||
var opts = { | ||
uri: URLS.BATCH(key, worksheetId), | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/atom+xml', | ||
'If-Match': '*' | ||
}, | ||
body: BATCH_TEMPLATE.BODY({ key: key, worksheetId: worksheetId, entry: entryXmlList.join('') }) | ||
}; | ||
return this.request(opts, callback); | ||
} | ||
var self = this; | ||
var unit = Math.ceil(entryXmlList.length / BATCH_LIMIT); | ||
var splitEntryXmlList = _.times(unit, function() { | ||
return entryXmlList.splice(0, BATCH_LIMIT); | ||
}); | ||
async.eachSeries(splitEntryXmlList, function(list, next) { | ||
var opts = { | ||
uri: URLS.BATCH(key, worksheetId), | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/atom+xml', | ||
'If-Match': '*' | ||
}, | ||
body: BATCH_TEMPLATE.BODY({ key: key, worksheetId: worksheetId, entry: list.join('') }) | ||
}; | ||
self.request(opts, next); | ||
}, callback); | ||
}; |
{ | ||
"name": "spread2json", | ||
"version": "0.3.2", | ||
"version": "0.3.3", | ||
"description": "spreadsheet convert json", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
374418
10189