Support scoped theme packages

This commit is contained in:
Peter Jaszkowiak
2018-06-09 16:26:28 -06:00
committed by Julian Lam
parent d656c65c9a
commit 70ff2d9b88
10 changed files with 98 additions and 29 deletions

View File

@@ -16,22 +16,26 @@ themesController.get = function (req, res, next) {
var screenshotPath;
async.waterfall([
function (next) {
file.exists(themeConfigPath, next);
},
function (exists, next) {
if (!exists) {
return next(Error('invalid-data'));
}
fs.readFile(themeConfigPath, 'utf8', function (err, config) {
if (err) {
if (err.code === 'ENOENT') {
return next(Error('invalid-data'));
}
fs.readFile(themeConfigPath, 'utf8', next);
return next(err);
}
return next(null, config);
});
},
function (themeConfig, next) {
try {
themeConfig = JSON.parse(themeConfig);
next(null, themeConfig.screenshot ? path.join(themeDir, themeConfig.screenshot) : defaultScreenshotPath);
} catch (e) {
next(e);
return next(e);
}
next(null, themeConfig.screenshot ? path.join(themeDir, themeConfig.screenshot) : defaultScreenshotPath);
},
function (_screenshotPath, next) {
screenshotPath = _screenshotPath;