-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
111 lines (92 loc) · 2.96 KB
/
server.js
File metadata and controls
111 lines (92 loc) · 2.96 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//OPTIONS//
var thumbSize = "140"; //size of thumbnails in px to be displayed on the startPage
var port = "1337"; //the port which the server will start on. If port 80 then server must be run as root.
//END OPTIONS//
//****DO NOT EDIT BELOW****//
var express = require('express');
var http = require('http');
var socketIO = require('socket.io');
var process = require('child_process');
var path = require('path');
var fs = require('fs');
var im = require('imagemagick');
var tg = require('./thumbgen.js');
var log = require('./log.js').log;
var app = express();
function getListing(path, callback) {
process.exec("find '"+path+"' -type d -o -name '*.jpg' -maxdepth 1 | sort -V", function (error, stdout, stderr) {
var returnData = [], members = [], type = "", hasChild = "", instructions="";
fs.readFile(path.replace(/\\ /g," ") + "/instructions.txt", 'utf8', function (err,instructions) {
try {
if(path !== __dirname+"/www/Photos")
log("Client requested: " + path.replace(__dirname+"/www/Photos/",""));
var lsData = stdout.split("\n");
lsData.splice(0,1);
lsData.splice(lsData.length-1,1);
stepNumber = lsData[0].replace(__dirname+"/www/Photos","");
stepNumber = stepNumber.split("/");
stepNumber = stepNumber.length -1;
for(i in lsData){
var name = lsData[i].split("/");
var name = name[name.length -1];
var thumbpath = "null";
if(name.indexOf(".jpg") > -1)
var type = "picture";
else
var type = "directory";
path = lsData[i];
if(type == "picture")
thumbpath = __dirname+"/www/thumbs/"+name;
name = name.replace(".jpg","");
members.push({name:name,path:path,thumbpath:thumbpath});
}
if(instructions == null)
instructions = "Please see a staff member for help";
returnData.push({
step:stepNumber,
members:members,
type:type,
hasChild:"true",
instructions:instructions,
thumbSize:thumbSize,
wwwDir:__dirname+"/www/"
});
callback(returnData);
}
catch(err){
log(err);
returnData.push({
step:stepNumber,
members:members,
type:type,
hasChild:"false",
instructions:instructions,
thumbSize:thumbSize,
wwwDir:__dirname+"/www/"
});
callback(returnData);
}
});
});
}
app.use(express.static(path.join(__dirname, "www")));
app.get("/", function(req, res){
res.sendFile(__dirname, "www/index.html");
});
app.get("/log", function(req, res){
res.sendFile(__dirname+"/log.txt");
});
var server = http.createServer(app);
var io = socketIO.listen(server, {log: false});
io.sockets.on("connection", function(socket){
//console.log("A new connection was made");
socket.on('getData', function(path){
if(path.indexOf("/www/Photos") > -1)
getListing(path, function(data){socket.emit('returnData', data);})
});
socket.on('getPhotosPath', function(){
socket.emit('returnPhotosPath',__dirname+"/www/Photos");
});
});
server.listen(port);
log("Server started and listening on port "+port);