|
|
|
@ -7,6 +7,7 @@ var path = require('path'),
|
|
|
|
|
rimraf = require('rimraf'),
|
|
|
|
|
mkdirp = require('mkdirp'),
|
|
|
|
|
async = require('async'),
|
|
|
|
|
cluster = require('cluster'),
|
|
|
|
|
|
|
|
|
|
plugins = require('../plugins'),
|
|
|
|
|
db = require('../database');
|
|
|
|
@ -15,41 +16,51 @@ module.exports = function(Meta) {
|
|
|
|
|
|
|
|
|
|
Meta.sounds = {};
|
|
|
|
|
|
|
|
|
|
Meta.sounds.init = function() {
|
|
|
|
|
var soundsPath = path.join(__dirname, '../../public/sounds');
|
|
|
|
|
Meta.sounds.init = function(callback) {
|
|
|
|
|
if (cluster.isWorker && process.env.cluster_setup === 'true') {
|
|
|
|
|
var soundsPath = path.join(__dirname, '../../public/sounds');
|
|
|
|
|
|
|
|
|
|
plugins.fireHook('filter:sounds.get', [], function(err, filePaths) {
|
|
|
|
|
if (err) {
|
|
|
|
|
winston.error('Could not initialise sound files:' + err.message);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Clear the sounds directory
|
|
|
|
|
async.series([
|
|
|
|
|
function(next) {
|
|
|
|
|
rimraf(soundsPath, next);
|
|
|
|
|
},
|
|
|
|
|
function(next) {
|
|
|
|
|
mkdirp(soundsPath, next);
|
|
|
|
|
}
|
|
|
|
|
], function(err) {
|
|
|
|
|
plugins.fireHook('filter:sounds.get', [], function(err, filePaths) {
|
|
|
|
|
if (err) {
|
|
|
|
|
winston.error('Could not initialise sound files:' + err.message);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Link paths
|
|
|
|
|
async.each(filePaths, function(filePath, next) {
|
|
|
|
|
fs[process.platform !== 'win32' ? 'symlink' : 'link'](filePath, path.join(soundsPath, path.basename(filePath)), 'file', next);
|
|
|
|
|
}, function(err) {
|
|
|
|
|
if (!err) {
|
|
|
|
|
winston.info('[sounds] Sounds OK');
|
|
|
|
|
} else {
|
|
|
|
|
winston.error('[sounds] Could not initialise sounds: ' + err.message);
|
|
|
|
|
// Clear the sounds directory
|
|
|
|
|
async.series([
|
|
|
|
|
function(next) {
|
|
|
|
|
rimraf(soundsPath, next);
|
|
|
|
|
},
|
|
|
|
|
function(next) {
|
|
|
|
|
mkdirp(soundsPath, next);
|
|
|
|
|
}
|
|
|
|
|
], function(err) {
|
|
|
|
|
if (err) {
|
|
|
|
|
winston.error('Could not initialise sound files:' + err.message);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Link paths
|
|
|
|
|
async.each(filePaths, function(filePath, next) {
|
|
|
|
|
fs[process.platform !== 'win32' ? 'symlink' : 'link'](filePath, path.join(soundsPath, path.basename(filePath)), 'file', next);
|
|
|
|
|
}, function(err) {
|
|
|
|
|
if (!err) {
|
|
|
|
|
winston.info('[sounds] Sounds OK');
|
|
|
|
|
} else {
|
|
|
|
|
winston.error('[sounds] Could not initialise sounds: ' + err.message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (typeof callback === 'function') {
|
|
|
|
|
callback();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
if (typeof callback === 'function') {
|
|
|
|
|
callback();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Meta.sounds.getFiles = function(callback) {
|
|
|
|
|