all files / src/controllers/admin/ themes.js

38.46% Statements 5/13
0% Branches 0/6
0% Functions 0/2
38.46% Lines 5/13
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25                                       
'use strict';
 
var path = require('path');
var file = require('../../file');
 
var themesController = {};
 
themesController.get = function(req, res, next) {
	var themeDir = path.join(__dirname, '../../../node_modules/' + req.params.theme);
	file.exists(themeDir, function(exists) {
		if (!exists) {
			return next();
		}
 
		var themeConfig = require(path.join(themeDir, 'theme.json')),
			screenshotPath = path.join(themeDir, themeConfig.screenshot);
		if (themeConfig.screenshot && file.existsSync(screenshotPath)) {
			res.sendFile(screenshotPath);
		} else {
			res.sendFile(path.join(__dirname, '../../../public/images/themes/default.png'));
		}
	});
};
 
module.exports = themesController;