-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
87 lines (71 loc) · 2.43 KB
/
server.js
File metadata and controls
87 lines (71 loc) · 2.43 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
var express = require('express')
var path = require('path');
var fs = require('fs');
var app = express();
var firebase = require('firebase');
var archiver = require('archiver');
app.set('view engine', 'ejs');
app.use(express.static(__dirname));
app.get('/', function (req, res) {
res.render('pages/form');
});
app.get('/products', function(req, res) {
res.render('pages/products');
});
String.prototype.format = function() {
var s = this,
i = arguments.length;
while (i--) {
s = s.replace(new RegExp('\\{' + i + '\\}', 'gm'), arguments[i]);
}
return s;
};
var myFirebaseRef = new firebase("https://bankhackathon.firebaseio.com/");
var dataArray = "";
myFirebaseRef.on("value", function(snapshot) {
console.log("change detected");
var data = snapshot.val().items;
dataArray = Object.keys(data).map(function(k) { return data[k] });
}, function (errorObject) {
console.log("The read failed: " + errorObject.code);
});
function data() {
var retString = "";
for (i in dataArray) {
var item = dataArray[i];
var str = '[titles addObject:@"{0}"];\n\t[costs addObject:@"{1}"];\n\t[description addObject:@"{2}"];\n\t[images addObject:@"{3}"];'.format(item.Name, item.cost, item.Description, item.image.replace("data:image/jpeg;base64,","").replace("data:image/png;base64,",""));
retString += str;
}
return retString;
}
app.get('/submit', function (req, res) {
console.log('submit pressed');
var populationData = data()
fs.readFile("ItemsViewController.m", 'utf8', function (err,data) {
if (err) {
return console.log(err);
}
var result = data.replace(/\/\/string to be replaced/g, populationData);
fs.writeFile("App/SimplifySDKSampleApp/SimplifySDKSampleApp/ViewControllers/ItemsViewController.m", result, 'utf8', function (err) {
if (err) return console.log(err);
});
});
var archive = archiver.create('zip', {});
res.setHeader('Content-Type', 'application/zip');
res.attachment('App/SimplifySDKSampleApp.zip');
archive.on('error', function(err) {
res.status(500).send({error: err.message});
});
//on stream closed we can end the request
res.on('close', function() {
console.log('Archive wrote %d bytes', archive.pointer());
// return res.status(200).send('OK').end();
});
//this is the streaming magic
archive.pipe(res);
var directory = 'App';
archive.directory(directory);
archive.finalize();
});
app.listen(3141)
console.log('3141');