-
Notifications
You must be signed in to change notification settings - Fork 4
/
server.js
69 lines (59 loc) · 1.78 KB
/
server.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
'use strict';
var
express = require('express'),
app = express(),
fs = require('fs'),
deployDir = __dirname + "/build/",
config = require(deployDir + "config.js"),
path = require('path'),
Encoder = require('./lib/encoder'),
encoder = new Encoder(),
sets = require("simplesets"),
uploadConf = {"uploadUrl":"/upload"};
app.set("port",config.port);
app.set("movieExtensions",new sets.Set(config.movieExtensions));
app.set("movieDir", deployDir + config.movieDir);
app.set("encodeDir", deployDir + config.encodeDir);
app.set("uploadDir", deployDir + 'uploads');
var
port = app.get("port") || 8080,
video = require('./routes/videos')(app),
encoding = require('./routes/encode')(app),
setup = require('./routes/setup')(app),
upload = require('./routes/upload')(app, uploadConf),
os = require("os");
app.set('view engine', 'jade');
app.set('views', deployDir + 'views');
app.enable('strict routing');
// use the static router
app.use(express.static(deployDir));
// Routes
app.get('/', function (req, res, next) {
video.getMovies(function(videos) {
encoding.getProcessing(function(processing) {
var out = {
"videos":videos.slice(0,10),
"processing":processing
};
res.render("index",out);
})
})
});
upload.on("end",function(fileInfo){
var uploadedFile = path.normalize( deployDir + "/uploads/" +fileInfo.name);
if(fileInfo.deleteUrl.match(uploadConf.uploadUrl + "-api"))
console.log("File uploaded via api");
else {
encodeVideo(uploadedFile, deployDir + "/videos");
}
});
var encodeVideo = function(file, outFile) {
var
handle = encoder.encode(file, outFile);
handle
.on("complete", function(){
fs.unlink(file);
});
}
app.listen(port);
console.log('Get to app at http://' + os.hostname() + ":" + port);