@ray-js/api 1.3.15 → 1.3.17

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 +1,2 @@
1
1
  export default function getCdnUrl(path: string): string;
2
+ export declare function getCdnUrlAsync(path: string): Promise<string>;
@@ -1,4 +1,10 @@
1
+ import "core-js/modules/es.object.to-string.js";
2
+ import "core-js/modules/es.promise.js";
1
3
  export default function getCdnUrl(path) {
2
4
  // 暂未实现获取cdn方法,将直接返回path
3
5
  return path;
6
+ }
7
+ export function getCdnUrlAsync(path) {
8
+ // 暂未实现获取cdn方法,将直接返回path
9
+ return Promise.resolve(path);
4
10
  }
@@ -1 +1,3 @@
1
+ export declare function getRegionCode(): Promise<string>;
1
2
  export default function getCdnUrl(path: string, cdnMap?: Record<string, string>): string;
3
+ export declare function getCdnUrlAsync(path: string, cdnMap?: Record<string, string>): Promise<string>;
@@ -1,4 +1,7 @@
1
- var regionCode = 'EU';
1
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
2
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
3
+ import "core-js/modules/es.object.to-string.js";
4
+ import "core-js/modules/es.promise.js";
2
5
  var regionMap = {
3
6
  AY: 'images.tuyacn.com',
4
7
  AZ: 'usimagesd1448c85ulz2o4.cdn5th.com',
@@ -8,8 +11,23 @@ var regionMap = {
8
11
  WE: 'd2h2yqnfpu4gl5.cdn5th.com',
9
12
  UE: 'usimagesd1448c85ulz2o4.cdn5th.com'
10
13
  };
11
- ty.getAppInfo().then(function (res) {
12
- regionCode = res.regionCode;
14
+ var regionCode = 'EU';
15
+ export function getRegionCode() {
16
+ return new Promise(function (resolve, reject) {
17
+ ty.getAppInfo({
18
+ success: function success(res) {
19
+ resolve(res.regionCode);
20
+ },
21
+ fail: function fail(err) {
22
+ reject(err);
23
+ }
24
+ });
25
+ });
26
+ }
27
+ ty.getAppInfo({
28
+ success: function success(res) {
29
+ regionCode = res.regionCode;
30
+ }
13
31
  });
14
32
  export default function getCdnUrl(path, cdnMap) {
15
33
  if (!cdnMap) {
@@ -26,4 +44,64 @@ export default function getCdnUrl(path, cdnMap) {
26
44
 
27
45
  var cdnPath = 'https://' + regionMap[regionCode] + '/' + cdnShortPath;
28
46
  return cdnPath;
47
+ }
48
+ export function getCdnUrlAsync() {
49
+ return _getCdnUrlAsync.apply(this, arguments);
50
+ }
51
+
52
+ function _getCdnUrlAsync() {
53
+ _getCdnUrlAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(path, cdnMap) {
54
+ var _regionCode, cdnShortPath, cdnPath;
55
+
56
+ return _regeneratorRuntime.wrap(function (_context) {
57
+ while (1) {
58
+ switch (_context.prev = _context.next) {
59
+ case 0:
60
+ if (cdnMap) {
61
+ _context.next = 3;
62
+ break;
63
+ }
64
+
65
+ console.warn('请传入cdnMap');
66
+ return _context.abrupt("return", path);
67
+
68
+ case 3:
69
+ _regionCode = 'EU';
70
+ _context.prev = 4;
71
+ _context.next = 7;
72
+ return getRegionCode();
73
+
74
+ case 7:
75
+ _regionCode = _context.sent;
76
+ _context.next = 13;
77
+ break;
78
+
79
+ case 10:
80
+ _context.prev = 10;
81
+ _context.t0 = _context["catch"](4);
82
+ console.warn('[App] getRegionCode error, use default region EU', _context.t0);
83
+
84
+ case 13:
85
+ cdnShortPath = cdnMap[path];
86
+
87
+ if (cdnShortPath) {
88
+ _context.next = 17;
89
+ break;
90
+ }
91
+
92
+ console.warn('[App] cdn "' + path + '" is not exist.');
93
+ return _context.abrupt("return", path);
94
+
95
+ case 17:
96
+ cdnPath = 'https://' + regionMap[_regionCode] + '/' + cdnShortPath;
97
+ return _context.abrupt("return", cdnPath);
98
+
99
+ case 19:
100
+ case "end":
101
+ return _context.stop();
102
+ }
103
+ }
104
+ }, _callee, null, [[4, 10]]);
105
+ }));
106
+ return _getCdnUrlAsync.apply(this, arguments);
29
107
  }
@@ -1 +1,2 @@
1
1
  export default function getCdnUrl(path: string): string;
2
+ export declare function getCdnUrlAsync(path: string): Promise<string>;
@@ -1,4 +1,10 @@
1
+ import "core-js/modules/es.object.to-string.js";
2
+ import "core-js/modules/es.promise.js";
1
3
  export default function getCdnUrl(path) {
2
4
  // 暂未实现获取cdn方法,将直接返回path
3
5
  return path;
6
+ }
7
+ export function getCdnUrlAsync(path) {
8
+ // 暂未实现获取cdn方法,将直接返回path
9
+ return Promise.resolve(path);
4
10
  }
package/lib/index.d.ts CHANGED
@@ -20,7 +20,7 @@ export { default as showTabBar } from './showTabBar';
20
20
  export { default as switchTab } from './switchTab';
21
21
  export { default as onNavigationBarBack } from './onNavigationBarBack';
22
22
  export { default as setNavigationBarBack } from './setNavigationBarBack';
23
- export { default as getCdnUrl } from './getCdnUrl';
23
+ export { default as getCdnUrl, getCdnUrlAsync } from './getCdnUrl';
24
24
  /**
25
25
  * 提供 glboal-api 将 wx / ty 对象暴露出去,供给业务在Ray为显示导出api时进行快速响应开发。
26
26
  */
package/lib/index.js CHANGED
@@ -20,7 +20,7 @@ export { default as showTabBar } from './showTabBar';
20
20
  export { default as switchTab } from './switchTab';
21
21
  export { default as onNavigationBarBack } from './onNavigationBarBack';
22
22
  export { default as setNavigationBarBack } from './setNavigationBarBack';
23
- export { default as getCdnUrl } from './getCdnUrl';
23
+ export { default as getCdnUrl, getCdnUrlAsync } from './getCdnUrl';
24
24
  /**
25
25
  * 提供 glboal-api 将 wx / ty 对象暴露出去,供给业务在Ray为显示导出api时进行快速响应开发。
26
26
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/api",
3
- "version": "1.3.15",
3
+ "version": "1.3.17",
4
4
  "description": "Ray universal api",
5
5
  "keywords": [
6
6
  "ray"
@@ -26,13 +26,13 @@
26
26
  "build:kit:api": "node scripts/api-creator.mjs"
27
27
  },
28
28
  "dependencies": {
29
- "@ray-js/framework": "^1.3.15",
30
- "@ray-js/router": "^1.3.15",
29
+ "@ray-js/framework": "^1.3.17",
30
+ "@ray-js/router": "^1.3.17",
31
31
  "@ray-js/wechat": "^0.0.16",
32
32
  "base64-browser": "^1.0.1"
33
33
  },
34
34
  "devDependencies": {
35
- "@ray-js/cli": "^1.3.15",
35
+ "@ray-js/cli": "^1.3.17",
36
36
  "art-template": "^4.13.2",
37
37
  "fs-extra": "^10.1.0",
38
38
  "miniprogram-api-typings": "^3.4.3",
@@ -44,6 +44,6 @@
44
44
  "email": "tuyafe@tuya.com"
45
45
  }
46
46
  ],
47
- "gitHead": "9576007b031faac65bf77ff5f3b550ba1254f106",
47
+ "gitHead": "7b2a744d2f1c81c406b42c8b258a7abbe7484999",
48
48
  "repository": {}
49
49
  }