diff options
Diffstat (limited to '')
-rw-r--r-- | app.js | 2 | ||||
-rw-r--r-- | lib/response.js | 36 |
2 files changed, 38 insertions, 0 deletions
@@ -457,6 +457,8 @@ app.get("/p/:shortid", response.showPublishSlide); app.get("/:noteId", response.showNote); //note actions app.get("/:noteId/:action", response.noteActions); +//note actions with action id +app.get("/:noteId/:action/:actionId", response.noteActions); // response not found if no any route matches app.get('*', function (req, res) { response.errorNotFound(res); diff --git a/lib/response.js b/lib/response.js index 873dfe4e..1ed3a5b0 100644 --- a/lib/response.js +++ b/lib/response.js @@ -10,6 +10,7 @@ var shortId = require('shortid'); var metaMarked = require('meta-marked'); var querystring = require('querystring'); var request = require('request'); +var moment = require('moment'); //core var config = require("./config.js"); @@ -322,6 +323,38 @@ function actionGist(req, res, note) { res.redirect("https://github.com/login/oauth/authorize?" + query); } +function actionRevision(req, res, note) { + var actionId = req.params.actionId; + if (actionId) { + var time = moment(parseInt(actionId)); + if (time.isValid()) { + models.Revision.getPatchedNoteRevisionByTime(note, time, function (err, content) { + if (err) { + logger.error(err); + return response.errorInternalError(res); + } + if (!content) { + return response.errorNotFound(res); + } + res.end(JSON.stringify(content)); + }); + } else { + return response.errorNotFound(res); + } + } else { + models.Revision.getNoteRevisions(note, function (err, data) { + if (err) { + logger.error(err); + return response.errorInternalError(res); + } + var out = { + revision: data + }; + res.end(JSON.stringify(out)); + }); + } +} + function noteActions(req, res, next) { var noteId = req.params.noteId; findNote(req, res, function (note) { @@ -343,6 +376,9 @@ function noteActions(req, res, next) { case "gist": actionGist(req, res, note); break; + case "revision": + actionRevision(req, res, note); + break; default: return res.redirect(config.serverurl + '/' + noteId); break; |