From 2411dffa2ce997370a636ed56cc73bcc4661ec7f Mon Sep 17 00:00:00 2001 From: Sheogorath Date: Wed, 7 Mar 2018 15:17:35 +0100 Subject: Change config to camel case with backwards compatibility This refactors the configs a bit to now use camel case everywhere. This change should help to clean up the config interface and make it better understandable. Signed-off-by: Sheogorath --- lib/response.js | 88 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 44 insertions(+), 44 deletions(-) (limited to 'lib/response.js') diff --git a/lib/response.js b/lib/response.js index 25b9fafc..b18fd7a3 100644 --- a/lib/response.js +++ b/lib/response.js @@ -44,22 +44,22 @@ var response = { } function responseError (res, code, detail, msg) { - res.status(code).render(config.errorpath, { - url: config.serverurl, + res.status(code).render(config.errorPath, { + url: config.serverURL, title: code + ' ' + detail + ' ' + msg, code: code, detail: detail, msg: msg, - useCDN: config.usecdn + useCDN: config.useCDN }) } function showIndex (req, res, next) { - res.render(config.indexpath, { - url: config.serverurl, - useCDN: config.usecdn, - allowAnonymous: config.allowanonymous, - allowAnonymousEdits: config.allowanonymousedits, + res.render(config.indexPath, { + url: config.serverURL, + useCDN: config.useCDN, + allowAnonymous: config.allowAnonymous, + allowAnonymousEdits: config.allowAnonymousedits, facebook: config.isFacebookEnable, twitter: config.isTwitterEnable, github: config.isGitHubEnable, @@ -71,8 +71,8 @@ function showIndex (req, res, next) { ldapProviderName: config.ldap.providerName, saml: config.isSAMLEnable, email: config.isEmailEnable, - allowemailregister: config.allowemailregister, - allowpdfexport: config.allowpdfexport, + allowEmailRegister: config.allowEmailRegister, + allowPDFExport: config.allowPDFExport, signin: req.isAuthenticated(), infoMessage: req.flash('info'), errorMessage: req.flash('error') @@ -89,12 +89,12 @@ function responseHackMD (res, note) { 'Cache-Control': 'private', // only cache by client 'X-Robots-Tag': 'noindex, nofollow' // prevent crawling }) - res.render(config.hackmdpath, { - url: config.serverurl, + res.render(config.hackmdPath, { + url: config.serverURL, title: title, - useCDN: config.usecdn, - allowAnonymous: config.allowanonymous, - allowAnonymousEdits: config.allowanonymousedits, + useCDN: config.useCDN, + allowAnonymous: config.allowAnonymous, + allowAnonymousEdits: config.allowAnonymousedits, facebook: config.isFacebookEnable, twitter: config.isTwitterEnable, github: config.isGitHubEnable, @@ -106,8 +106,8 @@ function responseHackMD (res, note) { ldapProviderName: config.ldap.providerName, saml: config.isSAMLEnable, email: config.isEmailEnable, - allowemailregister: config.allowemailregister, - allowpdfexport: config.allowpdfexport + allowEmailRegister: config.allowEmailRegister, + allowPDFExport: config.allowPDFExport }) } @@ -115,7 +115,7 @@ function newNote (req, res, next) { var owner = null if (req.isAuthenticated()) { owner = req.user.id - } else if (!config.allowanonymous) { + } else if (!config.allowAnonymous) { return response.errorForbidden(res) } models.Note.create({ @@ -123,7 +123,7 @@ function newNote (req, res, next) { alias: req.alias ? req.alias : null, content: req.body ? req.body : '' }).then(function (note) { - return res.redirect(config.serverurl + '/' + models.Note.encodeNoteId(note.id)) + return res.redirect(config.serverURL + '/' + models.Note.encodeNoteId(note.id)) }).catch(function (err) { logger.error(err) return response.errorInternalError(res) @@ -155,7 +155,7 @@ function findNote (req, res, callback, include) { include: include || null }).then(function (note) { if (!note) { - if (config.allowfreeurl && noteId) { + if (config.allowFreeURL && noteId) { req.alias = noteId return newNote(req, res) } else { @@ -179,7 +179,7 @@ function showNote (req, res, next) { // force to use note id var noteId = req.params.noteId var id = models.Note.encodeNoteId(note.id) - if ((note.alias && noteId !== note.alias) || (!note.alias && noteId !== id)) { return res.redirect(config.serverurl + '/' + (note.alias || id)) } + if ((note.alias && noteId !== note.alias) || (!note.alias && noteId !== id)) { return res.redirect(config.serverURL + '/' + (note.alias || id)) } return responseHackMD(res, note) }) } @@ -196,7 +196,7 @@ function showPublishNote (req, res, next) { // force to use short id var shortid = req.params.shortid if ((note.alias && shortid !== note.alias) || (!note.alias && shortid !== note.shortid)) { - return res.redirect(config.serverurl + '/s/' + (note.alias || note.shortid)) + return res.redirect(config.serverURL + '/s/' + (note.alias || note.shortid)) } note.increment('viewcount').then(function (note) { if (!note) { @@ -210,7 +210,7 @@ function showPublishNote (req, res, next) { var updatetime = note.lastchangeAt var title = models.Note.decodeTitle(note.title) title = models.Note.generateWebTitle(meta.title || title) - var origin = config.serverurl + var origin = config.serverURL var data = { title: title, description: meta.description || (markdown ? models.Note.generateDescription(markdown) : null), @@ -219,7 +219,7 @@ function showPublishNote (req, res, next) { updatetime: updatetime, url: origin, body: body, - useCDN: config.usecdn, + useCDN: config.useCDN, owner: note.owner ? note.owner.id : null, ownerprofile: note.owner ? models.User.getProfile(note.owner) : null, lastchangeuser: note.lastchangeuser ? note.lastchangeuser.id : null, @@ -240,15 +240,15 @@ function renderPublish (data, res) { res.set({ 'Cache-Control': 'private' // only cache by client }) - res.render(config.prettypath, data) + res.render(config.prettyPath, data) } function actionPublish (req, res, note) { - res.redirect(config.serverurl + '/s/' + (note.alias || note.shortid)) + res.redirect(config.serverURL + '/s/' + (note.alias || note.shortid)) } function actionSlide (req, res, note) { - res.redirect(config.serverurl + '/p/' + (note.alias || note.shortid)) + res.redirect(config.serverURL + '/p/' + (note.alias || note.shortid)) } function actionDownload (req, res, note) { @@ -298,10 +298,10 @@ function actionPDF (req, res, note) { var extracted = models.Note.extractMeta(body) var title = models.Note.decodeTitle(note.title) - if (!fs.existsSync(config.tmppath)) { - fs.mkdirSync(config.tmppath) + if (!fs.existsSync(config.tmpPath)) { + fs.mkdirSync(config.tmpPath) } - var path = config.tmppath + '/' + Date.now() + '.pdf' + var path = config.tmpPath + '/' + Date.now() + '.pdf' markdownpdf().from.string(extracted.markdown).to(path, function () { var stream = fs.createReadStream(path) var filename = title @@ -320,7 +320,7 @@ function actionPDF (req, res, note) { function actionGist (req, res, note) { var data = { client_id: config.github.clientID, - redirect_uri: config.serverurl + '/auth/github/callback/' + models.Note.encodeNoteId(note.id) + '/gist', + redirect_uri: config.serverURL + '/auth/github/callback/' + models.Note.encodeNoteId(note.id) + '/gist', scope: 'gist', state: shortId.generate() } @@ -393,10 +393,10 @@ function noteActions (req, res, next) { actionInfo(req, res, note) break case 'pdf': - if (config.allowpdfexport) { + if (config.allowPDFExport) { actionPDF(req, res, note) } else { - logger.error('PDF export failed: Disabled by config. Set "allowpdfexport: true" to enable. Check the documentation for details') + logger.error('PDF export failed: Disabled by config. Set "allowPDFExport: true" to enable. Check the documentation for details') response.errorForbidden(res) } break @@ -407,7 +407,7 @@ function noteActions (req, res, next) { actionRevision(req, res, note) break default: - return res.redirect(config.serverurl + '/' + noteId) + return res.redirect(config.serverURL + '/' + noteId) } }) } @@ -417,10 +417,10 @@ function publishNoteActions (req, res, next) { var action = req.params.action switch (action) { case 'edit': - res.redirect(config.serverurl + '/' + (note.alias ? note.alias : models.Note.encodeNoteId(note.id))) + res.redirect(config.serverURL + '/' + (note.alias ? note.alias : models.Note.encodeNoteId(note.id))) break default: - res.redirect(config.serverurl + '/s/' + note.shortid) + res.redirect(config.serverURL + '/s/' + note.shortid) break } }) @@ -431,10 +431,10 @@ function publishSlideActions (req, res, next) { var action = req.params.action switch (action) { case 'edit': - res.redirect(config.serverurl + '/' + (note.alias ? note.alias : models.Note.encodeNoteId(note.id))) + res.redirect(config.serverURL + '/' + (note.alias ? note.alias : models.Note.encodeNoteId(note.id))) break default: - res.redirect(config.serverurl + '/p/' + note.shortid) + res.redirect(config.serverURL + '/p/' + note.shortid) break } }) @@ -449,7 +449,7 @@ function githubActions (req, res, next) { githubActionGist(req, res, note) break default: - res.redirect(config.serverurl + '/' + noteId) + res.redirect(config.serverURL + '/' + noteId) break } }) @@ -521,7 +521,7 @@ function gitlabActions (req, res, next) { gitlabActionProjects(req, res, note) break default: - res.redirect(config.serverurl + '/' + noteId) + res.redirect(config.serverURL + '/' + noteId) break } }) @@ -569,7 +569,7 @@ function showPublishSlide (req, res, next) { findNote(req, res, function (note) { // force to use short id var shortid = req.params.shortid - if ((note.alias && shortid !== note.alias) || (!note.alias && shortid !== note.shortid)) { return res.redirect(config.serverurl + '/p/' + (note.alias || note.shortid)) } + if ((note.alias && shortid !== note.alias) || (!note.alias && shortid !== note.shortid)) { return res.redirect(config.serverURL + '/p/' + (note.alias || note.shortid)) } note.increment('viewcount').then(function (note) { if (!note) { return response.errorNotFound(res) @@ -582,7 +582,7 @@ function showPublishSlide (req, res, next) { var updatetime = note.lastchangeAt var title = models.Note.decodeTitle(note.title) title = models.Note.generateWebTitle(meta.title || title) - var origin = config.serverurl + var origin = config.serverURL var data = { title: title, description: meta.description || (markdown ? models.Note.generateDescription(markdown) : null), @@ -593,7 +593,7 @@ function showPublishSlide (req, res, next) { body: markdown, theme: meta.slideOptions && utils.isRevealTheme(meta.slideOptions.theme), meta: JSON.stringify(extracted.meta), - useCDN: config.usecdn, + useCDN: config.useCDN, owner: note.owner ? note.owner.id : null, ownerprofile: note.owner ? models.User.getProfile(note.owner) : null, lastchangeuser: note.lastchangeuser ? note.lastchangeuser.id : null, @@ -615,7 +615,7 @@ function renderPublishSlide (data, res) { res.set({ 'Cache-Control': 'private' // only cache by client }) - res.render(config.slidepath, data) + res.render(config.slidePath, data) } module.exports = response -- cgit v1.2.3