overleaf/services/real-time/app/coffee/WebApiManager.coffee

25 lines
876 B
CoffeeScript
Raw Normal View History

2014-11-10 11:27:08 +00:00
request = require "request"
settings = require "settings-sharelatex"
logger = require "logger-sharelatex"
module.exports = WebApiManager =
joinProject: (project_id, user_id, callback = (error, project, privilegeLevel) ->) ->
logger.log {project_id, user_id}, "sending join project request to web"
url = "#{settings.apis.web.url}/project/#{project_id}/join"
request.post {
url: url
qs: {user_id}
2014-11-17 14:35:07 +00:00
auth:
user: settings.apis.web.user
pass: settings.apis.web.pass
sendImmediately: true
2014-11-10 11:27:08 +00:00
json: true
jar: false
}, (error, response, data) ->
return callback(error) if error?
if 200 <= response.statusCode < 300
callback null, data?.project, data?.privilegeLevel
else
err = new Error("non-success status code from web: #{response.statusCode}")
logger.error {err, project_id, user_id}, "error accessing web api"
callback err