Node.js based forum software built for the modern web
closes #4831
Julian Lam55bcc28e0e5c
diff --git a/src/meta/css.js b/src/meta/css.jsindex 0250ae5b26..478acab284 100644--- a/src/meta/css.js+++ b/src/meta/css.js@@ -196,7 +196,7 @@ module.exports = function(Meta) {Meta.css[destination] = result.css;// Save the compiled CSS in public/ so things like nginx can serve it- if (nconf.get('isPrimary') === 'true') {+ if (nconf.get('isPrimary') === 'true' && (nconf.get('local-assets') === undefined || nconf.get('local-assets') !== false)) {return Meta.css.commitToFile(destination, function() {if (typeof callback === 'function') {callback(null, result.css);diff --git a/src/meta/js.js b/src/meta/js.jsindex b7585bbee8..0f4fd87c28 100644--- a/src/meta/js.js+++ b/src/meta/js.js@@ -154,6 +154,12 @@ module.exports = function(Meta) {winston.verbose('[meta/js] ' + target + ' minification complete');minifier.kill();+ function done() {+ if (typeof callback === 'function') {+ callback();+ }+ }+if (process.send && Meta.js.target['nodebb.min.js'] && Meta.js.target['acp.min.js']) {process.send({action: 'js-propagate',@@ -161,11 +167,12 @@ module.exports = function(Meta) {});}- Meta.js.commitToFile(target, function() {- if (typeof callback === 'function') {- callback();- }- });+ if (nconf.get('local-assets') === undefined || nconf.get('local-assets') !== false) {+ return Meta.js.commitToFile(target, done);+ } else {+ emitter.emit('meta:js.compiled');+ return done();+ }break;case 'error':diff --git a/src/meta/sounds.js b/src/meta/sounds.jsindex 4b85f681cb..c802458b14 100644--- a/src/meta/sounds.js+++ b/src/meta/sounds.js@@ -83,7 +83,9 @@ module.exports = function(Meta) {fs.readdir(path.join(__dirname, '../../public/uploads/sounds'), next);},function(uploaded, next) {- uploaded = uploaded.map(function(filename) {+ uploaded = uploaded.filter(function(filename) {+ return !filename.startsWith('.');+ }).map(function(filename) {return path.join(__dirname, '../../public/uploads/sounds', filename);});@@ -93,6 +95,21 @@ module.exports = function(Meta) {return;}+ if (nconf.get('local-assets') === false) {+ // Don't regenerate the public/sounds/ directory. Instead, create a mapping for the router to use+ Meta.sounds._filePathHash = filePaths.reduce(function(hash, filePath) {+ hash[path.basename(filePath)] = filePath;+ return hash;+ }, {});++ winston.verbose('[sounds] Sounds OK');+ if (typeof next === 'function') {+ return next();+ } else {+ return;+ }+ }+// Clear the sounds directoryasync.series([function(next) {@@ -121,8 +138,8 @@ module.exports = function(Meta) {winston.error('[sounds] Could not initialise sounds: ' + err.message);}- if (typeof callback === 'function') {- callback();+ if (typeof next === 'function') {+ next();}});});diff --git a/src/routes/meta.js b/src/routes/meta.jsindex a904fdb8b5..b459db2972 100644--- a/src/routes/meta.js+++ b/src/routes/meta.js@@ -1,6 +1,7 @@"use strict";var path = require('path');+var nconf = require('nconf');var meta = require('../meta');@@ -29,6 +30,16 @@ function sendACPStylesheet(req, res) {res.type('text/css').status(200).send(meta.css.acpCache);}+function sendSoundFile(req, res, next) {+ var resolved = meta.sounds._filePathHash[path.basename(req.path)];++ if (resolved) {+ res.status(200).sendFile(resolved);+ } else {+ next();+ }+}+module.exports = function(app, middleware, controllers) {app.get('/stylesheet.css', middleware.addExpiresHeaders, sendStylesheet);app.get('/admin.css', middleware.addExpiresHeaders, sendACPStylesheet);@@ -42,4 +53,8 @@ module.exports = function(app, middleware, controllers) {app.get('/robots.txt', controllers.robots);app.get('/manifest.json', controllers.manifest);app.get('/css/previews/:theme', controllers.admin.themes.get);++ if (nconf.get('local-assets') === false) {+ app.get('/sounds/*', middleware.addExpiresHeaders, sendSoundFile);+ }};