fixing screenshot previews in admin/themes

v1.18.x
Julian Lam 11 years ago
parent 1a415b60be
commit e4c62200de

@ -73,7 +73,7 @@ define(function() {
if (themes.length > 0) {
for (var x = 0, numThemes = themes.length; x < numThemes; x++) {
liEl.setAttribute('data-theme', themes[x].id);
liEl.innerHTML = '<img src="' + themes[x].screenshot + '" />' +
liEl.innerHTML = '<img src="' + (themes[x].screenshot ? '/css/previews/' + themes[x].id : RELATIVE_PATH + '/images/themes/default.png') + '" />' +
'<div>' +
'<div class="pull-right">' +
'<button class="btn btn-primary" data-action="use">Use</button> ' +

@ -80,20 +80,9 @@ var utils = require('./../public/src/utils.js'),
if (fs.existsSync(config)) {
fs.readFile(config, function (err, file) {
var configObj = JSON.parse(file.toString());
if (configObj.staticDir && configObj.screenshot) {
// Verify that the provided path leads to a file that exists
fs.exists(path.join(__dirname, '../node_modules/', configObj.id, configObj.staticDir, configObj.screenshot), function(exists) {
if (exists) {
configObj.screenshot = path.join('/css/assets/', configObj.screenshot);
} else {
configObj.screenshot = nconf.get('relative_path') + '/images/themes/default.png';
}
next(err, configObj);
});
} else {
configObj.screenshot = nconf.get('relative_path') + '/images/themes/default.png';
if (err) return next();
else {
var configObj = JSON.parse(file.toString());
next(err, configObj);
}
});

@ -137,10 +137,10 @@ var express = require('express'),
app.use(function (req, res, next) {
nconf.set('https', req.secure);
res.locals.csrf_token = req.session._csrf;
// Disable framing
res.setHeader("X-Frame-Options", "DENY");
next();
});
@ -215,6 +215,26 @@ var express = require('express'),
next();
}
});
// Route paths to screenshots for installed themes
meta.themes.get(function(err, themes) {
var screenshotPath;
async.each(themes, function(themeObj, next) {
if (themeObj.screenshot) {
screenshotPath = path.join(__dirname, '../node_modules', themeObj.id, themeObj.screenshot);
fs.exists(screenshotPath, function(exists) {
if (exists) {
app.get('/css/previews/' + themeObj.id, function(req, res) {
res.sendfile(screenshotPath);
});
}
});
} else {
next(false);
}
});
});
}
], next);
},

Loading…
Cancel
Save