mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-18 03:31:03 +01:00
closes #2165
This commit is contained in:
@@ -116,7 +116,12 @@ define('admin/settings', ['uploader', 'sounds'], function(uploader, sounds) {
|
|||||||
fileSize: 0,
|
fileSize: 0,
|
||||||
showHelp: uploadBtn.attr('data-help') ? uploadBtn.attr('data-help') === 1 : undefined
|
showHelp: uploadBtn.attr('data-help') ? uploadBtn.attr('data-help') === 1 : undefined
|
||||||
}, function(image) {
|
}, function(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);
|
$('#' + uploadBtn.attr('data-target')).val(image);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -93,6 +93,33 @@ uploadsController.uploadLogo = function(req, res, next) {
|
|||||||
upload('site-logo', 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) {
|
uploadsController.uploadDefaultAvatar = function(req, res, next) {
|
||||||
upload('avatar-default', req, res, next);
|
upload('avatar-default', req, res, next);
|
||||||
};
|
};
|
||||||
@@ -131,7 +158,9 @@ function uploadImage(filename, folder, uploadedFile, req, res, next) {
|
|||||||
if (err) {
|
if (err) {
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
res.json([{name: uploadedFile.name, url: image.url.startsWith('http') ? image.url : nconf.get('relative_path') + image.url}]);
|
res.json([{name: uploadedFile.name, url: image.url.startsWith('http') ? image.url : nconf.get('relative_path') + image.url}]);
|
||||||
|
next();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugins.hasListeners('filter:uploadImage')) {
|
if (plugins.hasListeners('filter:uploadImage')) {
|
||||||
|
|||||||
@@ -17,9 +17,72 @@ module.exports = function(Meta) {
|
|||||||
|
|
||||||
Meta.sounds.init = function(callback) {
|
Meta.sounds.init = function(callback) {
|
||||||
if (nconf.get('isPrimary') === 'true') {
|
if (nconf.get('isPrimary') === 'true') {
|
||||||
|
setupSounds(callback);
|
||||||
|
} else {
|
||||||
|
if (typeof callback === 'function') {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Meta.sounds.getFiles = function(callback) {
|
||||||
|
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) {
|
||||||
|
winston.error('Could not get local sound files:' + err.message);
|
||||||
|
console.log(err.stack);
|
||||||
|
return callback(null, []);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return proper paths
|
||||||
|
files.forEach(function(filename) {
|
||||||
|
localList[filename] = nconf.get('relative_path') + '/sounds/' + filename;
|
||||||
|
});
|
||||||
|
|
||||||
|
callback(null, localList);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
Meta.sounds.getMapping = function(callback) {
|
||||||
|
db.getObject('settings:sounds', function(err, sounds) {
|
||||||
|
if (err || !sounds) {
|
||||||
|
// Send default sounds
|
||||||
|
var defaults = {
|
||||||
|
'notification': 'notification.mp3',
|
||||||
|
'chat-incoming': 'waterdrop-high.mp3',
|
||||||
|
'chat-outgoing': undefined
|
||||||
|
};
|
||||||
|
|
||||||
|
return callback(null, defaults);
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(null, sounds);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
function setupSounds(callback) {
|
||||||
var soundsPath = path.join(__dirname, '../../public/sounds');
|
var soundsPath = path.join(__dirname, '../../public/sounds');
|
||||||
|
|
||||||
plugins.fireHook('filter:sounds.get', [], function(err, filePaths) {
|
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) {
|
if (err) {
|
||||||
winston.error('Could not initialise sound files:' + err.message);
|
winston.error('Could not initialise sound files:' + err.message);
|
||||||
return;
|
return;
|
||||||
@@ -59,47 +122,7 @@ module.exports = function(Meta) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
if (typeof callback === 'function') {
|
|
||||||
callback();
|
|
||||||
}
|
}
|
||||||
|
], callback);
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
Meta.sounds.getFiles = function(callback) {
|
|
||||||
// todo: Possibly move these into a bundled module?
|
|
||||||
fs.readdir(path.join(__dirname, '../../public/sounds'), function(err, files) {
|
|
||||||
var localList = {};
|
|
||||||
|
|
||||||
if (err) {
|
|
||||||
winston.error('Could not get local sound files:' + err.message);
|
|
||||||
console.log(err.stack);
|
|
||||||
return callback(null, []);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return proper paths
|
|
||||||
files.forEach(function(filename) {
|
|
||||||
localList[filename] = nconf.get('relative_path') + '/sounds/' + filename;
|
|
||||||
});
|
|
||||||
|
|
||||||
callback(null, localList);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
Meta.sounds.getMapping = function(callback) {
|
|
||||||
db.getObject('settings:sounds', function(err, sounds) {
|
|
||||||
if (err || !sounds) {
|
|
||||||
// Send default sounds
|
|
||||||
var defaults = {
|
|
||||||
'notification': 'notification.mp3',
|
|
||||||
'chat-incoming': 'waterdrop-high.mp3',
|
|
||||||
'chat-outgoing': undefined
|
|
||||||
};
|
|
||||||
|
|
||||||
return callback(null, defaults);
|
|
||||||
}
|
|
||||||
|
|
||||||
callback(null, sounds);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
@@ -15,6 +15,7 @@ function apiRoutes(router, middleware, controllers) {
|
|||||||
router.post('/uploadfavicon', middlewares, controllers.admin.uploads.uploadFavicon);
|
router.post('/uploadfavicon', middlewares, controllers.admin.uploads.uploadFavicon);
|
||||||
router.post('/uploadTouchIcon', middlewares, controllers.admin.uploads.uploadTouchIcon);
|
router.post('/uploadTouchIcon', middlewares, controllers.admin.uploads.uploadTouchIcon);
|
||||||
router.post('/uploadlogo', middlewares, controllers.admin.uploads.uploadLogo);
|
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);
|
router.post('/uploadDefaultAvatar', middlewares, controllers.admin.uploads.uploadDefaultAvatar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<div class="sounds settings" class="row">
|
<div class="sounds settings" class="row">
|
||||||
|
<div class="col-xs-9">
|
||||||
<form role="form">
|
<form role="form">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-2 col-xs-12 settings-header">Notifications</div>
|
<div class="col-sm-2 col-xs-12 settings-header">Notifications</div>
|
||||||
@@ -55,8 +56,27 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</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>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button id="save" class="floating-button mdl-button mdl-js-button mdl-button--fab mdl-js-ripple-effect mdl-button--colored">
|
<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>
|
<i class="material-icons">save</i>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
require(['admin/settings'], function(Settings) {
|
||||||
|
Settings.init();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
Reference in New Issue
Block a user