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

[web] pipe history zip download to history-v1 in CE/SP (#11362)

GitOrigin-RevId: 4ef181d1b79b3d0e2254af698defe0c2fa8c679f
Miguel Serrano 3 лет назад
Родитель
Сommit
b4e9bf3449

+ 13 - 2
services/web/app/src/Features/History/HistoryController.js

@@ -13,6 +13,7 @@ const ProjectEntityUpdateHandler = require('../Project/ProjectEntityUpdateHandle
 const RestoreManager = require('./RestoreManager')
 const RestoreManager = require('./RestoreManager')
 const { pipeline } = require('stream')
 const { pipeline } = require('stream')
 const { prepareZipAttachment } = require('../../infrastructure/Response')
 const { prepareZipAttachment } = require('../../infrastructure/Response')
+const Features = require('../../infrastructure/Features')
 
 
 module.exports = HistoryController = {
 module.exports = HistoryController = {
   selectHistoryApi(req, res, next) {
   selectHistoryApi(req, res, next) {
@@ -344,10 +345,20 @@ module.exports = HistoryController = {
         pass: settings.apis.v1_history.pass,
         pass: settings.apis.v1_history.pass,
       },
       },
       json: true,
       json: true,
-      method: 'post',
       url,
       url,
     }
     }
-    request(options, function (err, response, body) {
+
+    if (!Features.hasFeature('saas')) {
+      const getReq = request({ ...options, method: 'get' })
+      getReq.pipe(res)
+      getReq.on('error', function (err) {
+        logger.error({ url, err }, 'history API error')
+        next(err)
+      })
+      return
+    }
+
+    request({ ...options, method: 'post' }, function (err, response, body) {
       if (err) {
       if (err) {
         OError.tag(err, 'history API error', {
         OError.tag(err, 'history API error', {
           v1ProjectId,
           v1ProjectId,

+ 4 - 0
services/web/test/unit/src/History/HistoryControllerTests.js

@@ -34,6 +34,10 @@ describe('HistoryController', function () {
           (this.ProjectEntityUpdateHandler = {}),
           (this.ProjectEntityUpdateHandler = {}),
         '../User/UserGetter': (this.UserGetter = {}),
         '../User/UserGetter': (this.UserGetter = {}),
         './RestoreManager': (this.RestoreManager = {}),
         './RestoreManager': (this.RestoreManager = {}),
+        '../../infrastructure/Features': (this.Features = sinon
+          .stub()
+          .withArgs('saas')
+          .returns(true)),
       },
       },
     })
     })
     return (this.settings.apis = {
     return (this.settings.apis = {