pixuireactcomponents 1.3.86 → 1.3.88
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
|
@@ -37,21 +37,30 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
import { GameletAPI } from 'gamelet-pixui-frame';
|
|
38
38
|
import path from 'path';
|
|
39
39
|
import { tools } from './tools';
|
|
40
|
-
import { LibMgr } from '../../../lib/loadlib/lib_mgr';
|
|
40
|
+
// import { LibMgr } from '../../../lib/loadlib/lib_mgr';
|
|
41
41
|
var assetPrefix = 'cacheAsset';
|
|
42
42
|
var isJssdkEnv = function () {
|
|
43
43
|
return GameletAPI.getRuntimeEnv() == 'jssdk-appwindow' || GameletAPI.getRuntimeEnv() == 'jssdk-preprocessor';
|
|
44
44
|
};
|
|
45
45
|
//动态导入lib_mgr
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
46
|
+
var getLibMgr = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
47
|
+
var module_1, error_1;
|
|
48
|
+
return __generator(this, function (_a) {
|
|
49
|
+
switch (_a.label) {
|
|
50
|
+
case 0:
|
|
51
|
+
_a.trys.push([0, 2, , 3]);
|
|
52
|
+
return [4 /*yield*/, import('../../../lib/loadlib/lib_mgr')];
|
|
53
|
+
case 1:
|
|
54
|
+
module_1 = _a.sent();
|
|
55
|
+
return [2 /*return*/, module_1.LibMgr];
|
|
56
|
+
case 2:
|
|
57
|
+
error_1 = _a.sent();
|
|
58
|
+
console.error('need puerts env', error_1);
|
|
59
|
+
return [2 /*return*/, null];
|
|
60
|
+
case 3: return [2 /*return*/];
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}); };
|
|
55
64
|
/**
|
|
56
65
|
* 缓存资源到本地,仅jssdk环境可用
|
|
57
66
|
*/
|
|
@@ -71,7 +80,7 @@ export var assetCache;
|
|
|
71
80
|
return __generator(this, function (_a) {
|
|
72
81
|
console.log('cacheAsset---', url);
|
|
73
82
|
return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
74
|
-
var urlWithoutParams, lib, localPath, xhr;
|
|
83
|
+
var urlWithoutParams, LibMgr, lib, localPath, xhr;
|
|
75
84
|
var _this = this;
|
|
76
85
|
return __generator(this, function (_a) {
|
|
77
86
|
switch (_a.label) {
|
|
@@ -81,10 +90,23 @@ export var assetCache;
|
|
|
81
90
|
reject(url);
|
|
82
91
|
}
|
|
83
92
|
urlWithoutParams = url.split('?')[0];
|
|
93
|
+
return [4 /*yield*/, getLibMgr()];
|
|
94
|
+
case 1:
|
|
95
|
+
LibMgr = _a.sent();
|
|
96
|
+
if (!LibMgr) {
|
|
97
|
+
console.log('getLibMgr failed');
|
|
98
|
+
reject();
|
|
99
|
+
return [2 /*return*/];
|
|
100
|
+
}
|
|
84
101
|
lib = LibMgr.getInstance().getMainLib();
|
|
85
102
|
return [4 /*yield*/, getLocalPath(urlWithoutParams)];
|
|
86
|
-
case
|
|
103
|
+
case 2:
|
|
87
104
|
localPath = _a.sent();
|
|
105
|
+
if (!localPath) {
|
|
106
|
+
console.log('getLocalPath failed');
|
|
107
|
+
reject();
|
|
108
|
+
return [2 /*return*/];
|
|
109
|
+
}
|
|
88
110
|
console.log('cacheAsset getlocalPath', localPath);
|
|
89
111
|
if (!force) {
|
|
90
112
|
if (lib.fileExists(localPath)) {
|
|
@@ -101,8 +123,13 @@ export var assetCache;
|
|
|
101
123
|
if (xhr.status === 200) {
|
|
102
124
|
console.log('cacheAsset xhr statue=200', url, localPath);
|
|
103
125
|
// let buf = Buffer.from(xhr.response, 'binary').buffer;
|
|
104
|
-
|
|
105
|
-
|
|
126
|
+
if (localPath) {
|
|
127
|
+
lib.saveToFile(localPath, xhr.response);
|
|
128
|
+
resolve(localPath);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
reject(url);
|
|
132
|
+
}
|
|
106
133
|
}
|
|
107
134
|
else {
|
|
108
135
|
console.warn('cacheAsset xhr statue!=200', xhr.status);
|
|
@@ -181,17 +208,27 @@ export var assetCache;
|
|
|
181
208
|
});
|
|
182
209
|
};
|
|
183
210
|
var getLocalPath = function (url) { return __awaiter(_this, void 0, void 0, function () {
|
|
184
|
-
var lib, filePath, fileName;
|
|
211
|
+
var LibMgr, lib, filePath, fileName;
|
|
185
212
|
return __generator(this, function (_a) {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
213
|
+
switch (_a.label) {
|
|
214
|
+
case 0:
|
|
215
|
+
console.log('getLocalPath', url);
|
|
216
|
+
return [4 /*yield*/, getLibMgr()];
|
|
217
|
+
case 1:
|
|
218
|
+
LibMgr = _a.sent();
|
|
219
|
+
if (!LibMgr) {
|
|
220
|
+
console.log('getLibMgr failed');
|
|
221
|
+
return [2 /*return*/];
|
|
222
|
+
}
|
|
223
|
+
lib = LibMgr.getInstance().getMainLib();
|
|
224
|
+
filePath = path.join(lib.getCachePath(), 'assetcache');
|
|
225
|
+
//检查assetcache文件夹
|
|
226
|
+
if (!lib.dirExists(filePath)) {
|
|
227
|
+
lib.makeDir(filePath);
|
|
228
|
+
}
|
|
229
|
+
fileName = tools.getHashStr(assetPrefix + url) + path.extname(url);
|
|
230
|
+
return [2 /*return*/, path.join(filePath, fileName)];
|
|
192
231
|
}
|
|
193
|
-
fileName = tools.getHashStr(assetPrefix + url) + path.extname(url);
|
|
194
|
-
return [2 /*return*/, path.join(filePath, fileName)];
|
|
195
232
|
});
|
|
196
233
|
}); };
|
|
197
234
|
})(assetCache || (assetCache = {}));
|