diff options
author | Cheng-Han, Wu | 2016-06-17 16:11:14 +0800 |
---|---|---|
committer | Cheng-Han, Wu | 2016-06-17 16:11:14 +0800 |
commit | 8e351e7e33774f9c4ad15b311f8c3a4725bacfdb (patch) | |
tree | a0a33bb2d7c3b5903d4a99f32d6b29b84839dc82 /lib | |
parent | dbc126b156f301c18d3963cd269dcd1eac040873 (diff) |
Add revision api
Diffstat (limited to '')
-rw-r--r-- | lib/response.js | 36 |
1 files changed, 36 insertions, 0 deletions
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; |