使用多次导入相同 collection 的按钮导入 collection - Postman

Import collection using button importing same collection multiple times - Postman

我正在使用 Postman 版本 6.6.0,并尝试通过 Run in Postman 按钮导入 API collection。我有一个 HTML 页面,看起来像:

<div id="hiddenEnv" class="nodisplay highlight highlight-attention">
   <p>
      Click the button below to import into Postman
   </p>
   <p>                        
   <div class="postman-run-button"
      data-postman-action="collection/import"
      data-postman-var-1="abcd"></div>
   <script type="text/javascript">
      (function (p,o,s,t,m,a,n) {
          !p[s] && (p[s] = function () { (p[t] || (p[t] = [])).push(arguments); });
          !o.getElementById(s+t) && o.getElementsByTagName("head")[0].appendChild((
            (n = o.createElement("script")),
            (n.id = s+t), (n.async = 1), (n.src = m), n
          ));
        }(window, document, "_pm", "PostmanRunObject", "https://run.pstmn.io/button.js"));
   </script>        
   </p>
</div>

和js代码:

$(function() {

    var lastEnv;

    function newEnv(name) {
        debugger;
        var env = {
            "id": generateUUID(),
            "name": "MyProject-" + name,
            "values": [{
                    "key": "hostenv",
                    "value": "",
                    "type": "text",
                    "enabled": true
                },
                {
                    "key": "username",
                    "value": "",
                    "type": "text",
                    "enabled": true
                },
                {
                    "key": "password",
                    "value": "",
                    "type": "text",
                    "enabled": true
                }
            ],
            "timestamp": 1544608923,
            "synced": false,
            "syncedFilename": "",
            "team": null,
            "isDeleted": false
        };
        return env;
    }

    $('#enter-creds').on('click', function(ev) {
        var options = {
            "name": "sampleBasicModal",
            "content": $("script#envModal").html(),
            onComplete: function(ev) {
                console.log(ev);
                var modal = $(ev.currentTarget).closest('.modal');
                var form = modal.find('form');
                console.log(form);

                var formArr = form.serializeArray();

                var envName = _.find(formArr, {name: 'hostenv'}).value.split('.')[0];
                var envOutput = newEnv(envName);

                var formObj = {};

                formObj.hostenv = _.find(formArr, {name: 'hostenv'}).value;   
                formObj.username = _.find(formArr, {name: 'username'}).value;
                formObj.password = _.find(formArr, {name: 'password'}).value;     

                if (!_pm('env.create', 'MyProject-' + envName, formObj)) {
                    _pm('env.replace', 'MyProject-' + envName, formObj);
                }

                lastEnv = envOutput;
                $('#shownEnv').remove();
                $('#hiddenEnv').slideDown(750);
            }
        };
        var inst = Olive.modal.show(options);

        ev.preventDefault();
    });
}); 

我可以将我的 collection 导入 Postman 环境。然而,同样的 collection 继续添加 7 到 8 次。我找不到问题出在哪里!

编辑:
我检查了几次,然后发现当我有多个环境时会出现问题。

在与 Postman 团队成员讨论此问题后,他们发现 Windows OS 的 Postman 中存在问题,这是报告的 link

Collection getting imported multiple times when using RiP button [Windows]