Add revision api
This commit is contained in:
parent
dbc126b156
commit
8e351e7e33
2 changed files with 38 additions and 0 deletions
2
app.js
2
app.js
|
@ -457,6 +457,8 @@ app.get("/p/:shortid", response.showPublishSlide);
|
||||||
app.get("/:noteId", response.showNote);
|
app.get("/:noteId", response.showNote);
|
||||||
//note actions
|
//note actions
|
||||||
app.get("/:noteId/:action", response.noteActions);
|
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
|
// response not found if no any route matches
|
||||||
app.get('*', function (req, res) {
|
app.get('*', function (req, res) {
|
||||||
response.errorNotFound(res);
|
response.errorNotFound(res);
|
||||||
|
|
|
@ -10,6 +10,7 @@ var shortId = require('shortid');
|
||||||
var metaMarked = require('meta-marked');
|
var metaMarked = require('meta-marked');
|
||||||
var querystring = require('querystring');
|
var querystring = require('querystring');
|
||||||
var request = require('request');
|
var request = require('request');
|
||||||
|
var moment = require('moment');
|
||||||
|
|
||||||
//core
|
//core
|
||||||
var config = require("./config.js");
|
var config = require("./config.js");
|
||||||
|
@ -322,6 +323,38 @@ function actionGist(req, res, note) {
|
||||||
res.redirect("https://github.com/login/oauth/authorize?" + query);
|
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) {
|
function noteActions(req, res, next) {
|
||||||
var noteId = req.params.noteId;
|
var noteId = req.params.noteId;
|
||||||
findNote(req, res, function (note) {
|
findNote(req, res, function (note) {
|
||||||
|
@ -343,6 +376,9 @@ function noteActions(req, res, next) {
|
||||||
case "gist":
|
case "gist":
|
||||||
actionGist(req, res, note);
|
actionGist(req, res, note);
|
||||||
break;
|
break;
|
||||||
|
case "revision":
|
||||||
|
actionRevision(req, res, note);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return res.redirect(config.serverurl + '/' + noteId);
|
return res.redirect(config.serverurl + '/' + noteId);
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue