mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-15 10:16:12 +01:00
closes #2165
This commit is contained in:
@@ -116,7 +116,12 @@ define('admin/settings', ['uploader', 'sounds'], function(uploader, sounds) {
|
||||
fileSize: 0,
|
||||
showHelp: uploadBtn.attr('data-help') ? uploadBtn.attr('data-help') === 1 : undefined
|
||||
}, function(image) {
|
||||
$('#' + uploadBtn.attr('data-target')).val(image);
|
||||
// need to move these into template, ex data-callback
|
||||
if (ajaxify.currentPage === 'admin/general/sounds') {
|
||||
ajaxify.refresh();
|
||||
} else {
|
||||
$('#' + uploadBtn.attr('data-target')).val(image);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -93,6 +93,33 @@ uploadsController.uploadLogo = function(req, res, next) {
|
||||
upload('site-logo', req, res, next);
|
||||
};
|
||||
|
||||
uploadsController.uploadSound = function(req, res, next) {
|
||||
var uploadedFile = req.files.files[0];
|
||||
|
||||
file.saveFileToLocal(uploadedFile.name, 'sounds', uploadedFile.path, function(err) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
var soundsPath = path.join(__dirname, '../../../public/sounds'),
|
||||
filePath = path.join(__dirname, '../../../public/uploads/sounds', uploadedFile.name);
|
||||
|
||||
if (process.platform === 'win32') {
|
||||
fs.link(filePath, path.join(soundsPath, path.basename(filePath)));
|
||||
} else {
|
||||
fs.symlink(filePath, path.join(soundsPath, path.basename(filePath)), 'file');
|
||||
}
|
||||
|
||||
fs.unlink(uploadedFile.path, function(err) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
res.json([{}]);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
uploadsController.uploadDefaultAvatar = function(req, res, next) {
|
||||
upload('avatar-default', req, res, next);
|
||||
};
|
||||
@@ -131,7 +158,9 @@ function uploadImage(filename, folder, uploadedFile, req, res, next) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
res.json([{name: uploadedFile.name, url: image.url.startsWith('http') ? image.url : nconf.get('relative_path') + image.url}]);
|
||||
next();
|
||||
}
|
||||
|
||||
if (plugins.hasListeners('filter:uploadImage')) {
|
||||
|
||||
@@ -17,48 +17,7 @@ module.exports = function(Meta) {
|
||||
|
||||
Meta.sounds.init = function(callback) {
|
||||
if (nconf.get('isPrimary') === '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) {
|
||||
if (err) {
|
||||
winston.error('Could not initialise sound files:' + err.message);
|
||||
return;
|
||||
}
|
||||
|
||||
// Link paths
|
||||
async.each(filePaths, function(filePath, next) {
|
||||
if (process.platform === 'win32') {
|
||||
fs.link(filePath, path.join(soundsPath, path.basename(filePath)), next);
|
||||
} else {
|
||||
fs.symlink(filePath, path.join(soundsPath, path.basename(filePath)), 'file', next);
|
||||
}
|
||||
}, function(err) {
|
||||
if (!err) {
|
||||
winston.verbose('[sounds] Sounds OK');
|
||||
} else {
|
||||
winston.error('[sounds] Could not initialise sounds: ' + err.message);
|
||||
}
|
||||
|
||||
if (typeof callback === 'function') {
|
||||
callback();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
setupSounds(callback);
|
||||
} else {
|
||||
if (typeof callback === 'function') {
|
||||
callback();
|
||||
@@ -67,8 +26,16 @@ module.exports = function(Meta) {
|
||||
};
|
||||
|
||||
Meta.sounds.getFiles = function(callback) {
|
||||
// todo: Possibly move these into a bundled module?
|
||||
fs.readdir(path.join(__dirname, '../../public/sounds'), function(err, files) {
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
fs.readdir(path.join(__dirname, '../../public/sounds'), next);
|
||||
},
|
||||
function(sounds, next) {
|
||||
fs.readdir(path.join(__dirname, '../../public/uploads/sounds'), function(err, uploaded) {
|
||||
next(err, sounds.concat(uploaded));
|
||||
});
|
||||
}
|
||||
], function(err, files) {
|
||||
var localList = {};
|
||||
|
||||
if (err) {
|
||||
@@ -102,4 +69,60 @@ module.exports = function(Meta) {
|
||||
callback(null, sounds);
|
||||
});
|
||||
};
|
||||
|
||||
function setupSounds(callback) {
|
||||
var soundsPath = path.join(__dirname, '../../public/sounds');
|
||||
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
fs.readdir(path.join(__dirname, '../../public/uploads/sounds'), next);
|
||||
},
|
||||
function(uploaded, next) {
|
||||
uploaded = uploaded.map(function(filename) {
|
||||
return path.join(__dirname, '../../public/uploads/sounds', filename);
|
||||
});
|
||||
|
||||
plugins.fireHook('filter:sounds.get', uploaded, 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) {
|
||||
if (err) {
|
||||
winston.error('Could not initialise sound files:' + err.message);
|
||||
return;
|
||||
}
|
||||
|
||||
// Link paths
|
||||
async.each(filePaths, function(filePath, next) {
|
||||
if (process.platform === 'win32') {
|
||||
fs.link(filePath, path.join(soundsPath, path.basename(filePath)), next);
|
||||
} else {
|
||||
fs.symlink(filePath, path.join(soundsPath, path.basename(filePath)), 'file', next);
|
||||
}
|
||||
}, function(err) {
|
||||
if (!err) {
|
||||
winston.verbose('[sounds] Sounds OK');
|
||||
} else {
|
||||
winston.error('[sounds] Could not initialise sounds: ' + err.message);
|
||||
}
|
||||
|
||||
if (typeof callback === 'function') {
|
||||
callback();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
], callback);
|
||||
}
|
||||
};
|
||||
@@ -15,6 +15,7 @@ function apiRoutes(router, middleware, controllers) {
|
||||
router.post('/uploadfavicon', middlewares, controllers.admin.uploads.uploadFavicon);
|
||||
router.post('/uploadTouchIcon', middlewares, controllers.admin.uploads.uploadTouchIcon);
|
||||
router.post('/uploadlogo', middlewares, controllers.admin.uploads.uploadLogo);
|
||||
router.post('/upload/sound', middlewares, controllers.admin.uploads.uploadSound);
|
||||
router.post('/uploadDefaultAvatar', middlewares, controllers.admin.uploads.uploadDefaultAvatar);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,62 +1,82 @@
|
||||
<div class="sounds settings" class="row">
|
||||
<form role="form">
|
||||
<div class="row">
|
||||
<div class="col-sm-2 col-xs-12 settings-header">Notifications</div>
|
||||
<div class="col-sm-10 col-xs-12">
|
||||
<label for="notification">Notifications</label>
|
||||
<div class="row">
|
||||
<div class="form-group col-xs-9">
|
||||
<select class="form-control" id="notification" name="notification">
|
||||
<option value=""></option>
|
||||
<!-- BEGIN sounds -->
|
||||
<option value="{sounds.name}">{sounds.name}</option>
|
||||
<!-- END sounds -->
|
||||
</select>
|
||||
</div>
|
||||
<div class="btn-group col-xs-3">
|
||||
<button type="button" class="form-control btn btn-sm btn-default" data-action="play">Play <i class="fa fa-play"></i></button>
|
||||
<div class="col-xs-9">
|
||||
<form role="form">
|
||||
<div class="row">
|
||||
<div class="col-sm-2 col-xs-12 settings-header">Notifications</div>
|
||||
<div class="col-sm-10 col-xs-12">
|
||||
<label for="notification">Notifications</label>
|
||||
<div class="row">
|
||||
<div class="form-group col-xs-9">
|
||||
<select class="form-control" id="notification" name="notification">
|
||||
<option value=""></option>
|
||||
<!-- BEGIN sounds -->
|
||||
<option value="{sounds.name}">{sounds.name}</option>
|
||||
<!-- END sounds -->
|
||||
</select>
|
||||
</div>
|
||||
<div class="btn-group col-xs-3">
|
||||
<button type="button" class="form-control btn btn-sm btn-default" data-action="play">Play <i class="fa fa-play"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-2 col-xs-12 settings-header">Chat Messages</div>
|
||||
<div class="col-sm-10 col-xs-12">
|
||||
<label for="chat-incoming">Incoming Message</label>
|
||||
<div class="row">
|
||||
<div class="form-group col-xs-9">
|
||||
<select class="form-control" id="chat-incoming" name="chat-incoming">
|
||||
<option value=""></option>
|
||||
<!-- BEGIN sounds -->
|
||||
<option value="{sounds.name}">{sounds.name}</option>
|
||||
<!-- END sounds -->
|
||||
</select>
|
||||
<div class="row">
|
||||
<div class="col-sm-2 col-xs-12 settings-header">Chat Messages</div>
|
||||
<div class="col-sm-10 col-xs-12">
|
||||
<label for="chat-incoming">Incoming Message</label>
|
||||
<div class="row">
|
||||
<div class="form-group col-xs-9">
|
||||
<select class="form-control" id="chat-incoming" name="chat-incoming">
|
||||
<option value=""></option>
|
||||
<!-- BEGIN sounds -->
|
||||
<option value="{sounds.name}">{sounds.name}</option>
|
||||
<!-- END sounds -->
|
||||
</select>
|
||||
</div>
|
||||
<div class="btn-group col-xs-3">
|
||||
<button type="button" class="form-control btn btn-sm btn-default" data-action="play">Play <i class="fa fa-play"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="btn-group col-xs-3">
|
||||
<button type="button" class="form-control btn btn-sm btn-default" data-action="play">Play <i class="fa fa-play"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<label for="chat-outgoing">Outgoing Message</label>
|
||||
<div class="row">
|
||||
<div class="form-group col-xs-9">
|
||||
<select class="form-control" id="chat-outgoing" name="chat-outgoing">
|
||||
<option value=""></option>
|
||||
<!-- BEGIN sounds -->
|
||||
<option value="{sounds.name}">{sounds.name}</option>
|
||||
<!-- END sounds -->
|
||||
</select>
|
||||
</div>
|
||||
<div class="btn-group col-xs-3">
|
||||
<button type="button" class="form-control btn btn-sm btn-default" data-action="play">Play <i class="fa fa-play"></i></button>
|
||||
<label for="chat-outgoing">Outgoing Message</label>
|
||||
<div class="row">
|
||||
<div class="form-group col-xs-9">
|
||||
<select class="form-control" id="chat-outgoing" name="chat-outgoing">
|
||||
<option value=""></option>
|
||||
<!-- BEGIN sounds -->
|
||||
<option value="{sounds.name}">{sounds.name}</option>
|
||||
<!-- END sounds -->
|
||||
</select>
|
||||
</div>
|
||||
<div class="btn-group col-xs-3">
|
||||
<button type="button" class="form-control btn btn-sm btn-default" data-action="play">Play <i class="fa fa-play"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="col-xs-3">
|
||||
<div class="panel">
|
||||
<div class="panel-body">
|
||||
<div class="input-group">
|
||||
<span class="input-group-btn">
|
||||
<input data-action="upload" data-target="logoUrl" data-route="{config.relative_path}/api/admin/upload/sound" type="button" class="btn btn-default btn-block" value="Upload New Sound"></input>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button id="save" class="floating-button mdl-button mdl-js-button mdl-button--fab mdl-js-ripple-effect mdl-button--colored">
|
||||
<i class="material-icons">save</i>
|
||||
</button>
|
||||
|
||||
<script>
|
||||
require(['admin/settings'], function(Settings) {
|
||||
Settings.init();
|
||||
});
|
||||
</script>
|
||||
Reference in New Issue
Block a user