@ray-js/api 1.6.11 → 1.6.13-beta.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.
@@ -1,3 +1,18 @@
1
+ import get from 'lodash/get';
2
+ const regionMap = {
3
+ AY: 'https://images.tuyacn.com'
4
+ };
5
+ const concatRegionOrigin = (regionCode, path) => {
6
+ const regionOrigin = get(regionMap, [regionCode]) || get(regionMap, ['EU']);
7
+ if (path.indexOf('/') === 0) {
8
+ return "".concat(regionOrigin).concat(path);
9
+ }
10
+ return "".concat(regionOrigin, "/").concat(path);
11
+ };
12
+ const isEmptyOrUndefined = obj => {
13
+ return !obj || Object.keys(obj).length === 0;
14
+ };
15
+
1
16
  /**
2
17
  * 获取 CDN 地址
3
18
  * @description 基础库 2.26.0 及以上版本推荐使用此方法,可以准确获取区域码。
@@ -7,8 +22,26 @@
7
22
  * @param region - 区域代码,若未提供,则使用内置方法获取,EU 兜底
8
23
  * @returns CDN 完整地址
9
24
  */
10
- export default function getCdnUrl(path) {
11
- return path;
25
+ export default function getCdnUrl(path, cdnMap) {
26
+ const regionCode = 'AY';
27
+ if (isEmptyOrUndefined(cdnMap)) {
28
+ // 如果未提供 cdnMap,则使用 regionMap 直接与 path 进行拼接
29
+ return concatRegionOrigin(regionCode, path);
30
+ }
31
+
32
+ // 总是使用 EU 进行兜底
33
+ const cdnShortPath = get(cdnMap, [regionCode, path]) || get(cdnMap, ['AY', path]) || get(cdnMap, [path]);
34
+ if (!cdnShortPath) {
35
+ console.warn("[App] cdn \"".concat(path, "\" is not exist."));
36
+ return path;
37
+ }
38
+ if (cdnShortPath.indexOf('http') === 0 || cdnShortPath.indexOf('//') === 0) {
39
+ return cdnShortPath;
40
+ }
41
+ if (cdnShortPath.indexOf('/') === 0) {
42
+ return "".concat(regionMap[regionCode]).concat(cdnShortPath);
43
+ }
44
+ return "".concat(regionMap[regionCode], "/").concat(cdnShortPath);
12
45
  }
13
46
 
14
47
  /**
@@ -19,7 +52,11 @@ export default function getCdnUrl(path) {
19
52
  * @param region - 区域代码,若未提供,则使用内置方法获取,EU 兜底
20
53
  * @returns CDN 完整地址
21
54
  */
22
- export async function getCdnUrlAsync(path) {
23
- // 暂未实现获取cdn方法,将直接返回path
24
- return Promise.resolve(path);
55
+ export async function getCdnUrlAsync(path, cdnMap) {
56
+ let _regionCode = 'AY';
57
+ if (isEmptyOrUndefined(cdnMap)) {
58
+ // 如果未提供 cdnMap,则使用 regionMap 直接与 path 进行拼接
59
+ return concatRegionOrigin(_regionCode, path);
60
+ }
61
+ return getCdnUrl(path, cdnMap, _regionCode);
25
62
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/api",
3
- "version": "1.6.11",
3
+ "version": "1.6.13-beta.0",
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.11",
33
- "@ray-js/router": "1.6.11",
32
+ "@ray-js/framework": "1.6.13-beta.0",
33
+ "@ray-js/router": "1.6.13-beta.0",
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.11",
39
+ "@ray-js/cli": "1.6.13-beta.0",
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": "8fa280821fd6a139ffadcd31e985ed9df5683736"
49
+ "gitHead": "fc9a900b018f61d0b7ce37ac9db633f402ba9044"
50
50
  }