2014-02-12 10:23:40 +00:00
updateMerger = require ( ' ./UpdateMerger ' )
logger = require ( ' logger-sharelatex ' )
projectLocator = require ( ' ../Project/ProjectLocator ' )
projectCreationHandler = require ( ' ../Project/ProjectCreationHandler ' )
projectDeleter = require ( ' ../Project/ProjectDeleter ' )
ProjectRootDocManager = require " ../Project/ProjectRootDocManager "
2014-10-27 14:39:20 +00:00
FileTypeManager = require ( ' ../Uploads/FileTypeManager ' )
2017-05-11 10:29:57 +00:00
CooldownManager = require ( ' ../Cooldown/CooldownManager ' )
Errors = require ( ' ../Errors/Errors ' )
2014-02-12 10:23:40 +00:00
commitMessage = " Before update from Dropbox "
module.exports =
2014-10-16 10:43:54 +00:00
newUpdate: (user_id, projectName, path, updateRequest, source, callback)->
2014-02-12 10:23:40 +00:00
getOrCreateProject = (cb)=>
projectLocator . findUsersProjectByName user_id , projectName , (err, project)=>
logger . log user_id : user_id , filePath : path , projectName : projectName , " handling new update from tpds "
if ! project ?
projectCreationHandler . createBlankProject user_id , projectName , (err, project)=>
# have a crack at setting the root doc after a while, on creation we won't have it yet, but should have
# been sent it it within 30 seconds
2014-10-15 13:11:02 +00:00
setTimeout ( -> ProjectRootDocManager . setRootDocAutomatically project . _id ) , @ _rootDocTimeoutLength
2014-02-12 10:23:40 +00:00
cb err , project
else
cb err , project
getOrCreateProject (err, project)->
2014-10-27 14:39:20 +00:00
return callback ( err ) if err ?
2017-05-11 10:29:57 +00:00
CooldownManager . isProjectOnCooldown project . _id , (err, projectIsOnCooldown) ->
return callback ( err ) if err ?
if projectIsOnCooldown
logger . log { projectId: project . _id } , " project is on cooldown, denying request "
return callback ( new Errors . TooManyRequestsError ( ' project on cooldown ' ) )
FileTypeManager . shouldIgnore path , (err, shouldIgnore)->
if shouldIgnore
return callback ( )
updateMerger . mergeUpdate user_id , project . _id , path , updateRequest , source , callback
2014-02-12 10:23:40 +00:00
2014-10-16 10:43:54 +00:00
deleteUpdate: (user_id, projectName, path, source, callback)->
2014-02-12 10:23:40 +00:00
logger . log user_id : user_id , filePath : path , " handling delete update from tpds "
projectLocator . findUsersProjectByName user_id , projectName , (err, project)->
if ! project ?
2014-03-12 23:37:10 +00:00
logger . log user_id : user_id , filePath : path , projectName : projectName , " project not found from tpds update, ignoring folder or project "
2014-02-12 10:23:40 +00:00
return callback ( )
if path == " / "
logger . log user_id : user_id , filePath : path , projectName : projectName , project_id : project . _id , " project found for delete update, path is root so marking project as deleted "
return projectDeleter . markAsDeletedByExternalSource project . _id , callback
else
2017-12-15 11:32:43 +00:00
updateMerger . deleteUpdate user_id , project . _id , path , source , (err)->
2014-05-27 11:56:23 +00:00
callback ( err )
2014-02-12 10:23:40 +00:00
_rootDocTimeoutLength : 30 * 1000