2014-02-12 05:23:40 -05:00
|
|
|
path = require "path"
|
|
|
|
rimraf = require "rimraf"
|
|
|
|
ArchiveManager = require "./ArchiveManager"
|
|
|
|
FileSystemImportManager = require "./FileSystemImportManager"
|
|
|
|
ProjectCreationHandler = require "../Project/ProjectCreationHandler"
|
|
|
|
ProjectRootDocManager = require "../Project/ProjectRootDocManager"
|
2018-10-12 07:29:37 -04:00
|
|
|
ProjectDetailsHandler = require "../Project/ProjectDetailsHandler"
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
module.exports = ProjectUploadHandler =
|
2018-10-12 07:29:37 -04:00
|
|
|
createProjectFromZipArchive: (owner_id, proposedName, zipPath, callback = (error, project) ->) ->
|
|
|
|
ProjectDetailsHandler.generateUniqueName owner_id, proposedName, (error, name) =>
|
2014-02-12 05:23:40 -05:00
|
|
|
return callback(error) if error?
|
2018-10-12 07:29:37 -04:00
|
|
|
ProjectCreationHandler.createBlankProject owner_id, name, (error, project) =>
|
2014-02-12 05:23:40 -05:00
|
|
|
return callback(error) if error?
|
2018-10-12 07:29:37 -04:00
|
|
|
@insertZipArchiveIntoFolder owner_id, project._id, project.rootFolder[0]._id, zipPath, (error) ->
|
2014-02-12 05:23:40 -05:00
|
|
|
return callback(error) if error?
|
2018-10-12 07:29:37 -04:00
|
|
|
ProjectRootDocManager.setRootDocAutomatically project._id, (error) ->
|
|
|
|
return callback(error) if error?
|
|
|
|
callback(error, project)
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2016-02-23 11:46:14 -05:00
|
|
|
insertZipArchiveIntoFolder: (owner_id, project_id, folder_id, path, callback = (error) ->) ->
|
2014-02-12 05:23:40 -05:00
|
|
|
destination = @_getDestinationDirectory path
|
|
|
|
ArchiveManager.extractZipArchive path, destination, (error) ->
|
|
|
|
return callback(error) if error?
|
2016-02-24 12:21:20 -05:00
|
|
|
ArchiveManager.findTopLevelDirectory destination, (error, topLevelDestination) ->
|
2014-02-12 05:23:40 -05:00
|
|
|
return callback(error) if error?
|
2016-02-24 12:21:20 -05:00
|
|
|
FileSystemImportManager.addFolderContents owner_id, project_id, folder_id, topLevelDestination, false, (error) ->
|
|
|
|
return callback(error) if error?
|
|
|
|
rimraf(destination, callback)
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
_getDestinationDirectory: (source) ->
|
|
|
|
return path.join(path.dirname(source), "#{path.basename(source, ".zip")}-#{Date.now()}")
|
|
|
|
|