Skip to content

Commit 8e351e7

Browse files
committed
Add revision api
1 parent dbc126b commit 8e351e7

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

app.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,8 @@ app.get("/p/:shortid", response.showPublishSlide);
457457
app.get("/:noteId", response.showNote);
458458
//note actions
459459
app.get("/:noteId/:action", response.noteActions);
460+
//note actions with action id
461+
app.get("/:noteId/:action/:actionId", response.noteActions);
460462
// response not found if no any route matches
461463
app.get('*', function (req, res) {
462464
response.errorNotFound(res);

lib/response.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var shortId = require('shortid');
1010
var metaMarked = require('meta-marked');
1111
var querystring = require('querystring');
1212
var request = require('request');
13+
var moment = require('moment');
1314

1415
//core
1516
var config = require("./config.js");
@@ -322,6 +323,38 @@ function actionGist(req, res, note) {
322323
res.redirect("https://github.com/login/oauth/authorize?" + query);
323324
}
324325

326+
function actionRevision(req, res, note) {
327+
var actionId = req.params.actionId;
328+
if (actionId) {
329+
var time = moment(parseInt(actionId));
330+
if (time.isValid()) {
331+
models.Revision.getPatchedNoteRevisionByTime(note, time, function (err, content) {
332+
if (err) {
333+
logger.error(err);
334+
return response.errorInternalError(res);
335+
}
336+
if (!content) {
337+
return response.errorNotFound(res);
338+
}
339+
res.end(JSON.stringify(content));
340+
});
341+
} else {
342+
return response.errorNotFound(res);
343+
}
344+
} else {
345+
models.Revision.getNoteRevisions(note, function (err, data) {
346+
if (err) {
347+
logger.error(err);
348+
return response.errorInternalError(res);
349+
}
350+
var out = {
351+
revision: data
352+
};
353+
res.end(JSON.stringify(out));
354+
});
355+
}
356+
}
357+
325358
function noteActions(req, res, next) {
326359
var noteId = req.params.noteId;
327360
findNote(req, res, function (note) {
@@ -343,6 +376,9 @@ function noteActions(req, res, next) {
343376
case "gist":
344377
actionGist(req, res, note);
345378
break;
379+
case "revision":
380+
actionRevision(req, res, note);
381+
break;
346382
default:
347383
return res.redirect(config.serverurl + '/' + noteId);
348384
break;

0 commit comments

Comments
 (0)