mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Add in /doc/<doc-id>/flush endpoint
This commit is contained in:
parent
65360a9a2b
commit
45fe6978af
3 changed files with 15 additions and 17 deletions
|
@ -6,14 +6,17 @@ HttpController = require "./app/js/HttpController"
|
|||
express = require "express"
|
||||
app = express()
|
||||
|
||||
app.post "/doc/:doc_id/history", express.bodyParser(), HttpController.appendUpdates
|
||||
app.post "/doc/:doc_id/flush", HttpController.flushUpdatesWithLock
|
||||
|
||||
app.use (error, req, res, next) ->
|
||||
logger.error err: error, "an internal error occured"
|
||||
req.send 500
|
||||
|
||||
app.listen (Settings.port ||= 3014), (error) ->
|
||||
port = Settings.internal?.history?.port or 3014
|
||||
host = Settings.internal?.history?.host or "localhost"
|
||||
app.listen port, host, (error) ->
|
||||
if error?
|
||||
logger.error err: error, "could not start history server"
|
||||
logger.log "history api listening on port 3014"
|
||||
else
|
||||
logger.log "history api listening on http://#{host}:#{port}"
|
||||
|
||||
|
|
|
@ -2,11 +2,9 @@ HistoryManager = require "./HistoryManager"
|
|||
logger = require "logger-sharelatex"
|
||||
|
||||
module.exports = HttpController =
|
||||
appendUpdates: (req, res, next = (error) ->) ->
|
||||
flushUpdatesWithLock: (req, res, next = (error) ->) ->
|
||||
doc_id = req.params.doc_id
|
||||
docOps = req.body.docOps
|
||||
version = req.body.version
|
||||
logger.log doc_id: doc_id, version: version, "compressing doc history"
|
||||
HistoryManager.compressAndSaveRawUpdates doc_id, docOps, (error) ->
|
||||
logger.log doc_id: doc_id, "compressing doc history"
|
||||
HistoryManager.processUncompressedUpdatesWithLock doc_id, (error) ->
|
||||
return next(error) if error?
|
||||
res.send 204
|
||||
|
|
|
@ -14,22 +14,19 @@ describe "HttpController", ->
|
|||
@version = 42
|
||||
@next = sinon.stub()
|
||||
|
||||
describe "appendUpdates", ->
|
||||
describe "flushUpdatesWithLock", ->
|
||||
beforeEach ->
|
||||
@req =
|
||||
params:
|
||||
doc_id: @doc_id
|
||||
body:
|
||||
docOps: @docOps = ["mock-ops"]
|
||||
version: @version
|
||||
@res =
|
||||
send: sinon.stub()
|
||||
@HistoryManager.compressAndSaveRawUpdates = sinon.stub().callsArg(2)
|
||||
@HttpController.appendUpdates @req, @res, @next
|
||||
@HistoryManager.processUncompressedUpdatesWithLock = sinon.stub().callsArg(1)
|
||||
@HttpController.flushUpdatesWithLock @req, @res, @next
|
||||
|
||||
it "should append the updates", ->
|
||||
@HistoryManager.compressAndSaveRawUpdates
|
||||
.calledWith(@doc_id, @docOps)
|
||||
it "should process the updates", ->
|
||||
@HistoryManager.processUncompressedUpdatesWithLock
|
||||
.calledWith(@doc_id)
|
||||
.should.equal true
|
||||
|
||||
it "should return a success code", ->
|
||||
|
|
Loading…
Reference in a new issue