overleaf/services/clsi/app/js/OutputController.js
Andrew Rumble 92f62f91c1 Merge pull request #18148 from overleaf/ar-add-output-zip-endpoint-to-clsi
[clsi] Add endpoints to get zip of output files

GitOrigin-RevId: a1a935e8170ab5a8d40baa6d96f8e42fe22c2e8c
2024-05-02 08:03:44 +00:00

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) }