mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-14 20:40:17 -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"
|
express = require "express"
|
||||||
app = 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) ->
|
app.use (error, req, res, next) ->
|
||||||
logger.error err: error, "an internal error occured"
|
logger.error err: error, "an internal error occured"
|
||||||
req.send 500
|
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?
|
if error?
|
||||||
logger.error err: error, "could not start history server"
|
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"
|
logger = require "logger-sharelatex"
|
||||||
|
|
||||||
module.exports = HttpController =
|
module.exports = HttpController =
|
||||||
appendUpdates: (req, res, next = (error) ->) ->
|
flushUpdatesWithLock: (req, res, next = (error) ->) ->
|
||||||
doc_id = req.params.doc_id
|
doc_id = req.params.doc_id
|
||||||
docOps = req.body.docOps
|
logger.log doc_id: doc_id, "compressing doc history"
|
||||||
version = req.body.version
|
HistoryManager.processUncompressedUpdatesWithLock doc_id, (error) ->
|
||||||
logger.log doc_id: doc_id, version: version, "compressing doc history"
|
|
||||||
HistoryManager.compressAndSaveRawUpdates doc_id, docOps, (error) ->
|
|
||||||
return next(error) if error?
|
return next(error) if error?
|
||||||
res.send 204
|
res.send 204
|
||||||
|
|
|
@ -14,22 +14,19 @@ describe "HttpController", ->
|
||||||
@version = 42
|
@version = 42
|
||||||
@next = sinon.stub()
|
@next = sinon.stub()
|
||||||
|
|
||||||
describe "appendUpdates", ->
|
describe "flushUpdatesWithLock", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@req =
|
@req =
|
||||||
params:
|
params:
|
||||||
doc_id: @doc_id
|
doc_id: @doc_id
|
||||||
body:
|
|
||||||
docOps: @docOps = ["mock-ops"]
|
|
||||||
version: @version
|
|
||||||
@res =
|
@res =
|
||||||
send: sinon.stub()
|
send: sinon.stub()
|
||||||
@HistoryManager.compressAndSaveRawUpdates = sinon.stub().callsArg(2)
|
@HistoryManager.processUncompressedUpdatesWithLock = sinon.stub().callsArg(1)
|
||||||
@HttpController.appendUpdates @req, @res, @next
|
@HttpController.flushUpdatesWithLock @req, @res, @next
|
||||||
|
|
||||||
it "should append the updates", ->
|
it "should process the updates", ->
|
||||||
@HistoryManager.compressAndSaveRawUpdates
|
@HistoryManager.processUncompressedUpdatesWithLock
|
||||||
.calledWith(@doc_id, @docOps)
|
.calledWith(@doc_id)
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
it "should return a success code", ->
|
it "should return a success code", ->
|
||||||
|
|
Loading…
Reference in a new issue