overleaf/services/web/app/coffee/Features/Uploads/ProjectUploadManager.coffee

31 lines
1.5 KiB
CoffeeScript
Raw Normal View History

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"
module.exports = ProjectUploadHandler =
createProjectFromZipArchive: (owner_id, name, zipPath, callback = (error, project) ->) ->
ProjectCreationHandler.createBlankProject owner_id, name, (error, project) =>
return callback(error) if error?
2016-02-23 11:46:14 -05: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?
ProjectRootDocManager.setRootDocAutomatically project._id, (error) ->
return callback(error) if error?
callback(error, project)
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?
ArchiveManager.findTopLevelDirectory destination, (error, topLevelDestination) ->
2014-02-12 05:23:40 -05:00
return callback(error) if error?
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()}")