v1.18.x
Julian Lam 10 years ago
parent b877a4e7b4
commit 632fb3a618

@ -1,6 +1,8 @@
"use strict";
var async = require('async'),
fs = require('fs'),
path = require('path'),
user = require('../user'),
categories = require('../categories'),
@ -32,6 +34,7 @@ var adminController = {
settings: {},
logger: {},
sounds: {},
themes: {},
users: require('./admin/users'),
uploads: require('./admin/uploads')
};
@ -297,4 +300,21 @@ adminController.sounds.get = function(req, res, next) {
});
};
adminController.themes.get = function(req, res, next) {
var themeDir = path.join(__dirname, '../../node_modules/' + req.params.theme);
fs.exists(themeDir, function(exists) {
if (exists) {
var themeConfig = require(path.join(themeDir, 'theme.json')),
screenshotPath = path.join(themeDir, themeConfig.screenshot);
if (themeConfig.screenshot && fs.existsSync(screenshotPath)) {
res.sendfile(screenshotPath);
} else {
res.sendfile(path.join(__dirname, '../../public/images/themes/default.png'));
}
} else {
return next();
}
});
}
module.exports = adminController;

@ -29,27 +29,6 @@ var utils = require('./../../public/src/utils'),
var middleware = {};
function routeThemeScreenshots(app, themes) {
var screenshotPath;
async.each(themes, function(themeObj, next) {
if (themeObj.screenshot) {
screenshotPath = path.join(themesPath, themeObj.id, themeObj.screenshot);
(function(id, path) {
fs.exists(path, function(exists) {
if (exists) {
app.get(relativePath + '/css/previews/' + id, function(req, res) {
res.sendfile(path);
});
}
});
})(themeObj.id, screenshotPath);
} else {
next(false);
}
});
}
function routeCurrentTheme(app, themeId, themesData) {
var themeId = (themeId || 'nodebb-theme-vanilla'),
themeObj = (function(id) {
@ -132,7 +111,6 @@ module.exports = function(app, data) {
auth.initialize(app, middleware);
routeCurrentTheme(app, data.currentThemeId, data.themesData);
routeThemeScreenshots(app, data.themesData);
meta.templates.compile();
return middleware;

@ -56,6 +56,7 @@ module.exports = function(app, middleware, controllers) {
app.get('/nodebb.min.js', middleware.addExpiresHeaders, sendMinifiedJS);
app.get('/sitemap.xml', controllers.sitemap);
app.get('/robots.txt', controllers.robots);
app.get('/css/previews/:theme', controllers.admin.themes.get);
if (!minificationEnabled) {
app.get('/nodebb.min.js.map', middleware.addExpiresHeaders, sendSourceMap);

Loading…
Cancel
Save