Move logging into ArchiveManager

GitOrigin-RevId: 71a28a0215c5f1a6975c9e2fcdcd476513df1cbc
This commit is contained in:
andrew rumble
2024-06-18 09:17:15 +01:00
committed by Copybot
parent c387e60a28
commit 1409e32010
3 changed files with 10 additions and 6 deletions

View File

@@ -1,4 +1,3 @@
const logger = require('@overleaf/logger')
const OutputFileArchiveManager = require('./OutputFileArchiveManager')
const { expressify } = require('@overleaf/promise-utils')
@@ -8,7 +7,6 @@ async function createOutputZip(req, res) {
user_id: userId,
build_id: buildId,
} = req.params
logger.debug({ projectId, userId, buildId }, 'Will create zip file')
const archive = await OutputFileArchiveManager.archiveFilesForBuild(
projectId,
@@ -16,10 +14,6 @@ async function createOutputZip(req, res) {
buildId
)
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)

View File

@@ -5,6 +5,7 @@ const Settings = require('@overleaf/settings')
const { open } = require('node:fs/promises')
const path = require('path')
const { NotFoundError } = require('./Errors')
const logger = require('@overleaf/logger')
// NOTE: Updating this list requires a corresponding change in
// * services/web/frontend/js/features/pdf-preview/util/file-list.js
@@ -22,10 +23,14 @@ function getContentDir(projectId, userId) {
module.exports = {
async archiveFilesForBuild(projectId, userId, build) {
logger.debug({ projectId, userId, build }, 'Will create zip file')
const validFiles = await this._getAllOutputFiles(projectId, userId, build)
const archive = archiver('zip')
archive.on('error', err => {
logger.warn({ err }, 'error emitted when creating output files archive')
})
const missingFiles = []
for (const file of validFiles) {

View File

@@ -32,6 +32,7 @@ describe('OutputFileArchiveManager', function () {
this.archive = {
append: sinon.stub(),
finalize: sinon.stub(),
on: sinon.stub(),
}
this.archiver = sinon.stub().returns(this.archive)
@@ -80,6 +81,10 @@ describe('OutputFileArchiveManager', function () {
sinon.assert.calledWith(this.archiver, 'zip')
})
it('listens to errors from the archive', function () {
sinon.assert.calledWith(this.archive.on, 'error', sinon.match.func)
})
it('adds all the output files to the archive', function () {
expect(this.archive.append.callCount).to.equal(4)
sinon.assert.calledWith(