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
This commit is contained in:
Jakob Ackermann 2023-08-18 14:05:06 +02:00 committed by Copybot
parent ebebcf5956
commit ec11a74452

View file

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