@ikenxuan/amagi 2.0.0 → 2.0.1

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
@@ -35,9 +35,15 @@ const Client = await new amagi({
35
35
  bilibili: 'B站ck'
36
36
  }).initServer()
37
37
 
38
- const Data = await (Client.GetBilibiliData({ type: '单个视频作品数据' }))
38
+ const Douyin = await Client.GetDouyinData({ type: '热点词数据' })
39
+ .result({ query: '珠江新城CBD' })
40
+
41
+ const Bilibili = await Client.GetBilibiliData({ type: '单个视频作品数据' })
39
42
  .result({ url: 'https://b23.tv/9JvEHhJ' })
40
43
  ```
44
+ type 参数详见 [**API数据类型枚举**](./src/types/DataType.ts)
45
+
46
+ result 方法传递对象的参数详见 [**抖音接口请求参数类型**](./src/types/DouyinAPIParams.ts)、[**B站接口请求参数类型**](./src/types/BilibiliAPIParams.ts)
41
47
 
42
48
  ## 开发构建
43
49
  > **开发环境下,支持最低node版本为 v18**
@@ -24,10 +24,6 @@ export default class Networks {
24
24
  getLocation(): Promise<string>;
25
25
  /** 获取数据并处理数据的格式化,默认json */
26
26
  getData(new_fetch?: string): Promise<any | boolean>;
27
- /** 获取响应头 */
28
- getHeaders(): Promise<HeadersObject | null>;
29
- /** 一次性获取响应头和响应体 */
30
- getHeadersAndData(): Promise<object>;
31
27
  Tojson(): Promise<any>;
32
28
  ToText(): Promise<void>;
33
29
  ToArrayBuffer(): Promise<void>;
@@ -1,4 +1,4 @@
1
- import axios from 'axios';
1
+ import axios, { AxiosError } from 'axios';
2
2
  export default class Networks {
3
3
  url;
4
4
  method;
@@ -61,7 +61,9 @@ export default class Networks {
61
61
  return result.request.res.responseUrl; // axios中获取最终的请求URL
62
62
  }
63
63
  catch (error) {
64
- console.error(error);
64
+ if (error instanceof AxiosError) {
65
+ throw new Error(error.stack);
66
+ }
65
67
  return '';
66
68
  }
67
69
  }
@@ -77,7 +79,9 @@ export default class Networks {
77
79
  return response.headers['location'];
78
80
  }
79
81
  catch (error) {
80
- console.error(error);
82
+ if (error instanceof AxiosError) {
83
+ throw new Error(error.stack);
84
+ }
81
85
  return '';
82
86
  }
83
87
  }
@@ -117,65 +121,10 @@ export default class Networks {
117
121
  return this.axiosInstance;
118
122
  }
119
123
  catch (error) {
120
- console.error(error);
121
- return false;
122
- }
123
- }
124
- /** 获取响应头 */
125
- async getHeaders () {
126
- try {
127
- this.axiosInstance = await this.returnResult();
128
- if (this.axiosInstance) {
129
- if (this.axiosInstance.headers) {
130
- return this.axiosInstance.headers;
131
- }
132
- else {
133
- console.error('未获取到响应头');
134
- return null;
135
- }
136
- }
137
- else {
138
- console.error('未获取到响应对象');
139
- return null;
140
- }
141
- }
142
- catch (error) {
143
- console.error('获取响应头失败:', error);
144
- return null;
145
- }
146
- }
147
- /** 一次性获取响应头和响应体 */
148
- async getHeadersAndData () {
149
- try {
150
- this.axiosInstance = await this.returnResult();
151
- let headers = null;
152
- let data = null;
153
- if (this.axiosInstance) {
154
- headers = this.axiosInstance.headers;
155
- switch (this.type) {
156
- case 'json':
157
- data = this.axiosInstance.data;
158
- break;
159
- case 'text':
160
- data = this.axiosInstance.data;
161
- break;
162
- case 'arrayBuffer':
163
- data = await this.ToArrayBuffer();
164
- break;
165
- case 'blob':
166
- data = await this.ToBlob();
167
- break;
168
- default:
169
- }
124
+ if (error instanceof AxiosError) {
125
+ throw new Error(error.stack);
170
126
  }
171
- else {
172
- console.error('未获取到响应对象');
173
- }
174
- return { headers, data };
175
- }
176
- catch (error) {
177
- console.error('获取响应头和数据失败:', error);
178
- return { headers: null, data: null };
127
+ return false;
179
128
  }
180
129
  }
181
130
  async Tojson () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ikenxuan/amagi",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "type": "module",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",