mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-12 22:26:08 -04:00
Add revision api
This commit is contained in:
parent
dbc126b156
commit
8e351e7e33
2 changed files with 38 additions and 0 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue