mirror of
https://github.com/overleaf/overleaf.git
synced 2024-10-31 21:21:03 -04:00
26 lines
No EOL
840 B
CoffeeScript
26 lines
No EOL
840 B
CoffeeScript
request = require "request"
|
|
settings = require "settings-sharelatex"
|
|
|
|
module.exports = HistoryManager =
|
|
initializeProject: (callback = (error, history_id) ->) ->
|
|
return callback() if !settings.apis.project_history?.initializeHistoryForNewProjects
|
|
request.post {
|
|
url: "#{settings.apis.project_history.url}/project"
|
|
}, (error, res, body)->
|
|
return callback(error) if error?
|
|
|
|
if res.statusCode >= 200 and res.statusCode < 300
|
|
try
|
|
project = JSON.parse(body)
|
|
catch error
|
|
return callback(error)
|
|
|
|
overleaf_id = project?.project?.id
|
|
if !overleaf_id
|
|
error = new Error("project-history did not provide an id", project)
|
|
return callback(error)
|
|
|
|
callback null, { overleaf_id }
|
|
else
|
|
error = new Error("project-history returned a non-success status code: #{res.statusCode}")
|
|
callback error |