From 95c8f25fb56b0e39c8c6734a9c9489e763999044 Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Sat, 2 Jul 2016 16:11:30 +0800 Subject: [PATCH] Update response to force note, publish note, publish slide redirect to their expected url --- lib/response.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/response.js b/lib/response.js index a04b7176..2fc5d58d 100644 --- a/lib/response.js +++ b/lib/response.js @@ -188,6 +188,11 @@ function findNote(req, res, callback, include) { function showNote(req, res, next) { findNote(req, res, function (note) { + // force to use note id + var noteId = req.params.noteId; + var id = LZString.compressToBase64(note.id); + if ((note.alias && noteId != note.alias) || (!note.alias && noteId != id)) + return res.redirect(config.serverurl + "/" + (note.alias || id)); return responseHackMD(res, note); }); } @@ -201,6 +206,10 @@ function showPublishNote(req, res, next) { as: "lastchangeuser" }]; 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 + "/s/" + (note.alias || note.shortid)); note.increment('viewcount').then(function (note) { if (!note) { return response.errorNotFound(res); @@ -519,6 +528,10 @@ function gitlabActionProjects(req, res, note) { 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)); note.increment('viewcount').then(function (note) { if (!note) { return response.errorNotFound(res);