2017-05-25 07:50:02 +02:00
|
|
|
module.exports = function(app) {
|
2017-05-25 09:59:22 +02:00
|
|
|
var http = require('http').Server(app);
|
|
|
|
var io = require('socket.io')(http);
|
|
|
|
var path = require('path');
|
2017-06-01 04:48:09 +02:00
|
|
|
var siofu = require("socketio-file-upload");
|
2017-06-03 05:56:33 +02:00
|
|
|
var socketHelpers = require('../helpers/socketHelpers.js');
|
2017-05-25 07:50:02 +02:00
|
|
|
|
|
|
|
io.on('connection', function(socket){
|
|
|
|
console.log('a user connected');
|
2017-06-03 05:56:33 +02:00
|
|
|
// attach upload listeners
|
2017-06-01 04:48:09 +02:00
|
|
|
var uploader = new siofu();
|
2017-06-01 05:29:16 +02:00
|
|
|
uploader.dir = path.join(__dirname, '../../Uploads');
|
2017-06-01 04:48:09 +02:00
|
|
|
uploader.listen(socket);
|
|
|
|
uploader.on("error", function(event){
|
|
|
|
console.log("an error occured while uploading", event.error);
|
|
|
|
socket.emit("publish-status", event.error)
|
2017-05-25 07:50:02 +02:00
|
|
|
})
|
2017-06-01 04:48:09 +02:00
|
|
|
uploader.on("saved", function(event){
|
|
|
|
console.log("saved " + event.file.name);
|
|
|
|
if (event.file.success){
|
|
|
|
socket.emit("publish-status", "file upload successfully completed");
|
2017-06-03 05:56:33 +02:00
|
|
|
socketHelpers.publish(event.file.meta.name, event.file.pathName, event.file.meta.license,event.file.meta.nsfw, socket)
|
2017-06-01 01:44:45 +02:00
|
|
|
} else {
|
2017-06-03 09:41:02 +02:00
|
|
|
socket.emit("publish-failure", "file uploaded, but with errors")
|
2017-06-01 04:48:09 +02:00
|
|
|
};
|
2017-06-01 01:44:45 +02:00
|
|
|
});
|
2017-05-25 07:50:02 +02:00
|
|
|
// handle disconnect
|
|
|
|
socket.on('disconnect', function(){
|
|
|
|
console.log('user disconnected');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return http;
|
|
|
|
}
|