@polyv/request-plugin-polyv-business 2.0.0 → 2.1.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/README.md +1 -0
- package/judge.d.ts +10 -2
- package/judge.js +12 -2
- package/package.json +4 -4
- package/polyv-business.js +11 -5
package/README.md
CHANGED
|
@@ -74,6 +74,7 @@ requester.get('/api/data', {}, {
|
|
|
74
74
|
2. 插件会根据请求的 URL 判断需要插入哪些参数:
|
|
75
75
|
- 对于 `/live/v4/watch/common` 接口,插入 `sourceType` 和 `sourceId`
|
|
76
76
|
- 对于 `/live/v4/watch/viewer` 接口,插入 `sourceType`、`sourceId`、`viewerId` 和 `userId`
|
|
77
|
+
- 对于 `/live/v4/channel` 接口,插入 `channelId`
|
|
77
78
|
- 对于其他接口,插入 `channelId` 和 `viewerId`
|
|
78
79
|
3. 如果你使用了 `@polyv/request-plugin-authorize-token` 令牌插件,本插件会根据 URL 判断是否使用 token 和 tokenField:
|
|
79
80
|
- 对于 `/live/v4/watch/common` 接口,会自动插入 `useToken` 为 false 禁用 token 插入
|
package/judge.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
* 插入参数:sourceId、sourceType
|
|
7
7
|
*/
|
|
8
|
-
export declare function
|
|
8
|
+
export declare function isWatchCommonRequest(url: string): boolean;
|
|
9
9
|
/**
|
|
10
10
|
* 是否观众接口
|
|
11
11
|
*
|
|
@@ -13,7 +13,15 @@ export declare function isCommonRequest(url: string): boolean;
|
|
|
13
13
|
*
|
|
14
14
|
* 插入参数:sourceId、sourceType、viewerId、userId
|
|
15
15
|
*/
|
|
16
|
-
export declare function
|
|
16
|
+
export declare function isWatchViewerRequest(url: string): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* 是否频道接口
|
|
19
|
+
*
|
|
20
|
+
* 判断地址:/live/v4/channel
|
|
21
|
+
*
|
|
22
|
+
* 插入参数:channelId
|
|
23
|
+
*/
|
|
24
|
+
export declare function isChannelRequest(url: string): boolean;
|
|
17
25
|
/**
|
|
18
26
|
* 是否 v3 接口,/live/v3 开头的接口,使用 'token' 入参
|
|
19
27
|
*
|
package/judge.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
* 插入参数:sourceId、sourceType
|
|
7
7
|
*/
|
|
8
|
-
export function
|
|
8
|
+
export function isWatchCommonRequest(url) {
|
|
9
9
|
return url.indexOf('/live/v4/watch/common') !== -1;
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
@@ -15,9 +15,19 @@ export function isCommonRequest(url) {
|
|
|
15
15
|
*
|
|
16
16
|
* 插入参数:sourceId、sourceType、viewerId、userId
|
|
17
17
|
*/
|
|
18
|
-
export function
|
|
18
|
+
export function isWatchViewerRequest(url) {
|
|
19
19
|
return url.indexOf('/live/v4/watch/viewer') !== -1;
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* 是否频道接口
|
|
23
|
+
*
|
|
24
|
+
* 判断地址:/live/v4/channel
|
|
25
|
+
*
|
|
26
|
+
* 插入参数:channelId
|
|
27
|
+
*/
|
|
28
|
+
export function isChannelRequest(url) {
|
|
29
|
+
return url.indexOf('/live/v4/channel') !== -1;
|
|
30
|
+
}
|
|
21
31
|
/**
|
|
22
32
|
* 是否 v3 接口,/live/v3 开头的接口,使用 'token' 入参
|
|
23
33
|
*
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polyv/request-plugin-polyv-business",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"main": "./index.js",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@polyv/request-core": "2.
|
|
7
|
-
"@polyv/request-plugin-authorize-token": "2.
|
|
8
|
-
"@polyv/request-plugin-global-params": "2.
|
|
6
|
+
"@polyv/request-core": "2.1.0",
|
|
7
|
+
"@polyv/request-plugin-authorize-token": "2.1.0",
|
|
8
|
+
"@polyv/request-plugin-global-params": "2.1.0"
|
|
9
9
|
},
|
|
10
10
|
"types": "./index.d.ts"
|
|
11
11
|
}
|
package/polyv-business.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GlobalParamsRequestPlugin } from '@polyv/request-plugin-global-params';
|
|
2
|
-
import {
|
|
2
|
+
import { isWatchCommonRequest, isV3Request, isWatchViewerRequest, isChannelRequest } from "./judge";
|
|
3
3
|
/**
|
|
4
4
|
* 保利威业务数据插件
|
|
5
5
|
*/
|
|
@@ -20,16 +20,19 @@ export class PolyvBusinessRequestPlugin {
|
|
|
20
20
|
}
|
|
21
21
|
const url = requestOptions.url || '';
|
|
22
22
|
const businessData = await this.__getBusinessData(requestOptions);
|
|
23
|
-
if (
|
|
23
|
+
if (isWatchCommonRequest(url) && this.__checkBusiness(businessData, ['sourceType', 'sourceId'])) {
|
|
24
24
|
params.sourceType = businessData.sourceType;
|
|
25
25
|
params.sourceId = businessData.sourceId;
|
|
26
26
|
}
|
|
27
|
-
else if (
|
|
27
|
+
else if (isWatchViewerRequest(url) && this.__checkBusiness(businessData, ['sourceType', 'sourceId', 'viewerId', 'unionId'])) {
|
|
28
28
|
params.sourceType = businessData.sourceType;
|
|
29
29
|
params.sourceId = businessData.sourceId;
|
|
30
30
|
params.viewerId = businessData.viewerId;
|
|
31
31
|
params.userId = businessData.unionId;
|
|
32
32
|
}
|
|
33
|
+
else if (isChannelRequest(url) && this.__checkBusiness(businessData, ['channelId'])) {
|
|
34
|
+
params.channelId = businessData.channelId;
|
|
35
|
+
}
|
|
33
36
|
else if (this.__checkBusiness(businessData, ['channelId', 'viewerId'])) {
|
|
34
37
|
params.channelId = businessData.channelId;
|
|
35
38
|
params.viewerId = businessData.viewerId;
|
|
@@ -48,7 +51,7 @@ export class PolyvBusinessRequestPlugin {
|
|
|
48
51
|
const url = options.url || '';
|
|
49
52
|
options = options;
|
|
50
53
|
// 公共 api 接口,无需授权参数
|
|
51
|
-
if (
|
|
54
|
+
if (isWatchCommonRequest(url)) {
|
|
52
55
|
options.useToken = false;
|
|
53
56
|
return;
|
|
54
57
|
}
|
|
@@ -58,7 +61,10 @@ export class PolyvBusinessRequestPlugin {
|
|
|
58
61
|
// 如果 tokenField 未设置,则根据 url 设置
|
|
59
62
|
if (!options.tokenInfo.tokenField) {
|
|
60
63
|
let tokenField = 'viewerToken';
|
|
61
|
-
if (
|
|
64
|
+
if (isChannelRequest(url)) {
|
|
65
|
+
tokenField = 'channelToken';
|
|
66
|
+
}
|
|
67
|
+
else if (isV3Request(url)) {
|
|
62
68
|
tokenField = 'token';
|
|
63
69
|
}
|
|
64
70
|
options.tokenInfo.tokenField = tokenField;
|