commit
b4870654fc
@ -1,25 +1,53 @@
|
||||
'use strict';
|
||||
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
var async = require('async');
|
||||
|
||||
var file = require('../../file');
|
||||
|
||||
var themesController = {};
|
||||
|
||||
var defaultScreenshotPath = path.join(__dirname, '../../../public/images/themes/default.png');
|
||||
|
||||
themesController.get = function (req, res, next) {
|
||||
var themeDir = path.join(__dirname, '../../../node_modules/' + req.params.theme);
|
||||
file.exists(themeDir, function (err, exists) {
|
||||
if (err || !exists) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
var themeConfig = require(path.join(themeDir, 'theme.json'));
|
||||
var 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'));
|
||||
}
|
||||
});
|
||||
var themeDir = path.join(__dirname, '../../../node_modules', req.params.theme);
|
||||
var themeConfigPath = path.join(themeDir, 'theme.json');
|
||||
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
file.exists(themeConfigPath, function (err, exists) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
if (!exists) {
|
||||
return next(Error('invalid-data'));
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
},
|
||||
function (next) {
|
||||
fs.readFile(themeConfigPath, next);
|
||||
},
|
||||
function (themeConfig, next) {
|
||||
try {
|
||||
themeConfig = JSON.parse(themeConfig);
|
||||
next(null, themeConfig.screenshot ? path.join(themeDir, themeConfig.screenshot) : defaultScreenshotPath);
|
||||
} catch (e) {
|
||||
next(e);
|
||||
}
|
||||
},
|
||||
function (screenshotPath, next) {
|
||||
file.exists(screenshotPath, function (err, exists) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
res.sendFile(exists ? screenshotPath : defaultScreenshotPath);
|
||||
});
|
||||
},
|
||||
], next);
|
||||
};
|
||||
|
||||
module.exports = themesController;
|
||||
|
@ -0,0 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function () {
|
||||
var debugArg = process.execArgv.find(function (arg) {
|
||||
return /^--(debug|inspect)/.test(arg);
|
||||
});
|
||||
if (global.v8debug || debugArg) {
|
||||
debugArg = debugArg ? debugArg.split('=') : ['--debug', 5859];
|
||||
var num = parseInt(debugArg[1], 10) + 1;
|
||||
|
||||
return { execArgv: [debugArg[0] + '=' + num, '--nolazy'] };
|
||||
}
|
||||
|
||||
return { execArgv: [] };
|
||||
};
|
Loading…
Reference in New Issue