-
Notifications
You must be signed in to change notification settings - Fork 1
/
upload-volume-spans.js
executable file
·45 lines (37 loc) · 1.22 KB
/
upload-volume-spans.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env node
"use strict"
var fs = require('fs')
var Parse = require('parse').Parse
Parse.initialize("Dxi3BvGT3mHiDC7B1YjeEuiUQKtWIeQNofT5FIIx", "QG352rxcZvLrYeV4jOCsIZvM8mIeQyhvHzDNINAb")
var DocGeoSpansObject = Parse.Object.extend("DocGeoSpans")
var args = process.argv.slice(2)
function failure(op, error) {
console.log("Failure " + op + " " + error.message + " (" + error.code + ")")
}
function uploadSpans(file, aftercb) {
console.log("Reading " + file)
var vol = file.replace(/^(.*?)-(.*?).txt$/, '$2')
var user = file.replace(/^(.*?)-(.*?).txt$/, '$1')
var text = fs.readFileSync(file, 'utf8')
var base64 = Buffer(text).toString('base64')
var fileobj = new Parse.File(file, { base64: base64 })
fileobj.save().then(function() {
var spansObject = new DocGeoSpansObject()
return spansObject.save({"vol":vol, "spans":fileobj, "user":user})
}, function(error) {
failure("saving file", error)
}).then(function() {
aftercb()
}, function(error) {
failure("creating spans object", error)
})
}
function uploadSpansSeries(items) {
if (items.length > 0) {
var item = items[0]
uploadSpans(item, function() {
uploadSpansSeries(items.slice(1))
})
}
}
uploadSpansSeries(args)