@ray-js/api 1.6.9 → 1.6.11
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/@types/api-extend.d.ts +29 -11
- package/lib/getCdnUrl/index.d.ts +22 -2
- package/lib/getCdnUrl/index.js +18 -0
- package/lib/getCdnUrl/index.thing.d.ts +23 -3
- package/lib/getCdnUrl/index.thing.js +69 -28
- package/lib/getCdnUrl/index.wechat.d.ts +22 -2
- package/lib/getCdnUrl/index.wechat.js +18 -0
- package/package.json +5 -5
package/@types/api-extend.d.ts
CHANGED
@@ -228,8 +228,19 @@ interface WebviewContext {
|
|
228
228
|
}
|
229
229
|
|
230
230
|
interface SocketTask {
|
231
|
-
send(option: {
|
232
|
-
|
231
|
+
send(option: {
|
232
|
+
data: string | ArrayBuffer
|
233
|
+
success?: () => void
|
234
|
+
fail?: () => void
|
235
|
+
complete?: () => void
|
236
|
+
}): void
|
237
|
+
close(option: {
|
238
|
+
code?: number
|
239
|
+
reason?: string
|
240
|
+
success?: () => void
|
241
|
+
fail?: () => void
|
242
|
+
complete?: () => void
|
243
|
+
}): void
|
233
244
|
onOpen(callback: () => void): void
|
234
245
|
onClose(callback: () => void): void
|
235
246
|
onError(callback: () => void): void
|
@@ -237,15 +248,15 @@ interface SocketTask {
|
|
237
248
|
}
|
238
249
|
|
239
250
|
interface ConnectSocketProps {
|
240
|
-
url: string
|
241
|
-
protocols?: string[]
|
242
|
-
header?: Record<string, string
|
243
|
-
timeout?: number
|
244
|
-
tcpNoDelay?: boolean
|
245
|
-
perMessageDeflate?: boolean
|
246
|
-
forceCellularNetwork?: boolean
|
247
|
-
success?: () => void
|
248
|
-
fail?: () => void
|
251
|
+
url: string
|
252
|
+
protocols?: string[]
|
253
|
+
header?: Record<string, string>
|
254
|
+
timeout?: number
|
255
|
+
tcpNoDelay?: boolean
|
256
|
+
perMessageDeflate?: boolean
|
257
|
+
forceCellularNetwork?: boolean
|
258
|
+
success?: () => void
|
259
|
+
fail?: () => void
|
249
260
|
complete?: () => void
|
250
261
|
}
|
251
262
|
|
@@ -315,6 +326,13 @@ declare namespace ty {
|
|
315
326
|
* @returns 是否可用
|
316
327
|
*/
|
317
328
|
export function canIUse(schema: string): boolean
|
329
|
+
type IRegionCode = 'AY' | 'AZ' | 'EU' | 'IN' | 'UE' | 'WE' | 'RU'
|
330
|
+
|
331
|
+
/**
|
332
|
+
* 获取当前小程序的区域码
|
333
|
+
* @returns 区域码 可选值:AY, AZ, EU, IN, RU, UE, WE
|
334
|
+
*/
|
335
|
+
export function getRegionCode(): IRegionCode
|
318
336
|
}
|
319
337
|
|
320
338
|
declare namespace WechatMiniprogram {
|
package/lib/getCdnUrl/index.d.ts
CHANGED
@@ -1,2 +1,22 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
type IRegionCode = 'AY' | 'AZ' | 'EU' | 'IN' | 'UE' | 'WE' | 'RU';
|
2
|
+
type ICdnMap = Record<string, string> | Record<IRegionCode, Record<string, string>>;
|
3
|
+
/**
|
4
|
+
* 获取 CDN 地址
|
5
|
+
* @description 基础库 2.26.0 及以上版本推荐使用此方法,可以准确获取区域码。
|
6
|
+
* 基础库 2.26.0 以下版本请使用 getCdnUrlAsync 方法,以避免区域码获取不准确的问题。
|
7
|
+
* @param path - 图片路径
|
8
|
+
* @param cdnMap - CDN 地址映射表,若未提供,则使用内置 regionMap 直接与 path 进行拼接
|
9
|
+
* @param region - 区域代码,若未提供,则使用内置方法获取,EU 兜底
|
10
|
+
* @returns CDN 完整地址
|
11
|
+
*/
|
12
|
+
export default function getCdnUrl(path: string, cdnMap?: ICdnMap, region?: IRegionCode): string;
|
13
|
+
/**
|
14
|
+
* 获取 CDN 地址
|
15
|
+
* @description 基础库 2.26.0 以下版本请使用此方法,以避免区域码获取不准确的问题。
|
16
|
+
* @param path - 图片路径
|
17
|
+
* @param cdnMap - CDN 地址映射表,若未提供,则使用内置 regionMap 直接与 path 进行拼接
|
18
|
+
* @param region - 区域代码,若未提供,则使用内置方法获取,EU 兜底
|
19
|
+
* @returns CDN 完整地址
|
20
|
+
*/
|
21
|
+
export declare function getCdnUrlAsync(path: string, cdnMap?: ICdnMap, region?: IRegionCode): Promise<string>;
|
22
|
+
export {};
|
package/lib/getCdnUrl/index.js
CHANGED
@@ -1,6 +1,24 @@
|
|
1
|
+
/**
|
2
|
+
* 获取 CDN 地址
|
3
|
+
* @description 基础库 2.26.0 及以上版本推荐使用此方法,可以准确获取区域码。
|
4
|
+
* 基础库 2.26.0 以下版本请使用 getCdnUrlAsync 方法,以避免区域码获取不准确的问题。
|
5
|
+
* @param path - 图片路径
|
6
|
+
* @param cdnMap - CDN 地址映射表,若未提供,则使用内置 regionMap 直接与 path 进行拼接
|
7
|
+
* @param region - 区域代码,若未提供,则使用内置方法获取,EU 兜底
|
8
|
+
* @returns CDN 完整地址
|
9
|
+
*/
|
1
10
|
export default function getCdnUrl(path) {
|
2
11
|
return path;
|
3
12
|
}
|
13
|
+
|
14
|
+
/**
|
15
|
+
* 获取 CDN 地址
|
16
|
+
* @description 基础库 2.26.0 以下版本请使用此方法,以避免区域码获取不准确的问题。
|
17
|
+
* @param path - 图片路径
|
18
|
+
* @param cdnMap - CDN 地址映射表,若未提供,则使用内置 regionMap 直接与 path 进行拼接
|
19
|
+
* @param region - 区域代码,若未提供,则使用内置方法获取,EU 兜底
|
20
|
+
* @returns CDN 完整地址
|
21
|
+
*/
|
4
22
|
export async function getCdnUrlAsync(path) {
|
5
23
|
// 暂未实现获取cdn方法,将直接返回path
|
6
24
|
return Promise.resolve(path);
|
@@ -1,3 +1,23 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
export declare function
|
1
|
+
type IRegionCode = 'AY' | 'AZ' | 'EU' | 'IN' | 'UE' | 'WE' | 'RU';
|
2
|
+
type ICdnMap = Record<string, string> | Record<IRegionCode, Record<string, string>>;
|
3
|
+
export declare function getRegionCode(): Promise<IRegionCode>;
|
4
|
+
/**
|
5
|
+
* 获取 CDN 地址
|
6
|
+
* @description 基础库 2.26.0 及以上版本推荐使用此方法,可以准确获取区域码。
|
7
|
+
* 基础库 2.26.0 以下版本请使用 getCdnUrlAsync 方法,以避免区域码获取不准确的问题。
|
8
|
+
* @param path - 图片路径
|
9
|
+
* @param cdnMap - CDN 地址映射表,若未提供,则使用内置 regionMap 直接与 path 进行拼接
|
10
|
+
* @param region - 区域代码,若未提供,则使用内置方法获取,EU 兜底
|
11
|
+
* @returns CDN 完整地址
|
12
|
+
*/
|
13
|
+
export default function getCdnUrl(path: string, cdnMap?: ICdnMap, region?: IRegionCode): string;
|
14
|
+
/**
|
15
|
+
* 获取 CDN 地址
|
16
|
+
* @description 基础库 2.26.0 以下版本请使用此方法,以避免区域码获取不准确的问题。
|
17
|
+
* @param path - 图片路径
|
18
|
+
* @param cdnMap - CDN 地址映射表,若未提供,则使用内置 regionMap 直接与 path 进行拼接
|
19
|
+
* @param region - 区域代码,若未提供,则使用内置方法获取,EU 兜底
|
20
|
+
* @returns CDN 完整地址
|
21
|
+
*/
|
22
|
+
export declare function getCdnUrlAsync(path: string, cdnMap?: ICdnMap, region?: IRegionCode): Promise<string>;
|
23
|
+
export {};
|
@@ -1,28 +1,36 @@
|
|
1
|
+
import get from 'lodash/get';
|
1
2
|
const regionMap = {
|
2
|
-
AY: 'images.tuyacn.com',
|
3
|
-
AZ: 'usimagesd1448c85ulz2o4.cdn5th.com',
|
4
|
-
EU: 'euimagesd2h2yqnfpu4gl5.cdn5th.com',
|
5
|
-
IN: 'inimagesd1jqokb9wptk2t.cdn5th.com',
|
6
|
-
RU: 'euimagesd2h2yqnfpu4gl5.cdn5th.com',
|
7
|
-
WE: 'weimages57vdxnr.cdn5th.com',
|
8
|
-
UE: 'ueimages58yny2.cdn5th.com'
|
3
|
+
AY: 'https://images.tuyacn.com',
|
4
|
+
AZ: 'https://usimagesd1448c85ulz2o4.cdn5th.com',
|
5
|
+
EU: 'https://euimagesd2h2yqnfpu4gl5.cdn5th.com',
|
6
|
+
IN: 'https://inimagesd1jqokb9wptk2t.cdn5th.com',
|
7
|
+
RU: 'https://euimagesd2h2yqnfpu4gl5.cdn5th.com',
|
8
|
+
WE: 'https://weimages57vdxnr.cdn5th.com',
|
9
|
+
UE: 'https://ueimages58yny2.cdn5th.com'
|
9
10
|
};
|
10
|
-
let
|
11
|
-
|
12
|
-
if (!
|
11
|
+
let _globalRegionCode;
|
12
|
+
const getInternalRegionCode = () => {
|
13
|
+
if (!_globalRegionCode) {
|
14
|
+
// 2.26.0 基础库才加上的方法
|
15
|
+
|
16
|
+
if (typeof ty.getRegionCode === 'function') {
|
17
|
+
_globalRegionCode = ty.getRegionCode();
|
18
|
+
return _globalRegionCode || 'EU';
|
19
|
+
}
|
13
20
|
ty.getAppInfo({
|
14
21
|
success(res) {
|
15
|
-
|
22
|
+
_globalRegionCode = res.regionCode;
|
16
23
|
}
|
17
24
|
});
|
18
25
|
}
|
19
|
-
|
26
|
+
// FIXME: 第一次调用时,_regionCode 为 undefined 时,返回 'EU'
|
27
|
+
return _globalRegionCode || 'EU';
|
20
28
|
};
|
21
29
|
export function getRegionCode() {
|
22
30
|
return new Promise((resolve, reject) => {
|
23
31
|
ty.getAppInfo({
|
24
32
|
success(res) {
|
25
|
-
|
33
|
+
_globalRegionCode = res.regionCode;
|
26
34
|
resolve(res.regionCode);
|
27
35
|
},
|
28
36
|
fail(err) {
|
@@ -31,24 +39,62 @@ export function getRegionCode() {
|
|
31
39
|
});
|
32
40
|
});
|
33
41
|
}
|
42
|
+
const concatRegionOrigin = (regionCode, path) => {
|
43
|
+
const regionOrigin = get(regionMap, [regionCode]) || get(regionMap, ['EU']);
|
44
|
+
if (path.indexOf('/') === 0) {
|
45
|
+
return "".concat(regionOrigin).concat(path);
|
46
|
+
}
|
47
|
+
return "".concat(regionOrigin, "/").concat(path);
|
48
|
+
};
|
49
|
+
const isEmptyOrUndefined = obj => {
|
50
|
+
return !obj || Object.keys(obj).length === 0;
|
51
|
+
};
|
52
|
+
|
53
|
+
/**
|
54
|
+
* 获取 CDN 地址
|
55
|
+
* @description 基础库 2.26.0 及以上版本推荐使用此方法,可以准确获取区域码。
|
56
|
+
* 基础库 2.26.0 以下版本请使用 getCdnUrlAsync 方法,以避免区域码获取不准确的问题。
|
57
|
+
* @param path - 图片路径
|
58
|
+
* @param cdnMap - CDN 地址映射表,若未提供,则使用内置 regionMap 直接与 path 进行拼接
|
59
|
+
* @param region - 区域代码,若未提供,则使用内置方法获取,EU 兜底
|
60
|
+
* @returns CDN 完整地址
|
61
|
+
*/
|
34
62
|
export default function getCdnUrl(path, cdnMap, region) {
|
35
|
-
|
36
|
-
|
37
|
-
|
63
|
+
const regionCode = region || getInternalRegionCode();
|
64
|
+
if (isEmptyOrUndefined(cdnMap)) {
|
65
|
+
// 如果未提供 cdnMap,则使用 regionMap 直接与 path 进行拼接
|
66
|
+
return concatRegionOrigin(regionCode, path);
|
38
67
|
}
|
39
|
-
|
68
|
+
|
69
|
+
// 总是使用 EU 进行兜底
|
70
|
+
const cdnShortPath = get(cdnMap, [regionCode, path]) || get(cdnMap, ['EU', path]) || get(cdnMap, [path]);
|
40
71
|
if (!cdnShortPath) {
|
41
72
|
console.warn("[App] cdn \"".concat(path, "\" is not exist."));
|
42
73
|
return path;
|
43
74
|
}
|
44
|
-
|
75
|
+
if (cdnShortPath.indexOf('http') === 0 || cdnShortPath.indexOf('//') === 0) {
|
76
|
+
return cdnShortPath;
|
77
|
+
}
|
78
|
+
if (cdnShortPath.indexOf('/') === 0) {
|
79
|
+
return "".concat(regionMap[regionCode]).concat(cdnShortPath);
|
80
|
+
}
|
81
|
+
return "".concat(regionMap[regionCode], "/").concat(cdnShortPath);
|
45
82
|
}
|
83
|
+
|
84
|
+
/**
|
85
|
+
* 获取 CDN 地址
|
86
|
+
* @description 基础库 2.26.0 以下版本请使用此方法,以避免区域码获取不准确的问题。
|
87
|
+
* @param path - 图片路径
|
88
|
+
* @param cdnMap - CDN 地址映射表,若未提供,则使用内置 regionMap 直接与 path 进行拼接
|
89
|
+
* @param region - 区域代码,若未提供,则使用内置方法获取,EU 兜底
|
90
|
+
* @returns CDN 完整地址
|
91
|
+
*/
|
46
92
|
export async function getCdnUrlAsync(path, cdnMap, region) {
|
47
|
-
|
48
|
-
|
49
|
-
|
93
|
+
let _regionCode = _globalRegionCode || 'EU';
|
94
|
+
if (isEmptyOrUndefined(cdnMap)) {
|
95
|
+
// 如果未提供 cdnMap,则使用 regionMap 直接与 path 进行拼接
|
96
|
+
return concatRegionOrigin(_regionCode, path);
|
50
97
|
}
|
51
|
-
let _regionCode = 'EU';
|
52
98
|
if (region) {
|
53
99
|
_regionCode = region;
|
54
100
|
} else {
|
@@ -58,10 +104,5 @@ export async function getCdnUrlAsync(path, cdnMap, region) {
|
|
58
104
|
console.warn('[App] getRegionCode error, use default region EU', error);
|
59
105
|
}
|
60
106
|
}
|
61
|
-
|
62
|
-
if (!cdnShortPath) {
|
63
|
-
console.warn("[App] cdn \"".concat(path, "\" is not exist."));
|
64
|
-
return path;
|
65
|
-
}
|
66
|
-
return "https://".concat(regionMap[_regionCode], "/").concat(cdnShortPath);
|
107
|
+
return getCdnUrl(path, cdnMap, _regionCode);
|
67
108
|
}
|
@@ -1,2 +1,22 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
type IRegionCode = 'AY' | 'AZ' | 'EU' | 'IN' | 'UE' | 'WE' | 'RU';
|
2
|
+
type ICdnMap = Record<string, string> | Record<IRegionCode, Record<string, string>>;
|
3
|
+
/**
|
4
|
+
* 获取 CDN 地址
|
5
|
+
* @description 基础库 2.26.0 及以上版本推荐使用此方法,可以准确获取区域码。
|
6
|
+
* 基础库 2.26.0 以下版本请使用 getCdnUrlAsync 方法,以避免区域码获取不准确的问题。
|
7
|
+
* @param path - 图片路径
|
8
|
+
* @param cdnMap - CDN 地址映射表,若未提供,则使用内置 regionMap 直接与 path 进行拼接
|
9
|
+
* @param region - 区域代码,若未提供,则使用内置方法获取,EU 兜底
|
10
|
+
* @returns CDN 完整地址
|
11
|
+
*/
|
12
|
+
export default function getCdnUrl(path: string, cdnMap?: ICdnMap, region?: IRegionCode): string;
|
13
|
+
/**
|
14
|
+
* 获取 CDN 地址
|
15
|
+
* @description 基础库 2.26.0 以下版本请使用此方法,以避免区域码获取不准确的问题。
|
16
|
+
* @param path - 图片路径
|
17
|
+
* @param cdnMap - CDN 地址映射表,若未提供,则使用内置 regionMap 直接与 path 进行拼接
|
18
|
+
* @param region - 区域代码,若未提供,则使用内置方法获取,EU 兜底
|
19
|
+
* @returns CDN 完整地址
|
20
|
+
*/
|
21
|
+
export declare function getCdnUrlAsync(path: string, cdnMap?: ICdnMap, region?: IRegionCode): Promise<string>;
|
22
|
+
export {};
|
@@ -1,6 +1,24 @@
|
|
1
|
+
/**
|
2
|
+
* 获取 CDN 地址
|
3
|
+
* @description 基础库 2.26.0 及以上版本推荐使用此方法,可以准确获取区域码。
|
4
|
+
* 基础库 2.26.0 以下版本请使用 getCdnUrlAsync 方法,以避免区域码获取不准确的问题。
|
5
|
+
* @param path - 图片路径
|
6
|
+
* @param cdnMap - CDN 地址映射表,若未提供,则使用内置 regionMap 直接与 path 进行拼接
|
7
|
+
* @param region - 区域代码,若未提供,则使用内置方法获取,EU 兜底
|
8
|
+
* @returns CDN 完整地址
|
9
|
+
*/
|
1
10
|
export default function getCdnUrl(path) {
|
2
11
|
return path;
|
3
12
|
}
|
13
|
+
|
14
|
+
/**
|
15
|
+
* 获取 CDN 地址
|
16
|
+
* @description 基础库 2.26.0 以下版本请使用此方法,以避免区域码获取不准确的问题。
|
17
|
+
* @param path - 图片路径
|
18
|
+
* @param cdnMap - CDN 地址映射表,若未提供,则使用内置 regionMap 直接与 path 进行拼接
|
19
|
+
* @param region - 区域代码,若未提供,则使用内置方法获取,EU 兜底
|
20
|
+
* @returns CDN 完整地址
|
21
|
+
*/
|
4
22
|
export async function getCdnUrlAsync(path) {
|
5
23
|
// 暂未实现获取cdn方法,将直接返回path
|
6
24
|
return Promise.resolve(path);
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ray-js/api",
|
3
|
-
"version": "1.6.
|
3
|
+
"version": "1.6.11",
|
4
4
|
"description": "Ray universal api",
|
5
5
|
"keywords": [
|
6
6
|
"ray"
|
@@ -29,14 +29,14 @@
|
|
29
29
|
"watch": "ray start --type=component"
|
30
30
|
},
|
31
31
|
"dependencies": {
|
32
|
-
"@ray-js/framework": "1.6.
|
33
|
-
"@ray-js/router": "1.6.
|
32
|
+
"@ray-js/framework": "1.6.11",
|
33
|
+
"@ray-js/router": "1.6.11",
|
34
34
|
"@ray-js/wechat": "^0.2.19",
|
35
35
|
"base64-browser": "^1.0.1",
|
36
36
|
"query-string": "^7.1.3"
|
37
37
|
},
|
38
38
|
"devDependencies": {
|
39
|
-
"@ray-js/cli": "1.6.
|
39
|
+
"@ray-js/cli": "1.6.11",
|
40
40
|
"art-template": "^4.13.2",
|
41
41
|
"fs-extra": "^10.1.0",
|
42
42
|
"miniprogram-api-typings": "^3.12.3",
|
@@ -46,5 +46,5 @@
|
|
46
46
|
"access": "public",
|
47
47
|
"registry": "https://registry.npmjs.com"
|
48
48
|
},
|
49
|
-
"gitHead": "
|
49
|
+
"gitHead": "8fa280821fd6a139ffadcd31e985ed9df5683736"
|
50
50
|
}
|