From ec11a744524a0600458ce5082d5a10c1aa80f7df Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Fri, 18 Aug 2023 14:05:06 +0200 Subject: [PATCH] Merge pull request #14408 from overleaf/jpa-server-pro-history-zip-name [web] fix file name for history zip download in Server Pro/CE GitOrigin-RevId: e51213c4758bf241f8291a67231169ad7d54d423 --- .../src/Features/History/HistoryController.js | 33 +++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/services/web/app/src/Features/History/HistoryController.js b/services/web/app/src/Features/History/HistoryController.js index 7a64fc8ef5..404f1938af 100644 --- a/services/web/app/src/Features/History/HistoryController.js +++ b/services/web/app/src/Features/History/HistoryController.js @@ -317,13 +317,34 @@ module.exports = HistoryController = { if (!Features.hasFeature('saas')) { const getReq = request({ ...options, method: 'get' }) - pipeline(getReq, res, function (err) { - // If the downstream request is cancelled, we get an - // ERR_STREAM_PREMATURE_CLOSE. - if (err && err.code !== 'ERR_STREAM_PREMATURE_CLOSE') { - logger.error({ url, err }, 'history API error') - next(err) + getReq.on('error', function (err) { + logger.warn({ err, v1ProjectId, version }, 'history zip download error') + res.sendStatus(500) + }) + getReq.on('response', function (response) { + const statusCode = response.statusCode + if (statusCode !== 200) { + logger.warn( + { v1ProjectId, version, statusCode }, + 'history zip download failed' + ) + if (statusCode === 404) { + res.sendStatus(404) + } else { + res.sendStatus(500) + } + return } + + prepareZipAttachment(res, `${name}.zip`) + pipeline(response, res, function (err) { + // If the downstream request is cancelled, we get an + // ERR_STREAM_PREMATURE_CLOSE. + if (err && err.code !== 'ERR_STREAM_PREMATURE_CLOSE') { + logger.error({ err, v1ProjectId, version }, 'history API error') + next(err) + } + }) }) return }