-
Notifications
You must be signed in to change notification settings - Fork 1
/
upload-volume-nespans.js
68 lines (57 loc) · 1.82 KB
/
upload-volume-nespans.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env node
"use strict"
var fs = require('fs')
var Parse = require('parse').Parse
Parse.initialize("Dxi3BvGT3mHiDC7B1YjeEuiUQKtWIeQNofT5FIIx", "QG352rxcZvLrYeV4jOCsIZvM8mIeQyhvHzDNINAb")
var NESpans= Parse.Object.extend("NESpans")
var args = process.argv.slice(2)
console.log(args)
function failure(op, error) {
console.log("Failure " + op + " " + error.message + " (" + error.code + ")")
}
function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds){
break;
}
}
}
function uploadVolume(file, aftercb) {
console.log("Reading " + file)
var vol = file.split('/').slice(-1)[0].split('.')[0].replace(/[^0-9]+/, '').replace(/[^0-9]+/,'').replace(/^0*/, '')
console.log(vol)
//var vol = file.replace(/^0*(.*?)\.txt\.joined.nespans$/, '$1')
console.log("Writing volume " + vol)
//var desc = fs.readFileSync(file + '.desc', 'utf8')
var users = ["Max Cadwalder"]
var text = fs.readFileSync(file, 'utf8')
var base64 = Buffer(text).toString('base64')
for (var i=0;i<users.length;i++) {
(function(user){
var fileobj = new Parse.File("NESpans-"+user +"-"+ vol + ".txt", { base64: base64 })
fileobj.save().then(function() {
var nesObject = new NESpans()
return nesObject.save({"vol":vol, "spans":fileobj, "user":user})
}, function(error) {
failure("saving file", error)
}).then(function() {
aftercb()
}, function(error) {
failure("creating volume object", error)
})
})(users[i])
}
}
function uploadVolumeSeries(items) {
if (items.length > 0) {
for (var i=0;i<items.length;i++){
var item = items[i]
console.log(items[i])
uploadVolume(item, function() {
sleep(2000);
})
}
}
}
uploadVolumeSeries(args)