forked from bachy/banc-bi-js
/
router.js
129 lines (107 loc) · 3 KB
/
router.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
var _ = require("underscore");
var url = require('url')
var fs = require('fs');
module.exports = function(app,io,m){
/**
* routing event
*/
app.get("/", getIndex);
app.get("/editor/:session", getEditor);
app.get("/capture/:session/:column", getCapture);
app.get("/redaction/:session", getRedaction);
app.get("/feedback/:session", getFeedback);
app.get("/live/:session", getLive);
app.get("/admin", getAdmin);
//POST
app.post("/newSession", postNewSession);
/**
* routing functions
*/
// GET
function getIndex(req, res) {
res.render("index", {title : "museo", sessions:m.getSessionsList()});
};
function getEditor(req, res) {
var session = req.param('session');
res.render("editor", {
title : "Prise de notes",
session : session,
notes: m.getNotesList(session),
images:m.getImages(session)
});
};
function getCapture(req, res) {
var session = req.param('session');
var column = req.param('column');
res.render("capture", {
title : "Modelage / prise de vue",
session : session,
column : column,
notes: m.getNotesList(session)
});
};
function getRedaction(req, res) {
var session = req.param('session');
res.render("redaction", {
title : "Éditeur",
session : session,
lines: m.getRecordedSessionLines(session),
images:m.getImages(session)
});
};
function getFeedback(req, res) {
var session = req.param('session');
res.render("feedback", {
title : "Lecture",
session : session,
lines: m.getRecordedSessionLines(session),
images:m.getImages(session)
});
};
function getLive(req, res) {
var session = req.param('session');
res.render("live", {
title : "live",
session : session,
lines: m.getRecordedSessionLines(session),
images: m.getImages(session)
});
};
function getAdmin(req, res) {
res.render("admin", {pageData: {title : "Admin"}});
};
/* POST */
function postNewSession(req, res){
console.log('postNewSession');
var newsesspath = 'sessions/'+req.body.name;
// var fstat = fs.statSync(newsesspath);
// if(!fstat.isDirectory()){
fs.mkdir(newsesspath, function(){
// create csv file for record
var data_fd = fs.openSync(newsesspath+'/data.json', 'w+');
fs.writeSync(data_fd, JSON.stringify([]));
fs.close(data_fd);
// create sub folders for images
for (var i = 3; i > 0; i--) {
fs.mkdir(newsesspath+'/0'+i);
};
});
res.json(200, {message: "New Session created"});
// }else{
// res.json(200, {message: "Session already exists"});
// }
};
/**
* helpers
*/
function decodeBase64Image(dataString) {
var matches = dataString.match(/^data:([A-Za-z-+\/]+);base64,(.+)$/),
res = {};
if (matches.length !== 3) {
return new Error('Invalid input string');
}
res.type = matches[1];
res.data = new Buffer(matches[2], 'base64');
return res;
};
};