Merge pull request #3495 from overleaf/ae-prettier-2
Upgrade Prettier to v2 GitOrigin-RevId: 85aa3fa1acb6332c4f58c46165a43d1a51471f33
This commit is contained in:
@@ -26,7 +26,7 @@ module.exports = ProjectZipStreamManager = {
|
||||
// We'll build up a zip file that contains multiple zip files
|
||||
|
||||
if (callback == null) {
|
||||
callback = function(error, stream) {}
|
||||
callback = function (error, stream) {}
|
||||
}
|
||||
const archive = archiver('zip')
|
||||
archive.on('error', err =>
|
||||
@@ -41,38 +41,39 @@ module.exports = ProjectZipStreamManager = {
|
||||
for (let project_id of Array.from(project_ids || [])) {
|
||||
;(project_id =>
|
||||
jobs.push(callback =>
|
||||
ProjectGetter.getProject(project_id, { name: true }, function(
|
||||
error,
|
||||
project
|
||||
) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
logger.log(
|
||||
{ project_id, name: project.name },
|
||||
'appending project to zip stream'
|
||||
)
|
||||
return ProjectZipStreamManager.createZipStreamForProject(
|
||||
project_id,
|
||||
function(error, stream) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
archive.append(stream, { name: `${project.name}.zip` })
|
||||
return stream.on('end', function() {
|
||||
logger.log(
|
||||
{ project_id, name: project.name },
|
||||
'zip stream ended'
|
||||
)
|
||||
return callback()
|
||||
})
|
||||
ProjectGetter.getProject(
|
||||
project_id,
|
||||
{ name: true },
|
||||
function (error, project) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
)
|
||||
})
|
||||
logger.log(
|
||||
{ project_id, name: project.name },
|
||||
'appending project to zip stream'
|
||||
)
|
||||
return ProjectZipStreamManager.createZipStreamForProject(
|
||||
project_id,
|
||||
function (error, stream) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
archive.append(stream, { name: `${project.name}.zip` })
|
||||
return stream.on('end', function () {
|
||||
logger.log(
|
||||
{ project_id, name: project.name },
|
||||
'zip stream ended'
|
||||
)
|
||||
return callback()
|
||||
})
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
))(project_id)
|
||||
}
|
||||
|
||||
return async.series(jobs, function() {
|
||||
return async.series(jobs, function () {
|
||||
logger.log(
|
||||
{ project_ids },
|
||||
'finished creating zip stream of multiple projects'
|
||||
@@ -83,7 +84,7 @@ module.exports = ProjectZipStreamManager = {
|
||||
|
||||
createZipStreamForProject(project_id, callback) {
|
||||
if (callback == null) {
|
||||
callback = function(error, stream) {}
|
||||
callback = function (error, stream) {}
|
||||
}
|
||||
const archive = archiver('zip')
|
||||
// return stream immediately before we start adding things to it
|
||||
@@ -115,20 +116,20 @@ module.exports = ProjectZipStreamManager = {
|
||||
|
||||
addAllDocsToArchive(project_id, archive, callback) {
|
||||
if (callback == null) {
|
||||
callback = function(error) {}
|
||||
callback = function (error) {}
|
||||
}
|
||||
return ProjectEntityHandler.getAllDocs(project_id, function(error, docs) {
|
||||
return ProjectEntityHandler.getAllDocs(project_id, function (error, docs) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
const jobs = []
|
||||
for (let path in docs) {
|
||||
const doc = docs[path]
|
||||
;(function(path, doc) {
|
||||
;(function (path, doc) {
|
||||
if (path[0] === '/') {
|
||||
path = path.slice(1)
|
||||
}
|
||||
return jobs.push(function(callback) {
|
||||
return jobs.push(function (callback) {
|
||||
logger.log({ project_id }, 'Adding doc')
|
||||
archive.append(doc.lines.join('\n'), { name: path })
|
||||
return callback()
|
||||
@@ -141,37 +142,42 @@ module.exports = ProjectZipStreamManager = {
|
||||
|
||||
addAllFilesToArchive(project_id, archive, callback) {
|
||||
if (callback == null) {
|
||||
callback = function(error) {}
|
||||
callback = function (error) {}
|
||||
}
|
||||
return ProjectEntityHandler.getAllFiles(project_id, function(error, files) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
return ProjectEntityHandler.getAllFiles(
|
||||
project_id,
|
||||
function (error, files) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
const jobs = []
|
||||
for (let path in files) {
|
||||
const file = files[path]
|
||||
;((path, file) =>
|
||||
jobs.push(callback =>
|
||||
FileStoreHandler.getFileStream(
|
||||
project_id,
|
||||
file._id,
|
||||
{},
|
||||
function (error, stream) {
|
||||
if (error != null) {
|
||||
logger.warn(
|
||||
{ err: error, project_id, file_id: file._id },
|
||||
'something went wrong adding file to zip archive'
|
||||
)
|
||||
return callback(err)
|
||||
}
|
||||
if (path[0] === '/') {
|
||||
path = path.slice(1)
|
||||
}
|
||||
archive.append(stream, { name: path })
|
||||
return stream.on('end', () => callback())
|
||||
}
|
||||
)
|
||||
))(path, file)
|
||||
}
|
||||
return async.parallelLimit(jobs, 5, callback)
|
||||
}
|
||||
const jobs = []
|
||||
for (let path in files) {
|
||||
const file = files[path]
|
||||
;((path, file) =>
|
||||
jobs.push(callback =>
|
||||
FileStoreHandler.getFileStream(project_id, file._id, {}, function(
|
||||
error,
|
||||
stream
|
||||
) {
|
||||
if (error != null) {
|
||||
logger.warn(
|
||||
{ err: error, project_id, file_id: file._id },
|
||||
'something went wrong adding file to zip archive'
|
||||
)
|
||||
return callback(err)
|
||||
}
|
||||
if (path[0] === '/') {
|
||||
path = path.slice(1)
|
||||
}
|
||||
archive.append(stream, { name: path })
|
||||
return stream.on('end', () => callback())
|
||||
})
|
||||
))(path, file)
|
||||
}
|
||||
return async.parallelLimit(jobs, 5, callback)
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user