mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
added /check endpoint for documents
This commit is contained in:
parent
c51d249221
commit
2a7c33d7ca
3 changed files with 21 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue