added /check endpoint for documents

This commit is contained in:
Brian Gough 2015-12-09 14:57:04 +00:00
parent c51d249221
commit 2a7c33d7ca
3 changed files with 21 additions and 2 deletions

View file

@ -22,6 +22,8 @@ app.post "/project/:project_id/doc/:doc_id/flush", HttpController.flushDoc
app.get "/project/:project_id/doc/:doc_id/diff", HttpController.getDiff
app.get "/project/:project_id/doc/:doc_id/check", HttpController.checkDoc
app.get "/project/:project_id/updates", HttpController.getUpdates
app.post "/project/:project_id/flush", HttpController.flushProject

View file

@ -11,11 +11,13 @@ module.exports = DiffGenerator =
ConsistencyError: ConsistencyError
rewindUpdate: (content, update) ->
for op in update.op by -1
for op, i in update.op by -1
try
content = DiffGenerator.rewindOp content, op
catch e
if e instanceof ConsistencyError
if e instanceof ConsistencyError and i = update.op.length - 1
# catch known case where the last op in an array has been
# merged into a later op
logger.error {update, op: JSON.stringify(op)}, "marking op as broken"
op.broken = true
else

View file

@ -30,6 +30,21 @@ module.exports = HttpController =
return next(error) if error?
res.send 204
checkDoc: (req, res, next = (error) ->) ->
doc_id = req.params.doc_id
project_id = req.params.project_id
logger.log project_id: project_id, doc_id: doc_id, "checking doc history"
DiffManager.getDocumentBeforeVersion project_id, doc_id, 1, (error, document, rewoundUpdates) ->
return next(error) if error?
broken = []
for update in rewoundUpdates
for op in update.op when op.broken is true
broken.push op
if broken.length > 0
res.send broken
else
res.send 204
getDiff: (req, res, next = (error) ->) ->
doc_id = req.params.doc_id
project_id = req.params.project_id