mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-25 17:41:03 +00:00
40 lines
No EOL
1.6 KiB
CoffeeScript
40 lines
No EOL
1.6 KiB
CoffeeScript
request = require "request"
|
|
logger = require "logger-sharelatex"
|
|
Settings = require "settings-sharelatex"
|
|
|
|
module.exports = DocumentUpdaterManager =
|
|
getDocument: (project_id, doc_id, callback = (error, content, version) ->) ->
|
|
url = "#{Settings.apis.documentupdater.url}/project/#{project_id}/doc/#{doc_id}"
|
|
logger.log project_id:project_id, doc_id: doc_id, "getting doc from document updater"
|
|
request.get url, (error, res, body)->
|
|
if error?
|
|
return callback(error)
|
|
if res.statusCode >= 200 and res.statusCode < 300
|
|
try
|
|
body = JSON.parse(body)
|
|
catch error
|
|
return callback(error)
|
|
callback null, body.lines.join("\n"), body.version
|
|
else
|
|
error = new Error("doc updater returned a non-success status code: #{res.statusCode}")
|
|
logger.error err: error, project_id:project_id, doc_id:doc_id, url: url, "error accessing doc updater"
|
|
callback error
|
|
|
|
setDocument: (project_id, doc_id, content, user_id, callback = (error) ->) ->
|
|
url = "#{Settings.apis.documentupdater.url}/project/#{project_id}/doc/#{doc_id}"
|
|
logger.log project_id:project_id, doc_id: doc_id, "setting doc in document updater"
|
|
request.post {
|
|
url: url
|
|
json:
|
|
lines: content.split("\n")
|
|
source: "restore"
|
|
user_id: user_id
|
|
}, (error, res, body)->
|
|
if error?
|
|
return callback(error)
|
|
if res.statusCode >= 200 and res.statusCode < 300
|
|
callback null
|
|
else
|
|
error = new Error("doc updater returned a non-success status code: #{res.statusCode}")
|
|
logger.error err: error, project_id:project_id, doc_id:doc_id, url: url, "error accessing doc updater"
|
|
callback error |