pixuireactcomponents 1.3.93 → 1.3.94

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pixuireactcomponents",
3
- "version": "1.3.93",
3
+ "version": "1.3.94",
4
4
  "description": "pixui react components",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -9,6 +9,7 @@ export declare namespace assetCache {
9
9
  * @returns 返回本地缓存文件路径,成功后resolve资源的本地路径,失败后reject函数的url参数
10
10
  */
11
11
  const cache: (url: string, force?: boolean, retryTimes?: number) => Promise<string>;
12
+ const getCachePath: (url: string) => string;
12
13
  /**
13
14
  *
14
15
  * @param url 资源url
@@ -64,60 +64,43 @@ export var assetCache;
64
64
  var urlWithoutParams, localPath, xhr;
65
65
  var _this = this;
66
66
  return __generator(this, function (_a) {
67
- switch (_a.label) {
68
- case 0:
69
- if (!isJssdkEnv) {
70
- console.log('非jssdk环境');
71
- reject(url);
72
- }
73
- urlWithoutParams = url.split('?')[0];
74
- return [4 /*yield*/, getLocalPath(urlWithoutParams)];
75
- case 1:
76
- localPath = _a.sent();
77
- if (!localPath) {
78
- console.log('getLocalPath failed');
79
- reject();
80
- return [2 /*return*/];
81
- }
82
- console.log('cacheAsset getlocalPath', localPath);
83
- if (!force) {
84
- if (OPLib.fileExists(localPath)) {
85
- console.log('cacheAsset file exist', localPath);
67
+ if (!isJssdkEnv) {
68
+ console.log('非jssdk环境');
69
+ reject(url);
70
+ }
71
+ urlWithoutParams = url.split('?')[0];
72
+ localPath = getLocalPath(urlWithoutParams);
73
+ if (!localPath) {
74
+ console.log('getLocalPath failed');
75
+ reject();
76
+ return [2 /*return*/];
77
+ }
78
+ console.log('cacheAsset getlocalPath', localPath);
79
+ if (!force) {
80
+ if (OPLib.fileExists(localPath)) {
81
+ console.log('cacheAsset file exist', localPath);
82
+ resolve(localPath);
83
+ }
84
+ }
85
+ console.log('cacheAsset file not exist or not force', url, localPath);
86
+ xhr = new XMLHttpRequest();
87
+ xhr.open('GET', url, true);
88
+ xhr.responseType = 'arraybuffer';
89
+ xhr.onload = function () { return __awaiter(_this, void 0, void 0, function () {
90
+ return __generator(this, function (_a) {
91
+ if (xhr.status === 200) {
92
+ console.log('cacheAsset xhr statue=200', url, localPath);
93
+ // let buf = Buffer.from(xhr.response, 'binary').buffer;
94
+ if (localPath) {
95
+ OPLib.saveToFile(localPath, xhr.response);
86
96
  resolve(localPath);
87
97
  }
98
+ else {
99
+ reject(url);
100
+ }
88
101
  }
89
- console.log('cacheAsset file not exist or not force', url, localPath);
90
- xhr = new XMLHttpRequest();
91
- xhr.open('GET', url, true);
92
- xhr.responseType = 'arraybuffer';
93
- xhr.onload = function () { return __awaiter(_this, void 0, void 0, function () {
94
- return __generator(this, function (_a) {
95
- if (xhr.status === 200) {
96
- console.log('cacheAsset xhr statue=200', url, localPath);
97
- // let buf = Buffer.from(xhr.response, 'binary').buffer;
98
- if (localPath) {
99
- OPLib.saveToFile(localPath, xhr.response);
100
- resolve(localPath);
101
- }
102
- else {
103
- reject(url);
104
- }
105
- }
106
- else {
107
- console.warn('cacheAsset xhr statue!=200', xhr.status);
108
- if (retryTimes > 0) {
109
- console.log('retry cacheAsset', retryTimes);
110
- assetCache.cache(url, force, retryTimes - 1).then(resolve, reject);
111
- }
112
- else {
113
- reject(url);
114
- }
115
- }
116
- return [2 /*return*/];
117
- });
118
- }); };
119
- xhr.onerror = function () {
120
- console.warn('cacheAsset XHR error', xhr.status);
102
+ else {
103
+ console.warn('cacheAsset xhr statue!=200', xhr.status);
121
104
  if (retryTimes > 0) {
122
105
  console.log('retry cacheAsset', retryTimes);
123
106
  assetCache.cache(url, force, retryTimes - 1).then(resolve, reject);
@@ -125,15 +108,46 @@ export var assetCache;
125
108
  else {
126
109
  reject(url);
127
110
  }
128
- };
129
- xhr.send();
111
+ }
130
112
  return [2 /*return*/];
131
- }
113
+ });
114
+ }); };
115
+ xhr.onerror = function () {
116
+ console.warn('cacheAsset XHR error', xhr.status);
117
+ if (retryTimes > 0) {
118
+ console.log('retry cacheAsset', retryTimes);
119
+ assetCache.cache(url, force, retryTimes - 1).then(resolve, reject);
120
+ }
121
+ else {
122
+ reject(url);
123
+ }
124
+ };
125
+ xhr.send();
126
+ return [2 /*return*/];
132
127
  });
133
128
  }); })];
134
129
  });
135
130
  });
136
131
  };
132
+ assetCache.getCachePath = function (url) {
133
+ console.log('getCachePath', url);
134
+ if (!isJssdkEnv) {
135
+ console.log('非jssdk环境');
136
+ return '';
137
+ }
138
+ var urlWithoutParams = url.split('?')[0];
139
+ var localPath = getLocalPath(urlWithoutParams);
140
+ if (!localPath) {
141
+ console.log('getLocalPath failed');
142
+ return '';
143
+ }
144
+ if (OPLib.fileExists(localPath)) {
145
+ console.log('getCachePath success', localPath);
146
+ return localPath;
147
+ }
148
+ console.log('getCachePath failed', localPath);
149
+ return '';
150
+ };
137
151
  /**
138
152
  *
139
153
  * @param url 资源url
@@ -179,17 +193,14 @@ export var assetCache;
179
193
  xhr.send();
180
194
  });
181
195
  };
182
- var getLocalPath = function (url) { return __awaiter(_this, void 0, void 0, function () {
183
- var filePath, fileName;
184
- return __generator(this, function (_a) {
185
- console.log('getLocalPath', url);
186
- filePath = path.join(OPLib.getCachePath(), 'assetcache');
187
- //检查assetcache文件夹
188
- if (!OPLib.dirExists(filePath)) {
189
- OPLib.makeDir(filePath);
190
- }
191
- fileName = tools.getHashStr(assetPrefix + url) + path.extname(url);
192
- return [2 /*return*/, path.join(filePath, fileName)];
193
- });
194
- }); };
196
+ var getLocalPath = function (url) {
197
+ console.log('getLocalPath', url);
198
+ var filePath = path.join(OPLib.getCachePath() || '', 'assetcache');
199
+ //检查assetcache文件夹
200
+ if (!OPLib.dirExists(filePath)) {
201
+ OPLib.makeDir(filePath);
202
+ }
203
+ var fileName = tools.getHashStr(assetPrefix + url) + path.extname(url);
204
+ return path.join(filePath, fileName || '');
205
+ };
195
206
  })(assetCache || (assetCache = {}));