mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
92f62f91c1
[clsi] Add endpoints to get zip of output files GitOrigin-RevId: a1a935e8170ab5a8d40baa6d96f8e42fe22c2e8c
37 lines
986 B
JavaScript
37 lines
986 B
JavaScript
const logger = require('@overleaf/logger')
|
|
const OutputFileArchiveManager = require('./OutputFileArchiveManager')
|
|
const { expressify } = require('@overleaf/promise-utils')
|
|
|
|
function cleanFiles(files) {
|
|
if (!Array.isArray(files)) {
|
|
return []
|
|
}
|
|
return files.filter(file => /^output\./g.test(file))
|
|
}
|
|
|
|
async function createOutputZip(req, res) {
|
|
const {
|
|
project_id: projectId,
|
|
user_id: userId,
|
|
build_id: buildId,
|
|
} = req.params
|
|
const files = cleanFiles(req.query.files)
|
|
logger.debug({ projectId, userId, buildId, files }, 'Will create zip file')
|
|
|
|
const archive = await OutputFileArchiveManager.archiveFilesForBuild(
|
|
projectId,
|
|
userId,
|
|
buildId,
|
|
files
|
|
)
|
|
|
|
archive.on('error', err => {
|
|
logger.warn({ err }, 'error emitted when creating output files archive')
|
|
})
|
|
|
|
res.attachment('output.zip')
|
|
res.setHeader('X-Content-Type-Options', 'nosniff')
|
|
archive.pipe(res)
|
|
}
|
|
|
|
module.exports = { createOutputZip: expressify(createOutputZip) }
|