From b807be9699f1badc116cbf30d13777e245290239 Mon Sep 17 00:00:00 2001 From: Naz Date: Thu, 25 Nov 2021 14:49:06 +0400 Subject: [PATCH] Added JSDocs to redirects validator refs https://github.com/TryGhost/Toolbox/issues/139 - Makes the expected file formatting easier to reason about --- core/server/services/redirects/api.js | 2 +- core/server/services/redirects/validation.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/core/server/services/redirects/api.js b/core/server/services/redirects/api.js index 0abe0b6e87..05aa00cb25 100644 --- a/core/server/services/redirects/api.js +++ b/core/server/services/redirects/api.js @@ -217,7 +217,7 @@ class CustomRedirectsAPI { const redirectsFilePath = await this.getRedirectsFilePath(); if (redirectsFilePath) { - const backupRedirectsPath = getBackupRedirectsFilePath(redirectsFilePath); + const backupRedirectsPath = this.getBackupFilePath(redirectsFilePath); const backupExists = await fs.pathExists(backupRedirectsPath); if (backupExists) { diff --git a/core/server/services/redirects/validation.js b/core/server/services/redirects/validation.js index 98067da4f3..aaba74b0f7 100644 --- a/core/server/services/redirects/validation.js +++ b/core/server/services/redirects/validation.js @@ -7,9 +7,19 @@ const messages = { invalidRedirectsFromRegex: 'Incorrect RegEx in redirects file.', redirectsHelp: 'https://ghost.org/docs/themes/routing/#redirects' }; + +/** + * Redirect configuration object + * @typedef {Object} RedirectConfig + * @property {String} from - Defines the relative incoming URL or pattern (regex) + * @property {String} to - Defines where the incoming traffic should be redirected to, which can be a static URL, or a dynamic value using regex (example: "to": "/$1/") + * @property {boolean} [permanent] - Can be defined with true for a permanent HTTP 301 redirect, or false for a temporary HTTP 302 redirect + */ + /** * 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. + * @param {RedirectConfig[]} redirects */ const validate = (redirects) => { if (!_.isArray(redirects)) {