Files
overleaf-cep/services/clsi/app/js/OutputController.js
Jakob Ackermann 591b9f5d39 [clsi] adopt strict zod types and extend test coverage (#36090)
GitOrigin-RevId: ce11933ccc10ac74baf5c78cec194b5532a357a2
2026-09-17 11:47:13 +00:00

32 lines
1.0 KiB
JavaScript

import OutputFileArchiveManager from './OutputFileArchiveManager.js'
import { expressify } from '@overleaf/promise-utils'
import { pipeline } from 'node:stream/promises'
import { parseReq, z, zz } from '@overleaf/validation-tools'
// user_id is present only on the /project/:project_id/user/:user_id/build/...
// mount; this same handler is used for both routes.
const createOutputZipSchema = z.object({
params: z.strictObject({
project_id: zz.objectId().or(zz.submissionId()),
user_id: zz.objectId().optional(),
build_id: zz.buildId(),
}),
})
async function createOutputZip(req, res) {
const { params } = parseReq(req, createOutputZipSchema, { logOnly: true })
const { project_id: projectId, user_id: userId, build_id: buildId } = params
const archive = await OutputFileArchiveManager.archiveFilesForBuild(
projectId,
userId,
buildId
)
res.attachment('output.zip')
res.setHeader('X-Content-Type-Options', 'nosniff')
await pipeline(archive, res)
}
export default { createOutputZip: expressify(createOutputZip) }