2014-02-12 05:23:40 -05:00
|
|
|
logger = require "logger-sharelatex"
|
2017-04-03 11:18:30 -04:00
|
|
|
Metrics = require "metrics-sharelatex"
|
2018-02-15 07:18:43 -05:00
|
|
|
ProjectGetter = require('../Project/ProjectGetter')
|
2014-02-12 05:23:40 -05:00
|
|
|
ProjectZipStreamManager = require "./ProjectZipStreamManager"
|
|
|
|
DocumentUpdaterHandler = require "../DocumentUpdater/DocumentUpdaterHandler"
|
|
|
|
|
|
|
|
module.exports = ProjectDownloadsController =
|
|
|
|
downloadProject: (req, res, next) ->
|
|
|
|
project_id = req.params.Project_id
|
|
|
|
Metrics.inc "zip-downloads"
|
|
|
|
logger.log project_id: project_id, "downloading project"
|
|
|
|
DocumentUpdaterHandler.flushProjectToMongo project_id, (error)->
|
|
|
|
return next(error) if error?
|
2018-02-15 07:18:43 -05:00
|
|
|
ProjectGetter.getProject project_id, name: true, (error, project) ->
|
2014-02-12 05:23:40 -05:00
|
|
|
return next(error) if error?
|
|
|
|
ProjectZipStreamManager.createZipStreamForProject project_id, (error, stream) ->
|
|
|
|
return next(error) if error?
|
2017-04-12 11:00:02 -04:00
|
|
|
res.setContentDisposition(
|
|
|
|
'attachment',
|
|
|
|
{filename: "#{project.name}.zip"}
|
2014-02-12 05:23:40 -05:00
|
|
|
)
|
|
|
|
res.contentType('application/zip')
|
|
|
|
stream.pipe(res)
|
|
|
|
|
2014-06-18 11:37:18 -04:00
|
|
|
downloadMultipleProjects: (req, res, next) ->
|
|
|
|
project_ids = req.query.project_ids.split(",")
|
|
|
|
Metrics.inc "zip-downloads-multiple"
|
|
|
|
logger.log project_ids: project_ids, "downloading multiple projects"
|
|
|
|
DocumentUpdaterHandler.flushMultipleProjectsToMongo project_ids, (error) ->
|
|
|
|
return next(error) if error?
|
|
|
|
ProjectZipStreamManager.createZipStreamForMultipleProjects project_ids, (error, stream) ->
|
|
|
|
return next(error) if error?
|
2017-04-12 11:00:02 -04:00
|
|
|
res.setContentDisposition(
|
|
|
|
'attachment',
|
2018-09-24 11:33:54 -04:00
|
|
|
{filename: "Overleaf Projects (#{project_ids.length} items).zip"}
|
2014-06-18 11:37:18 -04:00
|
|
|
)
|
|
|
|
res.contentType('application/zip')
|
|
|
|
stream.pipe(res)
|
|
|
|
|
2014-02-12 05:23:40 -05:00
|
|
|
|