2014-08-13 12:26:18 -04:00
|
|
|
logger = require("logger-sharelatex")
|
|
|
|
DropboxWebhookHandler = require("./DropboxWebhookHandler")
|
|
|
|
|
|
|
|
module.exports = DropboxWebhookController =
|
|
|
|
verify: (req, res, next = (error) ->) ->
|
|
|
|
res.send(req.query.challenge)
|
|
|
|
|
|
|
|
webhook: (req, res, next = (error) ->) ->
|
|
|
|
dropbox_uids = req.body?.delta?.users
|
|
|
|
logger.log dropbox_uids: dropbox_uids, "received webhook request from Dropbox"
|
|
|
|
if !dropbox_uids?
|
|
|
|
return res.send(400) # Bad Request
|
2014-08-14 08:48:23 -04:00
|
|
|
|
|
|
|
# Do this in the background so as not to keep Dropbox waiting
|
2014-08-13 12:26:18 -04:00
|
|
|
DropboxWebhookHandler.pollDropboxUids dropbox_uids, (error) ->
|
2014-08-14 08:48:23 -04:00
|
|
|
if error?
|
|
|
|
logger.error err: error, dropbox_uids: dropbox_uids, "error in webhook"
|
|
|
|
|
|
|
|
res.send(200)
|