@ray-js/api 1.6.2 → 1.6.3-alpha.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,5 @@
1
- export declare function getRegionCode(): Promise<string>;
2
- export default function getCdnUrl(path: string, cdnMap?: Record<string, string>, region?: string): string;
3
- export declare function getCdnUrlAsync(path: string, cdnMap?: Record<string, string>, region?: string): Promise<string>;
1
+ type IRegionCode = 'AY' | 'AZ' | 'EU' | 'IN' | 'UE' | 'WE' | 'RU';
2
+ export declare function getRegionCode(): Promise<IRegionCode>;
3
+ export default function getCdnUrl(path: string, cdnMap?: Record<string, string> | Record<IRegionCode, Record<string, string>>, region?: IRegionCode): string;
4
+ export declare function getCdnUrlAsync(path: string, cdnMap?: Record<string, string> | Record<IRegionCode, Record<string, string>>, region?: IRegionCode): Promise<string>;
5
+ export {};
@@ -1,3 +1,4 @@
1
+ import get from 'lodash/get';
1
2
  const regionMap = {
2
3
  AY: 'images.tuyacn.com',
3
4
  AZ: 'usimagesd1448c85ulz2o4.cdn5th.com',
@@ -16,7 +17,8 @@ let getInternalRegionCode = () => {
16
17
  }
17
18
  });
18
19
  }
19
- return 'EU';
20
+ // FIXME: 第一次调用时,_regionCode 为 undefined 时,返回 'EU'
21
+ return _regionCode || 'EU';
20
22
  };
21
23
  export function getRegionCode() {
22
24
  return new Promise((resolve, reject) => {
@@ -33,19 +35,23 @@ export function getRegionCode() {
33
35
  }
34
36
  export default function getCdnUrl(path, cdnMap, region) {
35
37
  if (!cdnMap) {
36
- console.warn('Please pass in cdnMap');
38
+ console.warn('Please provider `cdnImage.json` data');
37
39
  return path;
38
40
  }
39
- const cdnShortPath = cdnMap[path];
41
+ const regionCode = region || getInternalRegionCode();
42
+ const cdnShortPath = get(cdnMap, [regionCode, path]) || get(cdnMap, [path]);
40
43
  if (!cdnShortPath) {
41
44
  console.warn("[App] cdn \"".concat(path, "\" is not exist."));
42
45
  return path;
43
46
  }
44
- return "https://".concat(regionMap[region || getInternalRegionCode()], "/").concat(cdnShortPath);
47
+ if (cdnShortPath.indexOf('http') === 0 || cdnShortPath.indexOf('//') === 0) {
48
+ return cdnShortPath;
49
+ }
50
+ return "https://".concat(regionMap[regionCode], "/").concat(cdnShortPath);
45
51
  }
46
52
  export async function getCdnUrlAsync(path, cdnMap, region) {
47
53
  if (!cdnMap) {
48
- console.warn('Please pass in cdnMap');
54
+ console.warn('Please provider `cdnImage.json` data');
49
55
  return path;
50
56
  }
51
57
  let _regionCode = 'EU';
@@ -58,10 +64,5 @@ export async function getCdnUrlAsync(path, cdnMap, region) {
58
64
  console.warn('[App] getRegionCode error, use default region EU', error);
59
65
  }
60
66
  }
61
- const cdnShortPath = cdnMap[path];
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);
67
+ return getCdnUrl(path, cdnMap, _regionCode);
67
68
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/api",
3
- "version": "1.6.2",
3
+ "version": "1.6.3-alpha.0",
4
4
  "description": "Ray universal api",
5
5
  "keywords": [
6
6
  "ray"
@@ -29,14 +29,16 @@
29
29
  "watch": "ray start --type=component"
30
30
  },
31
31
  "dependencies": {
32
- "@ray-js/framework": "1.6.2",
33
- "@ray-js/router": "1.6.2",
32
+ "@ray-js/framework": "1.6.3-alpha.0",
33
+ "@ray-js/router": "1.6.3-alpha.0",
34
34
  "@ray-js/wechat": "^0.2.19",
35
35
  "base64-browser": "^1.0.1",
36
+ "lodash.get": "^4.4.2",
36
37
  "query-string": "^7.1.3"
37
38
  },
38
39
  "devDependencies": {
39
- "@ray-js/cli": "1.6.2",
40
+ "@ray-js/cli": "1.6.3-alpha.0",
41
+ "@types/lodash.get": "^4",
40
42
  "art-template": "^4.13.2",
41
43
  "fs-extra": "^10.1.0",
42
44
  "miniprogram-api-typings": "^3.12.3",
@@ -46,5 +48,5 @@
46
48
  "access": "public",
47
49
  "registry": "https://registry.npmjs.com"
48
50
  },
49
- "gitHead": "3b5d2fa88a51ed215543b93d99e10c6977cce04d"
51
+ "gitHead": "6c03feeff88f61004021f4264eb9bd2e59c30def"
50
52
  }