whistle 2.10.13 → 2.10.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  # whistle
8
8
 
9
9
  [![NPM version](https://img.shields.io/npm/v/whistle.svg?style=flat-square)](https://npmjs.org/package/whistle)
10
- [![node version](https://img.shields.io/badge/node.js->=_8-green.svg?style=flat-square)](http://nodejs.org/download/)
10
+ [![node version](https://img.shields.io/badge/node.js->=_16-green.svg?style=flat-square)](http://nodejs.org/download/)
11
11
  [![npm download](https://img.shields.io/npm/dm/whistle.svg?style=flat-square)](https://npmjs.org/package/whistle)
12
12
  [![NPM count](https://img.shields.io/npm/dt/whistle.svg?style=flat-square)](https://www.npmjs.com/package/whistle)
13
13
  [![License](https://img.shields.io/github/license/avwo/whistle?style=flat-square)](https://www.npmjs.com/package/whistle)
package/bin/api.js CHANGED
@@ -58,6 +58,49 @@ async function request(options) {
58
58
  });
59
59
  }
60
60
 
61
+ function createFile(data) {
62
+ if (Buffer.isBuffer(data)) {
63
+ data = { base64: data.toString('base64') };
64
+ } else {
65
+ data = { value: common.toString(data) };
66
+ }
67
+ return request({ url: 'temp/create', data: data }).then(function(data) {
68
+ return data.filepath;
69
+ });
70
+ }
71
+
72
+ /**
73
+ * 生成访问 Whistle 抓包界面的 URL,用 Chrome 或系统自带浏览器打开即可查看抓包数据
74
+ *
75
+ * 入参可选,支持传入以下来源:
76
+ * - 抓包数据
77
+ * - 本地文件目录
78
+ * - 临时文件目录
79
+ * - 远程 URL
80
+ *
81
+ * 不传参时,返回默认的 Whistle 抓包界面 URL。
82
+ *
83
+ * @param source 可选。抓包数据、本地文件目录、临时文件目录或远程 URL;
84
+ * 不传时返回默认的 Whistle 抓包界面 URL
85
+ * @returns 访问 Whistle 抓包界面的 URL
86
+ */
87
+ exports.createUrl = async function(sessions) {
88
+ var options = await getOptions();
89
+ var url = 'http://' + (options.host || '127.0.0.1') + ':' + (options.port || 8899) + '/';
90
+ if (!sessions) {
91
+ return url;
92
+ }
93
+ var tempFile = common.getTempFile(sessions);
94
+ if (!tempFile) {
95
+ if (/^[\da-f]{64}$/.test(sessions)) {
96
+ tempFile = sessions;
97
+ } else {
98
+ tempFile = (await createFile(sessions)).substring(5);
99
+ }
100
+ }
101
+ return url + '#network?dataUrl=' + encodeURIComponent(tempFile);
102
+ };
103
+
61
104
  exports.getRootCA = async function() {
62
105
  return request({ url: 'rootca', type: 'raw' });
63
106
  };
@@ -73,16 +116,7 @@ exports.setEnableHTTPS = exports.setEnableHttps = async function (enabled) {
73
116
  };
74
117
 
75
118
 
76
- exports.createFile = function(data) {
77
- if (Buffer.isBuffer(data)) {
78
- data = { base64: data.toString('base64') };
79
- } else {
80
- data = { value: common.toString(data) };
81
- }
82
- return request({ url: 'temp/create', data: data }).then(function(data) {
83
- return data.filepath;
84
- });
85
- };
119
+ exports.createFile = createFile;
86
120
 
87
121
  exports.getFile = function(filepath) {
88
122
  return request('temp/get?filename=' + encodeURIComponent(filepath))
@@ -8,6 +8,6 @@
8
8
  </head>
9
9
  <body>
10
10
  <div id="container" class="main"></div>
11
- <script src="js/index.js?v=2.10.13"></script>
11
+ <script src="js/index.js?v=2.10.14"></script>
12
12
  </body>
13
13
  </html>