6e117e63fb
closes TryGhost/Support#426 refs TryGhost/gscan#106 needs TryGhost/gscan#107 GScan can return errors, which was not handled in our theme validator and caused Ghost to crash completely. GScan will now return an Ignition error when its not able to read the `.zip` file. e. g.: `{"errors":[{"message":"Failed to read zip file","context":"tife.zip","errorType":"ValidationError","errorDetails":"invalid relative path: ../tife/"}]}`
43 lines
1.4 KiB
JavaScript
43 lines
1.4 KiB
JavaScript
var Promise = require('bluebird'),
|
|
config = require('../../config'),
|
|
common = require('../../lib/common'),
|
|
checkTheme;
|
|
|
|
checkTheme = function checkTheme(theme, isZip) {
|
|
var checkPromise,
|
|
// gscan can slow down boot time if we require on boot, for now nest the require.
|
|
gscan = require('gscan');
|
|
|
|
if (isZip) {
|
|
checkPromise = gscan.checkZip(theme, {
|
|
keepExtractedDir: true
|
|
});
|
|
} else {
|
|
checkPromise = gscan.check(theme.path);
|
|
}
|
|
|
|
return checkPromise
|
|
.then(function resultHandler(checkedTheme) {
|
|
checkedTheme = gscan.format(checkedTheme, {
|
|
onlyFatalErrors: config.get('env') === 'production'
|
|
});
|
|
|
|
// CASE: production and no fatal errors
|
|
// CASE: development returns fatal and none fatal errors, theme is only invalid if fatal errors
|
|
if (!checkedTheme.results.error.length ||
|
|
config.get('env') === 'development' && !checkedTheme.results.hasFatalErrors) {
|
|
return checkedTheme;
|
|
}
|
|
|
|
return Promise.reject(new common.errors.ThemeValidationError({
|
|
message: common.i18n.t('errors.api.themes.invalidTheme'),
|
|
errorDetails: checkedTheme.results.error,
|
|
context: checkedTheme
|
|
}));
|
|
}).catch(function (error) {
|
|
return Promise.reject(error);
|
|
});
|
|
};
|
|
|
|
module.exports.check = checkTheme;
|