@polyv/request-core 2.3.0 → 2.5.0
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/ajax.js +4 -0
- package/interface/index.d.ts +5 -0
- package/package.json +2 -2
- package/utils.js +23 -1
package/ajax.js
CHANGED
|
@@ -148,6 +148,10 @@ export class PolyvRequest {
|
|
|
148
148
|
let newResult = result;
|
|
149
149
|
// 处理插件中的响应拦截
|
|
150
150
|
newResult = await this.__pluginCtrl.interceptPluginResponse(newResult, options);
|
|
151
|
+
if (options.responseInterceptor) {
|
|
152
|
+
const r = await options.responseInterceptor(newResult, options);
|
|
153
|
+
newResult = r || newResult;
|
|
154
|
+
}
|
|
151
155
|
return newResult;
|
|
152
156
|
}
|
|
153
157
|
/**
|
package/interface/index.d.ts
CHANGED
|
@@ -41,6 +41,7 @@ export type RequestType = 'form' | 'json';
|
|
|
41
41
|
* 响应格式。
|
|
42
42
|
*/
|
|
43
43
|
export type ResponseType = 'json' | 'text' | 'blob' | 'arraybuffer';
|
|
44
|
+
export type ResponseInterceptor<Options extends RequestOptions = RequestOptions> = (result: RequestResult, options: Options) => Promise<RequestResult | void> | RequestResult | void;
|
|
44
45
|
/**
|
|
45
46
|
* 请求公用选项
|
|
46
47
|
*/
|
|
@@ -86,6 +87,10 @@ export interface RequestBasicOptions {
|
|
|
86
87
|
* 跨域请求时是否提供凭据
|
|
87
88
|
*/
|
|
88
89
|
withCredentials?: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* 响应头拦截
|
|
92
|
+
*/
|
|
93
|
+
responseInterceptor?: ResponseInterceptor;
|
|
89
94
|
}
|
|
90
95
|
export interface RequestCustomOptions {
|
|
91
96
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polyv/request-core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"main": "./index.js",
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"axios": ">=1.0.0"
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@just4/querystring": "^2.0.0",
|
|
15
|
-
"@just4/request": "^0.
|
|
15
|
+
"@just4/request": "^1.0.0",
|
|
16
16
|
"@polyv/utils": "^2.6.0",
|
|
17
17
|
"md5": "2.3.0",
|
|
18
18
|
"sha256": "0.2.0"
|
package/utils.js
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 是否是 Blob 或 File 鸭子类型
|
|
3
|
+
* @description 解决 iframe 中 Blob 或 File 类型无法被识别的问题
|
|
4
|
+
* @param value 值
|
|
5
|
+
*/
|
|
6
|
+
function isBlobLike(value) {
|
|
7
|
+
if (!value || typeof value !== 'object') {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
const tag = Object.prototype.toString.call(value);
|
|
11
|
+
if (tag === '[object Blob]' || tag === '[object File]') {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
const blobLike = value;
|
|
15
|
+
return typeof blobLike.size === 'number'
|
|
16
|
+
&& typeof blobLike.type === 'string'
|
|
17
|
+
&& typeof blobLike.slice === 'function'
|
|
18
|
+
&& typeof blobLike.arrayBuffer === 'function';
|
|
19
|
+
}
|
|
1
20
|
/**
|
|
2
21
|
* 是否存在 File 值
|
|
3
22
|
* @param data
|
|
@@ -6,7 +25,10 @@ export function hasFileValue(data) {
|
|
|
6
25
|
for (const key in data) {
|
|
7
26
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
8
27
|
const val = data[key];
|
|
9
|
-
if (val
|
|
28
|
+
if (isBlobLike(val)) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
if (val instanceof File || val instanceof Blob) {
|
|
10
32
|
return true;
|
|
11
33
|
}
|
|
12
34
|
}
|