mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
parent
2956c2c247
commit
4fe7c9d7fc
4 changed files with 30 additions and 28 deletions
|
@ -6,7 +6,7 @@ const fs = require('fs-extra'),
|
|||
path = require('path'),
|
||||
config = require('../config'),
|
||||
common = require('../lib/common'),
|
||||
globalUtils = require('../utils'),
|
||||
validation = require('../data/validation'),
|
||||
localUtils = require('./utils'),
|
||||
customRedirectsMiddleware = require('../web/middleware/custom-redirects');
|
||||
|
||||
|
@ -77,7 +77,7 @@ redirectsAPI = {
|
|||
.then(function overrideFile() {
|
||||
return _private.readRedirectsFile(options.path)
|
||||
.then(function (content) {
|
||||
globalUtils.validateRedirects(content);
|
||||
validation.validateRedirects(content);
|
||||
return fs.writeFile(redirectsPath, JSON.stringify(content), 'utf-8');
|
||||
})
|
||||
.then(function () {
|
||||
|
|
|
@ -11,6 +11,7 @@ var schema = require('../schema').tables,
|
|||
validatePassword,
|
||||
validateSchema,
|
||||
validateSettings,
|
||||
validateRedirects,
|
||||
validate;
|
||||
|
||||
function assertString(input) {
|
||||
|
@ -329,10 +330,34 @@ validate = function validate(value, key, validations, tableName) {
|
|||
return validationErrors;
|
||||
};
|
||||
|
||||
/**
|
||||
* Redirects are file based at the moment, but they will live in the database in the future.
|
||||
* See V2 of https://github.com/TryGhost/Ghost/issues/7707.
|
||||
*/
|
||||
validateRedirects = function validateRedirects(redirects) {
|
||||
if (!_.isArray(redirects)) {
|
||||
throw new common.errors.ValidationError({
|
||||
message: common.i18n.t('errors.utils.redirectsWrongFormat'),
|
||||
help: 'https://docs.ghost.org/docs/redirects'
|
||||
});
|
||||
}
|
||||
|
||||
_.each(redirects, function (redirect) {
|
||||
if (!redirect.from || !redirect.to) {
|
||||
throw new common.errors.ValidationError({
|
||||
message: common.i18n.t('errors.utils.redirectsWrongFormat'),
|
||||
context: JSON.stringify(redirect),
|
||||
help: 'https://docs.ghost.org/docs/redirects'
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
validate: validate,
|
||||
validator: validator,
|
||||
validatePassword: validatePassword,
|
||||
validateSchema: validateSchema,
|
||||
validateSettings: validateSettings
|
||||
validateSettings: validateSettings,
|
||||
validateRedirects: validateRedirects
|
||||
};
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
var unidecode = require('unidecode'),
|
||||
_ = require('lodash'),
|
||||
common = require('../lib/common'),
|
||||
utils,
|
||||
getRandomInt;
|
||||
|
||||
|
@ -109,28 +108,6 @@ utils = {
|
|||
return base64String;
|
||||
},
|
||||
|
||||
/**
|
||||
* NOTE: No separate utils file, because redirects won't live forever in a JSON file, see V2 of https://github.com/TryGhost/Ghost/issues/7707
|
||||
*/
|
||||
validateRedirects: function validateRedirects(redirects) {
|
||||
if (!_.isArray(redirects)) {
|
||||
throw new common.errors.ValidationError({
|
||||
message: common.i18n.t('errors.utils.redirectsWrongFormat'),
|
||||
help: 'https://docs.ghost.org/docs/redirects'
|
||||
});
|
||||
}
|
||||
|
||||
_.each(redirects, function (redirect) {
|
||||
if (!redirect.from || !redirect.to) {
|
||||
throw new common.errors.ValidationError({
|
||||
message: common.i18n.t('errors.utils.redirectsWrongFormat'),
|
||||
context: JSON.stringify(redirect),
|
||||
help: 'https://docs.ghost.org/docs/redirects'
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
readCSV: require('./read-csv'),
|
||||
zipFolder: require('./zip-folder'),
|
||||
tokens: require('./tokens'),
|
||||
|
|
|
@ -6,7 +6,7 @@ var fs = require('fs-extra'),
|
|||
debug = require('ghost-ignition').debug('custom-redirects'),
|
||||
config = require('../../config'),
|
||||
common = require('../../lib/common'),
|
||||
globalUtils = require('../../utils'),
|
||||
validation = require('../../data/validation'),
|
||||
customRedirectsRouter,
|
||||
_private = {};
|
||||
|
||||
|
@ -18,7 +18,7 @@ _private.registerRoutes = function registerRoutes() {
|
|||
try {
|
||||
var redirects = fs.readFileSync(path.join(config.getContentPath('data'), 'redirects.json'), 'utf-8');
|
||||
redirects = JSON.parse(redirects);
|
||||
globalUtils.validateRedirects(redirects);
|
||||
validation.validateRedirects(redirects);
|
||||
|
||||
_.each(redirects, function (redirect) {
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue