This repository has been archived by the owner on Jul 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
app.js
86 lines (72 loc) · 2.39 KB
/
app.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
try {
process.setgid("prismabox");
}
catch (err) {
console.log("Setting Group failed");
}
try {
process.setuid("prismabox");
}
catch (err) {
console.log("Setting User failed");
}
/**
* Module dependencies.
*/
require("./logger").init();
var logger = require('./logger').logger;
/*logger.use(require('devnull/transports/stream'), {
stream: require('fs').createWriteStream('loggers.log')
});*/
var express = require('express')
, routes = require('./routes')
, formidable = require("formidable");
var config = require("./config");
var app = module.exports = express.createServer();
// Configuration
//var progressBars = {};
app.configure(function(){
app.use(function(req, res, next){
console.log(req.connection.remoteAddress);
if (req.url == '/api/soap/eyefilm/v1/upload') {
var form = new formidable.IncomingForm();
var startTime = new Date();
var old = 0;
console.log("Starting upload");
//We can't use progressbars because there are two files at the same time.
form.on('progress', function(received, expected) {
//console.log(this.requestHeader);
if(old != Math.round(received*100/expected) && Math.round(received*100/expected) % 10 == 0)
console.log(Math.round(received*100/expected));
old = Math.round(received*100/expected)
});
form.on('end', function() {
var timeTaken = (new Date().getTime() - startTime.getTime()) / 1000;
var kbs = ((req.headers['content-length']/1024)/timeTaken);
console.log(timeTaken + " - " + kbs + "kb/s");
// logger.log((req.headers['content-length']/1024) + " - "+ timeTaken + " (" + kbs + "kb/s)");
});
form.parse(req);
}
next();
});
app.set('views', __dirname + '/views');
app.register("html", require('ejs'));
app.set('view engine', 'html');
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(__dirname + '/public'));
});
app.configure('development', function(){
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
app.configure('production', function(){
app.use(express.errorHandler());
});
// Routes
app.get('/', routes.index);
app.post('/api/soap/eyefilm/v1', routes.soap);
app.post('/api/soap/eyefilm/v1/upload', routes.upload);
app.listen(59278);
console.log("The Node-Eyefi Server was successfully started and is listening.");