Просмотр исходного кода

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
Jakob Ackermann 3 лет назад
Родитель
Сommit
ec11a74452
1 измененных файлов с 27 добавлено и 6 удалено
  1. 27 6
      services/web/app/src/Features/History/HistoryController.js

+ 27 - 6
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
     }