@smart100/spu-web-plugin 1.0.15 → 1.0.16
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/dist/index.d.ts +13 -0
- package/dist/spu-web-plugin.mjs +213 -31
- package/package.json +1 -1
- package/src/index.ts +4 -0
- package/src/login.ts +1 -1
- package/src/map/MapService.ts +9 -0
- package/src/{cloudServ.ts → oss/cloudServ.ts} +8 -1
- package/src/oss/downloadService.ts +5 -4
- package/src/oss/servtoken.ts +3 -3
- package/src/oss/uploadService.ts +131 -8
- package/src/types/index.d.ts +13 -0
package/dist/index.d.ts
CHANGED
|
@@ -66,8 +66,14 @@ interface IUpload {
|
|
|
66
66
|
onprogress?: (p: number, _checkpoint?: any) => void
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
interface ICopy {
|
|
70
|
+
copykey: string
|
|
71
|
+
storagetype?: StorageType
|
|
72
|
+
}
|
|
73
|
+
|
|
69
74
|
interface IUploadService {
|
|
70
75
|
upload: (options: IUpload) => Promise<any>
|
|
76
|
+
copy: (options: ICopy) => Promise<any>
|
|
71
77
|
}
|
|
72
78
|
|
|
73
79
|
// interface ISPUWebPluginOptions {
|
|
@@ -111,6 +117,13 @@ export const spuConfig: any
|
|
|
111
117
|
export const globalConfig: any
|
|
112
118
|
export const downloadService: IDownloadService
|
|
113
119
|
export const uploadService: IUploadService
|
|
120
|
+
export const getServToken: () => Promise<{
|
|
121
|
+
accesskeyid: string
|
|
122
|
+
accesskeysecret: string
|
|
123
|
+
securitytoken: string
|
|
124
|
+
expiration: string
|
|
125
|
+
}>
|
|
126
|
+
export const getCloudServ: () => any
|
|
114
127
|
export const getUniqueid: () => string
|
|
115
128
|
export const getUuid: () => string
|
|
116
129
|
export const functionCheck: (functioncode?: string) => boolean
|
package/dist/spu-web-plugin.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var version = "1.0.
|
|
1
|
+
var version = "1.0.16";
|
|
2
2
|
|
|
3
3
|
/** Detect free variable `global` from Node.js. */
|
|
4
4
|
var freeGlobal$2 = typeof global == 'object' && global && global.Object === Object && global;
|
|
@@ -8606,6 +8606,7 @@ var CloudServ = /*#__PURE__*/function () {
|
|
|
8606
8606
|
return CloudServ;
|
|
8607
8607
|
}();
|
|
8608
8608
|
var cloudServ = new CloudServ();
|
|
8609
|
+
var getCloudServ = cloudServ.get.bind(cloudServ);
|
|
8609
8610
|
|
|
8610
8611
|
var cryptoJs = {exports: {}};
|
|
8611
8612
|
|
|
@@ -17210,7 +17211,7 @@ var MapService = /*#__PURE__*/function () {
|
|
|
17210
17211
|
key = this.key;
|
|
17211
17212
|
secretkey = this.secretkey;
|
|
17212
17213
|
if (!(type === 'tencent')) {
|
|
17213
|
-
_context2.next =
|
|
17214
|
+
_context2.next = 14;
|
|
17214
17215
|
break;
|
|
17215
17216
|
}
|
|
17216
17217
|
if (!(!key || !secretkey)) {
|
|
@@ -17220,45 +17221,54 @@ var MapService = /*#__PURE__*/function () {
|
|
|
17220
17221
|
console.error('请填写腾讯地图 Web App Key 和 Web Secret Key');
|
|
17221
17222
|
return _context2.abrupt("return");
|
|
17222
17223
|
case 7:
|
|
17223
|
-
|
|
17224
|
+
console.log('当前使用腾讯地图');
|
|
17225
|
+
console.log("Web App Key: ".concat(key));
|
|
17226
|
+
console.log("Web Secret Key: ".concat(secretkey));
|
|
17227
|
+
_context2.next = 12;
|
|
17224
17228
|
return this.initTecent();
|
|
17225
|
-
case
|
|
17226
|
-
_context2.next =
|
|
17229
|
+
case 12:
|
|
17230
|
+
_context2.next = 34;
|
|
17227
17231
|
break;
|
|
17228
|
-
case
|
|
17232
|
+
case 14:
|
|
17229
17233
|
if (!(type === 'amap')) {
|
|
17230
|
-
_context2.next =
|
|
17234
|
+
_context2.next = 25;
|
|
17231
17235
|
break;
|
|
17232
17236
|
}
|
|
17233
17237
|
if (!(!key || !secretkey)) {
|
|
17234
|
-
_context2.next =
|
|
17238
|
+
_context2.next = 18;
|
|
17235
17239
|
break;
|
|
17236
17240
|
}
|
|
17237
17241
|
console.error('请填写高德地图 Web App Key 和 Web Secret Key');
|
|
17238
17242
|
return _context2.abrupt("return");
|
|
17239
|
-
case
|
|
17240
|
-
|
|
17243
|
+
case 18:
|
|
17244
|
+
console.log('当前使用高德地图');
|
|
17245
|
+
console.log("Web App Key: ".concat(key));
|
|
17246
|
+
console.log("Web Secret Key: ".concat(secretkey));
|
|
17247
|
+
_context2.next = 23;
|
|
17241
17248
|
return this.initAmap();
|
|
17242
|
-
case
|
|
17243
|
-
_context2.next =
|
|
17249
|
+
case 23:
|
|
17250
|
+
_context2.next = 34;
|
|
17244
17251
|
break;
|
|
17245
|
-
case
|
|
17252
|
+
case 25:
|
|
17246
17253
|
if (!(type === 'baidu')) {
|
|
17247
|
-
_context2.next =
|
|
17254
|
+
_context2.next = 34;
|
|
17248
17255
|
break;
|
|
17249
17256
|
}
|
|
17250
17257
|
if (key) {
|
|
17251
|
-
_context2.next =
|
|
17258
|
+
_context2.next = 29;
|
|
17252
17259
|
break;
|
|
17253
17260
|
}
|
|
17254
17261
|
console.error('请填写百度地图 Web App Key');
|
|
17255
17262
|
return _context2.abrupt("return");
|
|
17256
|
-
case
|
|
17257
|
-
|
|
17263
|
+
case 29:
|
|
17264
|
+
console.log('当前使用百度地图');
|
|
17265
|
+
console.log("Web App Key: ".concat(key));
|
|
17266
|
+
console.log("Web Secret Key: ".concat(secretkey));
|
|
17267
|
+
_context2.next = 34;
|
|
17258
17268
|
return this.initBaidu();
|
|
17259
|
-
case
|
|
17269
|
+
case 34:
|
|
17260
17270
|
this.isInit = true;
|
|
17261
|
-
case
|
|
17271
|
+
case 35:
|
|
17262
17272
|
case "end":
|
|
17263
17273
|
return _context2.stop();
|
|
17264
17274
|
}
|
|
@@ -51809,7 +51819,7 @@ var last = 0;
|
|
|
51809
51819
|
var servtoken = null;
|
|
51810
51820
|
var isGetting = false;
|
|
51811
51821
|
var xhr = null;
|
|
51812
|
-
var
|
|
51822
|
+
var requestServToken = /*#__PURE__*/function () {
|
|
51813
51823
|
var _ref = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee() {
|
|
51814
51824
|
var response;
|
|
51815
51825
|
return _regeneratorRuntime$1().wrap(function _callee$(_context) {
|
|
@@ -51833,11 +51843,11 @@ var getServToken = /*#__PURE__*/function () {
|
|
|
51833
51843
|
}
|
|
51834
51844
|
}, _callee, null, [[0, 7]]);
|
|
51835
51845
|
}));
|
|
51836
|
-
return function
|
|
51846
|
+
return function requestServToken() {
|
|
51837
51847
|
return _ref.apply(this, arguments);
|
|
51838
51848
|
};
|
|
51839
51849
|
}();
|
|
51840
|
-
var
|
|
51850
|
+
var getServToken = function getServToken() {
|
|
51841
51851
|
return new Promise(function (resolve, reject) {
|
|
51842
51852
|
// 在请求中,排队列
|
|
51843
51853
|
if (isGetting && xhr) {
|
|
@@ -51864,7 +51874,7 @@ var initServToken = function initServToken() {
|
|
|
51864
51874
|
if (!last || last - Date.now() < 1000 * 60 * 5) {
|
|
51865
51875
|
// 过期了 重新请求
|
|
51866
51876
|
isGetting = true;
|
|
51867
|
-
xhr =
|
|
51877
|
+
xhr = requestServToken();
|
|
51868
51878
|
xhr.then(function (res) {
|
|
51869
51879
|
servtoken = res;
|
|
51870
51880
|
last = new Date(res.expiration).getTime();
|
|
@@ -51974,7 +51984,7 @@ var getUrl = /*#__PURE__*/function () {
|
|
|
51974
51984
|
throw Error('无可用存储设置');
|
|
51975
51985
|
case 4:
|
|
51976
51986
|
_context.next = 6;
|
|
51977
|
-
return
|
|
51987
|
+
return getServToken();
|
|
51978
51988
|
case 6:
|
|
51979
51989
|
servToken = _context.sent;
|
|
51980
51990
|
if (servToken) {
|
|
@@ -52056,7 +52066,8 @@ var getUrl = /*#__PURE__*/function () {
|
|
|
52056
52066
|
res = obs.createSignedUrlSync(Params);
|
|
52057
52067
|
signedUrl = res.SignedUrl; // const expires = get(qs.parse(signedUrl), 'Expires') as string
|
|
52058
52068
|
// if (expires) setCacheUrl(cacheKey, signedUrl, +expires)
|
|
52059
|
-
|
|
52069
|
+
// 华为云通过 createSignedUrlSync 生产的签名链接默认带有 :80 或者 :443 端口 后端删除时需要去除
|
|
52070
|
+
return _context.abrupt("return", signedUrl.replace(/:(80|443)/, ''));
|
|
52060
52071
|
case 37:
|
|
52061
52072
|
_context.prev = 37;
|
|
52062
52073
|
_context.t0 = _context["catch"](29);
|
|
@@ -52669,7 +52680,7 @@ var upload = /*#__PURE__*/function () {
|
|
|
52669
52680
|
throw Error('无可用存储设置');
|
|
52670
52681
|
case 6:
|
|
52671
52682
|
_context4.next = 8;
|
|
52672
|
-
return
|
|
52683
|
+
return getServToken();
|
|
52673
52684
|
case 8:
|
|
52674
52685
|
servToken = _context4.sent;
|
|
52675
52686
|
if (servToken) {
|
|
@@ -52727,9 +52738,10 @@ var upload = /*#__PURE__*/function () {
|
|
|
52727
52738
|
onprogress && onprogress(p, _checkpoint);
|
|
52728
52739
|
if (p === 1) {
|
|
52729
52740
|
resolve({
|
|
52741
|
+
key: osskey,
|
|
52730
52742
|
source: source,
|
|
52731
52743
|
filename: file.name,
|
|
52732
|
-
type:
|
|
52744
|
+
type: type,
|
|
52733
52745
|
date: date,
|
|
52734
52746
|
datetime: datetime,
|
|
52735
52747
|
storage: storagetype,
|
|
@@ -52784,9 +52796,10 @@ var upload = /*#__PURE__*/function () {
|
|
|
52784
52796
|
uploadRes = _context3.sent;
|
|
52785
52797
|
if (uploadRes) {
|
|
52786
52798
|
resolve({
|
|
52799
|
+
key: osskey,
|
|
52787
52800
|
source: source,
|
|
52788
52801
|
filename: file.name,
|
|
52789
|
-
type:
|
|
52802
|
+
type: type,
|
|
52790
52803
|
date: date,
|
|
52791
52804
|
datetime: datetime,
|
|
52792
52805
|
storage: storagetype,
|
|
@@ -52840,7 +52853,7 @@ var upload = /*#__PURE__*/function () {
|
|
|
52840
52853
|
key: osskey,
|
|
52841
52854
|
source: source,
|
|
52842
52855
|
filename: file.name,
|
|
52843
|
-
type:
|
|
52856
|
+
type: type,
|
|
52844
52857
|
date: date,
|
|
52845
52858
|
datetime: datetime,
|
|
52846
52859
|
storage: storagetype,
|
|
@@ -52873,8 +52886,177 @@ var upload = /*#__PURE__*/function () {
|
|
|
52873
52886
|
return _ref2.apply(this, arguments);
|
|
52874
52887
|
};
|
|
52875
52888
|
}();
|
|
52889
|
+
var createTargetObj = function createTargetObj(copykey) {
|
|
52890
|
+
var storagetype = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'storage';
|
|
52891
|
+
var uuid = v4();
|
|
52892
|
+
var datetime = Date.now().toString();
|
|
52893
|
+
var date = dayjs(Number(datetime)).format('YYYYMMDD');
|
|
52894
|
+
var arr = copykey.split('/');
|
|
52895
|
+
arr[0] = uuid.slice(0, 3);
|
|
52896
|
+
arr[2] = date;
|
|
52897
|
+
var arr2 = arr[arr.length - 1].split('.');
|
|
52898
|
+
var ext = arr2[arr2.length - 1];
|
|
52899
|
+
arr[arr.length - 1] = "".concat(uuid, ".").concat(ext);
|
|
52900
|
+
return {
|
|
52901
|
+
key: arr.join('/'),
|
|
52902
|
+
source: arr[arr.length - 1],
|
|
52903
|
+
datetime: datetime,
|
|
52904
|
+
date: date,
|
|
52905
|
+
type: arr[1],
|
|
52906
|
+
storage: storagetype
|
|
52907
|
+
};
|
|
52908
|
+
};
|
|
52909
|
+
var copy = /*#__PURE__*/function () {
|
|
52910
|
+
var _ref5 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee5(_ref4) {
|
|
52911
|
+
var _ref4$copykey, copykey, _ref4$storagetype, storagetype, storageConfig, servToken, provider, targetObj;
|
|
52912
|
+
return _regeneratorRuntime$1().wrap(function _callee5$(_context6) {
|
|
52913
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
52914
|
+
case 0:
|
|
52915
|
+
_ref4$copykey = _ref4.copykey, copykey = _ref4$copykey === void 0 ? '' : _ref4$copykey, _ref4$storagetype = _ref4.storagetype, storagetype = _ref4$storagetype === void 0 ? 'storage' : _ref4$storagetype;
|
|
52916
|
+
storageConfig = cloudServ.get(storagetype);
|
|
52917
|
+
if (storageConfig) {
|
|
52918
|
+
_context6.next = 4;
|
|
52919
|
+
break;
|
|
52920
|
+
}
|
|
52921
|
+
throw Error('无可用存储设置');
|
|
52922
|
+
case 4:
|
|
52923
|
+
_context6.next = 6;
|
|
52924
|
+
return getServToken();
|
|
52925
|
+
case 6:
|
|
52926
|
+
servToken = _context6.sent;
|
|
52927
|
+
if (servToken) {
|
|
52928
|
+
_context6.next = 9;
|
|
52929
|
+
break;
|
|
52930
|
+
}
|
|
52931
|
+
throw Error('无可用servToken');
|
|
52932
|
+
case 9:
|
|
52933
|
+
provider = cloudServ.getProvider(storagetype);
|
|
52934
|
+
targetObj = createTargetObj(copykey, storagetype);
|
|
52935
|
+
return _context6.abrupt("return", new Promise( /*#__PURE__*/function () {
|
|
52936
|
+
var _ref6 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee4(resolve, reject) {
|
|
52937
|
+
var ossClient, obs, s3;
|
|
52938
|
+
return _regeneratorRuntime$1().wrap(function _callee4$(_context5) {
|
|
52939
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
52940
|
+
case 0:
|
|
52941
|
+
if (!(provider !== null && provider !== void 0 && provider.isAliyun)) {
|
|
52942
|
+
_context5.next = 5;
|
|
52943
|
+
break;
|
|
52944
|
+
}
|
|
52945
|
+
ossClient = new AliClient({
|
|
52946
|
+
// region: cloudServ.cloudserv_storage_storageendpoint,
|
|
52947
|
+
endpoint: storageConfig.cloudserv_storage_storageendpoint,
|
|
52948
|
+
accessKeyId: servToken.accesskeyid,
|
|
52949
|
+
accessKeySecret: servToken.accesskeysecret,
|
|
52950
|
+
stsToken: servToken.securitytoken,
|
|
52951
|
+
bucket: storageConfig.cloudserv_storage_storagebucket,
|
|
52952
|
+
secure: true
|
|
52953
|
+
// sldEnable: true // 二级域名,ip地址
|
|
52954
|
+
});
|
|
52955
|
+
|
|
52956
|
+
co$1(ossClient.copy(targetObj.key, copykey)).then(function (res) {
|
|
52957
|
+
var _res$res, _res$data;
|
|
52958
|
+
// console.log(res)
|
|
52959
|
+
// debugger
|
|
52960
|
+
// resolve(targetObj)
|
|
52961
|
+
if ((res === null || res === void 0 || (_res$res = res.res) === null || _res$res === void 0 ? void 0 : _res$res.status) === 200 && res !== null && res !== void 0 && (_res$data = res.data) !== null && _res$data !== void 0 && _res$data.etag) {
|
|
52962
|
+
resolve(targetObj);
|
|
52963
|
+
} else {
|
|
52964
|
+
console.error(res);
|
|
52965
|
+
reject(res);
|
|
52966
|
+
}
|
|
52967
|
+
})["catch"](function (e) {
|
|
52968
|
+
console.error(e);
|
|
52969
|
+
// debugger
|
|
52970
|
+
reject(e);
|
|
52971
|
+
});
|
|
52972
|
+
_context5.next = 16;
|
|
52973
|
+
break;
|
|
52974
|
+
case 5:
|
|
52975
|
+
if (!(provider !== null && provider !== void 0 && provider.isHuawei)) {
|
|
52976
|
+
_context5.next = 10;
|
|
52977
|
+
break;
|
|
52978
|
+
}
|
|
52979
|
+
obs = new ObsClient({
|
|
52980
|
+
access_key_id: servToken.accesskeyid,
|
|
52981
|
+
secret_access_key: servToken.accesskeysecret,
|
|
52982
|
+
server: storageConfig.cloudserv_storage_storageendpoint,
|
|
52983
|
+
security_token: servToken.securitytoken
|
|
52984
|
+
});
|
|
52985
|
+
obs.copyObject({
|
|
52986
|
+
Bucket: storageConfig.cloudserv_storage_storagebucket,
|
|
52987
|
+
Key: targetObj.key,
|
|
52988
|
+
CopySource: "".concat(storageConfig.cloudserv_storage_storagebucket, "/").concat(copykey)
|
|
52989
|
+
}).then(function (res) {
|
|
52990
|
+
var _res$CommonMsg;
|
|
52991
|
+
if ((res === null || res === void 0 || (_res$CommonMsg = res.CommonMsg) === null || _res$CommonMsg === void 0 ? void 0 : _res$CommonMsg.Status) === 200 && res !== null && res !== void 0 && res.InterfaceResult) {
|
|
52992
|
+
resolve(targetObj);
|
|
52993
|
+
} else {
|
|
52994
|
+
console.error(res);
|
|
52995
|
+
reject(res);
|
|
52996
|
+
}
|
|
52997
|
+
})["catch"](function (e) {
|
|
52998
|
+
console.error(e);
|
|
52999
|
+
reject(e);
|
|
53000
|
+
});
|
|
53001
|
+
_context5.next = 16;
|
|
53002
|
+
break;
|
|
53003
|
+
case 10:
|
|
53004
|
+
if (!(provider !== null && provider !== void 0 && provider.isMinio || provider !== null && provider !== void 0 && provider.isAwss3)) {
|
|
53005
|
+
_context5.next = 15;
|
|
53006
|
+
break;
|
|
53007
|
+
}
|
|
53008
|
+
// debugger
|
|
53009
|
+
// debugger
|
|
53010
|
+
s3 = new S3Client({
|
|
53011
|
+
accessKeyId: servToken.accesskeyid,
|
|
53012
|
+
secretAccessKey: servToken.accesskeysecret,
|
|
53013
|
+
sessionToken: servToken.securitytoken,
|
|
53014
|
+
region: storageConfig.cloudserv_storage_region,
|
|
53015
|
+
endpoint: storageConfig.cloudserv_storage_storageendpoint,
|
|
53016
|
+
signatureVersion: 'v4',
|
|
53017
|
+
s3ForcePathStyle: provider !== null && provider !== void 0 && provider.isMinio ? true : undefined
|
|
53018
|
+
}); // console.log(s3)
|
|
53019
|
+
// debugger
|
|
53020
|
+
s3.copyObject({
|
|
53021
|
+
Bucket: storageConfig.cloudserv_storage_storagebucket,
|
|
53022
|
+
CopySource: "".concat(storageConfig.cloudserv_storage_storagebucket, "/").concat(copykey),
|
|
53023
|
+
Key: targetObj.key
|
|
53024
|
+
}, function (err, data) {
|
|
53025
|
+
if (err) {
|
|
53026
|
+
console.error(err);
|
|
53027
|
+
reject(err);
|
|
53028
|
+
} else {
|
|
53029
|
+
// console.log(data)
|
|
53030
|
+
resolve(targetObj);
|
|
53031
|
+
}
|
|
53032
|
+
});
|
|
53033
|
+
_context5.next = 16;
|
|
53034
|
+
break;
|
|
53035
|
+
case 15:
|
|
53036
|
+
throw Error("\u6682\u4E0D\u652F\u6301".concat(provider === null || provider === void 0 ? void 0 : provider.name, "\u5B58\u50A8\u7C7B\u578B"));
|
|
53037
|
+
case 16:
|
|
53038
|
+
case "end":
|
|
53039
|
+
return _context5.stop();
|
|
53040
|
+
}
|
|
53041
|
+
}, _callee4);
|
|
53042
|
+
}));
|
|
53043
|
+
return function (_x5, _x6) {
|
|
53044
|
+
return _ref6.apply(this, arguments);
|
|
53045
|
+
};
|
|
53046
|
+
}()));
|
|
53047
|
+
case 12:
|
|
53048
|
+
case "end":
|
|
53049
|
+
return _context6.stop();
|
|
53050
|
+
}
|
|
53051
|
+
}, _callee5);
|
|
53052
|
+
}));
|
|
53053
|
+
return function copy(_x4) {
|
|
53054
|
+
return _ref5.apply(this, arguments);
|
|
53055
|
+
};
|
|
53056
|
+
}();
|
|
52876
53057
|
var uploadService = {
|
|
52877
|
-
upload: upload
|
|
53058
|
+
upload: upload,
|
|
53059
|
+
copy: copy
|
|
52878
53060
|
};
|
|
52879
53061
|
|
|
52880
53062
|
var isinit = false;
|
|
@@ -70043,4 +70225,4 @@ var SPUWebPlugin = {
|
|
|
70043
70225
|
version: version
|
|
70044
70226
|
};
|
|
70045
70227
|
|
|
70046
|
-
export { AMapLoader, Module, normalAxios$1 as apaasAxios, normalAxios$1 as axios, checkLogin, index as components, SPUWebPlugin as default, downloadService, expandexp, functionCheck, getAddress, getDistance, getLocation, getRefreshToken, getToken, getTokenExpires, getUniqueid, getUser, v4 as getUuid, globalConfig, globalOptions, isInApp, isdebugger, isvirtuallocation, lsProxy, mapService, setTitle, singleLogin, spuAxios, spuConfig, ssProxy, updateToken, uploadService, wxworkSuite };
|
|
70228
|
+
export { AMapLoader, Module, normalAxios$1 as apaasAxios, normalAxios$1 as axios, checkLogin, index as components, SPUWebPlugin as default, downloadService, expandexp, functionCheck, getAddress, getCloudServ, getDistance, getLocation, getRefreshToken, getServToken, getToken, getTokenExpires, getUniqueid, getUser, v4 as getUuid, globalConfig, globalOptions, isInApp, isdebugger, isvirtuallocation, lsProxy, mapService, setTitle, singleLogin, spuAxios, spuConfig, ssProxy, updateToken, uploadService, wxworkSuite };
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -7,6 +7,8 @@ import { installAxios, spuAxios, axios } from './axios'
|
|
|
7
7
|
import { installSpuConfig, spuConfig } from './spuConfig'
|
|
8
8
|
import { globalConfig } from './globalConfig'
|
|
9
9
|
import { downloadService, uploadService } from './oss'
|
|
10
|
+
import { getServToken } from './oss/servtoken'
|
|
11
|
+
import { getCloudServ } from './oss/cloudServ'
|
|
10
12
|
import { getUniqueid, functionCheck, setTitle, isInApp, isdebugger, isvirtuallocation } from './utils'
|
|
11
13
|
import { installUrlquery } from './urlquery'
|
|
12
14
|
import { mapService } from './map/MapService'
|
|
@@ -109,6 +111,8 @@ export {
|
|
|
109
111
|
globalConfig,
|
|
110
112
|
downloadService,
|
|
111
113
|
uploadService,
|
|
114
|
+
getServToken,
|
|
115
|
+
getCloudServ,
|
|
112
116
|
getUniqueid,
|
|
113
117
|
getUuid,
|
|
114
118
|
functionCheck,
|
package/src/login.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { get, cloneDeep } from 'lodash-es'
|
|
|
2
2
|
import jwtDecode from 'jwt-decode'
|
|
3
3
|
import { lsProxy } from './storageProxy'
|
|
4
4
|
import { axios } from './axios'
|
|
5
|
-
import cloudServ from './cloudServ'
|
|
5
|
+
import cloudServ from './oss/cloudServ'
|
|
6
6
|
import core from './core'
|
|
7
7
|
import { urlquery } from './urlquery'
|
|
8
8
|
import { getData, setData, removeData } from './storageCache'
|
package/src/map/MapService.ts
CHANGED
|
@@ -108,18 +108,27 @@ class MapService {
|
|
|
108
108
|
console.error('请填写腾讯地图 Web App Key 和 Web Secret Key')
|
|
109
109
|
return
|
|
110
110
|
}
|
|
111
|
+
console.log('当前使用腾讯地图')
|
|
112
|
+
console.log(`Web App Key: ${key}`)
|
|
113
|
+
console.log(`Web Secret Key: ${secretkey}`)
|
|
111
114
|
await this.initTecent()
|
|
112
115
|
} else if (type === 'amap') {
|
|
113
116
|
if (!key || !secretkey) {
|
|
114
117
|
console.error('请填写高德地图 Web App Key 和 Web Secret Key')
|
|
115
118
|
return
|
|
116
119
|
}
|
|
120
|
+
console.log('当前使用高德地图')
|
|
121
|
+
console.log(`Web App Key: ${key}`)
|
|
122
|
+
console.log(`Web Secret Key: ${secretkey}`)
|
|
117
123
|
await this.initAmap()
|
|
118
124
|
} else if (type === 'baidu') {
|
|
119
125
|
if (!key) {
|
|
120
126
|
console.error('请填写百度地图 Web App Key')
|
|
121
127
|
return
|
|
122
128
|
}
|
|
129
|
+
console.log('当前使用百度地图')
|
|
130
|
+
console.log(`Web App Key: ${key}`)
|
|
131
|
+
console.log(`Web Secret Key: ${secretkey}`)
|
|
123
132
|
await this.initBaidu()
|
|
124
133
|
}
|
|
125
134
|
this.isInit = true
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { lsProxy } from '
|
|
1
|
+
import { lsProxy } from '../storageProxy'
|
|
2
2
|
|
|
3
3
|
class CloudServ {
|
|
4
4
|
CLOUD_SERVE_KEY = 'cloudserv'
|
|
@@ -49,4 +49,11 @@ class CloudServ {
|
|
|
49
49
|
|
|
50
50
|
const cloudServ = new CloudServ()
|
|
51
51
|
|
|
52
|
+
|
|
53
|
+
const getCloudServ = cloudServ.get.bind(cloudServ)
|
|
54
|
+
|
|
52
55
|
export default cloudServ
|
|
56
|
+
|
|
57
|
+
export {
|
|
58
|
+
getCloudServ
|
|
59
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AliClient, ObsClient, S3Client } from './OSSClient'
|
|
2
2
|
import dayjs from 'dayjs'
|
|
3
|
-
import cloudServ from '
|
|
4
|
-
import {
|
|
3
|
+
import cloudServ from './cloudServ'
|
|
4
|
+
import { getServToken } from './servtoken'
|
|
5
5
|
import { axios } from '../axios'
|
|
6
6
|
import { getUser } from '../login'
|
|
7
7
|
// import { get } from 'lodash-es'
|
|
@@ -130,7 +130,7 @@ const getUrl = async ({
|
|
|
130
130
|
}: IDownload) => {
|
|
131
131
|
const storageConfig = cloudServ.get(storagetype)
|
|
132
132
|
if (!storageConfig) throw Error('无可用存储设置')
|
|
133
|
-
const servToken = await
|
|
133
|
+
const servToken = await getServToken()
|
|
134
134
|
if (!servToken) throw Error('无可用servToken')
|
|
135
135
|
|
|
136
136
|
const tenantCode = getUser('tenantcode')
|
|
@@ -210,7 +210,8 @@ const getUrl = async ({
|
|
|
210
210
|
// const expires = get(qs.parse(signedUrl), 'Expires') as string
|
|
211
211
|
// if (expires) setCacheUrl(cacheKey, signedUrl, +expires)
|
|
212
212
|
|
|
213
|
-
|
|
213
|
+
// 华为云通过 createSignedUrlSync 生产的签名链接默认带有 :80 或者 :443 端口 后端删除时需要去除
|
|
214
|
+
return signedUrl.replace(/:(80|443)/, '')
|
|
214
215
|
} catch (e: any) {
|
|
215
216
|
console.error(e)
|
|
216
217
|
throw Error(e)
|
package/src/oss/servtoken.ts
CHANGED
|
@@ -18,7 +18,7 @@ let servtoken: ServToken | null = null
|
|
|
18
18
|
let isGetting = false
|
|
19
19
|
let xhr: Promise<ServToken> | null = null
|
|
20
20
|
|
|
21
|
-
const
|
|
21
|
+
const requestServToken = async () => {
|
|
22
22
|
try {
|
|
23
23
|
const response: ServToken = await axios.get('/api/teapi/auth/servtoken').then((res: any) => res.data)
|
|
24
24
|
// debugger
|
|
@@ -28,7 +28,7 @@ const getServToken = async () => {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
export const
|
|
31
|
+
export const getServToken = () => {
|
|
32
32
|
return new Promise<ServToken>((resolve, reject) => {
|
|
33
33
|
// 在请求中,排队列
|
|
34
34
|
if (isGetting && xhr) {
|
|
@@ -57,7 +57,7 @@ export const initServToken = () => {
|
|
|
57
57
|
if (!last || last - Date.now() < 1000 * 60 * 5) {
|
|
58
58
|
// 过期了 重新请求
|
|
59
59
|
isGetting = true
|
|
60
|
-
xhr =
|
|
60
|
+
xhr = requestServToken()
|
|
61
61
|
xhr
|
|
62
62
|
.then((res) => {
|
|
63
63
|
servtoken = res
|
package/src/oss/uploadService.ts
CHANGED
|
@@ -2,10 +2,9 @@ import { AliClient, ObsClient, S3Client } from './OSSClient'
|
|
|
2
2
|
import { v4 as uuidv4 } from 'uuid'
|
|
3
3
|
import dayjs from 'dayjs'
|
|
4
4
|
import co from 'co'
|
|
5
|
-
|
|
6
5
|
import { getUser } from '../login'
|
|
7
|
-
import cloudServ from '
|
|
8
|
-
import {
|
|
6
|
+
import cloudServ from './cloudServ'
|
|
7
|
+
import { getServToken } from './servtoken'
|
|
9
8
|
import { obsMultiUpload } from './multiUpload'
|
|
10
9
|
|
|
11
10
|
interface IUpload {
|
|
@@ -28,7 +27,7 @@ const upload = async ({
|
|
|
28
27
|
if (!file) throw Error('请传入文件')
|
|
29
28
|
const storageConfig = cloudServ.get(storagetype)
|
|
30
29
|
if (!storageConfig) throw Error('无可用存储设置')
|
|
31
|
-
const servToken = await
|
|
30
|
+
const servToken = await getServToken()
|
|
32
31
|
if (!servToken) throw Error('无可用servToken')
|
|
33
32
|
|
|
34
33
|
const provider = cloudServ.getProvider(storagetype)
|
|
@@ -66,9 +65,10 @@ const upload = async ({
|
|
|
66
65
|
onprogress && onprogress(p, _checkpoint)
|
|
67
66
|
if (p === 1) {
|
|
68
67
|
resolve({
|
|
68
|
+
key: osskey,
|
|
69
69
|
source,
|
|
70
70
|
filename: file.name,
|
|
71
|
-
type:
|
|
71
|
+
type: type,
|
|
72
72
|
date: date,
|
|
73
73
|
datetime: datetime,
|
|
74
74
|
storage: storagetype,
|
|
@@ -105,9 +105,10 @@ const upload = async ({
|
|
|
105
105
|
})
|
|
106
106
|
if (uploadRes) {
|
|
107
107
|
resolve({
|
|
108
|
+
key: osskey,
|
|
108
109
|
source,
|
|
109
110
|
filename: file.name,
|
|
110
|
-
type:
|
|
111
|
+
type: type,
|
|
111
112
|
date: date,
|
|
112
113
|
datetime: datetime,
|
|
113
114
|
storage: storagetype,
|
|
@@ -161,7 +162,7 @@ const upload = async ({
|
|
|
161
162
|
key: osskey,
|
|
162
163
|
source,
|
|
163
164
|
filename: file.name,
|
|
164
|
-
type:
|
|
165
|
+
type: type,
|
|
165
166
|
date: date,
|
|
166
167
|
datetime: datetime,
|
|
167
168
|
storage: storagetype,
|
|
@@ -177,6 +178,128 @@ const upload = async ({
|
|
|
177
178
|
return promise
|
|
178
179
|
}
|
|
179
180
|
|
|
181
|
+
|
|
182
|
+
const createTargetObj = (copykey: string, storagetype: StorageType = 'storage') => {
|
|
183
|
+
const uuid = uuidv4()
|
|
184
|
+
const datetime = Date.now().toString()
|
|
185
|
+
const date = dayjs(Number(datetime)).format('YYYYMMDD')
|
|
186
|
+
const arr = copykey.split('/')
|
|
187
|
+
arr[0] = uuid.slice(0, 3)
|
|
188
|
+
arr[2] = date
|
|
189
|
+
const arr2 = arr[arr.length - 1].split('.')
|
|
190
|
+
const ext = arr2[arr2.length - 1]
|
|
191
|
+
arr[arr.length - 1] = `${uuid}.${ext}`
|
|
192
|
+
return {
|
|
193
|
+
key: arr.join('/'),
|
|
194
|
+
source: arr[arr.length - 1],
|
|
195
|
+
datetime,
|
|
196
|
+
date,
|
|
197
|
+
type: arr[1],
|
|
198
|
+
storage: storagetype,
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const copy = async ({
|
|
203
|
+
copykey = '',
|
|
204
|
+
storagetype = 'storage'
|
|
205
|
+
}: any) => {
|
|
206
|
+
const storageConfig = cloudServ.get(storagetype)
|
|
207
|
+
if (!storageConfig) throw Error('无可用存储设置')
|
|
208
|
+
const servToken = await getServToken()
|
|
209
|
+
if (!servToken) throw Error('无可用servToken')
|
|
210
|
+
|
|
211
|
+
const provider = cloudServ.getProvider(storagetype)
|
|
212
|
+
const targetObj = createTargetObj(copykey, storagetype)
|
|
213
|
+
|
|
214
|
+
return new Promise(async (resolve, reject) => {
|
|
215
|
+
if (provider?.isAliyun) {
|
|
216
|
+
const ossClient = new AliClient({
|
|
217
|
+
// region: cloudServ.cloudserv_storage_storageendpoint,
|
|
218
|
+
endpoint: storageConfig.cloudserv_storage_storageendpoint,
|
|
219
|
+
accessKeyId: servToken.accesskeyid,
|
|
220
|
+
accessKeySecret: servToken.accesskeysecret,
|
|
221
|
+
stsToken: servToken.securitytoken,
|
|
222
|
+
bucket: storageConfig.cloudserv_storage_storagebucket,
|
|
223
|
+
secure: true
|
|
224
|
+
// sldEnable: true // 二级域名,ip地址
|
|
225
|
+
})
|
|
226
|
+
co(ossClient.copy(targetObj.key, copykey))
|
|
227
|
+
.then((res: any) => {
|
|
228
|
+
// console.log(res)
|
|
229
|
+
// debugger
|
|
230
|
+
// resolve(targetObj)
|
|
231
|
+
if (res?.res?.status === 200 && res?.data?.etag) {
|
|
232
|
+
resolve(targetObj)
|
|
233
|
+
} else {
|
|
234
|
+
console.error(res)
|
|
235
|
+
reject(res)
|
|
236
|
+
}
|
|
237
|
+
})
|
|
238
|
+
.catch((e: any) => {
|
|
239
|
+
console.error(e)
|
|
240
|
+
// debugger
|
|
241
|
+
reject(e)
|
|
242
|
+
})
|
|
243
|
+
} else if (provider?.isHuawei) {
|
|
244
|
+
const obs = new ObsClient({
|
|
245
|
+
access_key_id: servToken.accesskeyid,
|
|
246
|
+
secret_access_key: servToken.accesskeysecret,
|
|
247
|
+
server: storageConfig.cloudserv_storage_storageendpoint,
|
|
248
|
+
security_token: servToken.securitytoken
|
|
249
|
+
})
|
|
250
|
+
obs.copyObject({
|
|
251
|
+
Bucket: storageConfig.cloudserv_storage_storagebucket,
|
|
252
|
+
Key: targetObj.key,
|
|
253
|
+
CopySource: `${storageConfig.cloudserv_storage_storagebucket}/${copykey}`
|
|
254
|
+
})
|
|
255
|
+
.then((res: any) => {
|
|
256
|
+
if (res?.CommonMsg?.Status === 200 && res?.InterfaceResult) {
|
|
257
|
+
resolve(targetObj)
|
|
258
|
+
} else {
|
|
259
|
+
console.error(res)
|
|
260
|
+
reject(res)
|
|
261
|
+
}
|
|
262
|
+
})
|
|
263
|
+
.catch((e: any) => {
|
|
264
|
+
console.error(e)
|
|
265
|
+
reject(e)
|
|
266
|
+
})
|
|
267
|
+
} else if (provider?.isMinio || provider?.isAwss3) {
|
|
268
|
+
// debugger
|
|
269
|
+
// debugger
|
|
270
|
+
const s3 = new S3Client({
|
|
271
|
+
accessKeyId: servToken.accesskeyid,
|
|
272
|
+
secretAccessKey: servToken.accesskeysecret,
|
|
273
|
+
sessionToken: servToken.securitytoken,
|
|
274
|
+
region: storageConfig.cloudserv_storage_region,
|
|
275
|
+
endpoint: storageConfig.cloudserv_storage_storageendpoint,
|
|
276
|
+
signatureVersion: 'v4',
|
|
277
|
+
s3ForcePathStyle: provider?.isMinio ? true : undefined
|
|
278
|
+
})
|
|
279
|
+
// console.log(s3)
|
|
280
|
+
// debugger
|
|
281
|
+
s3.copyObject({
|
|
282
|
+
Bucket: storageConfig.cloudserv_storage_storagebucket,
|
|
283
|
+
CopySource: `${storageConfig.cloudserv_storage_storagebucket}/${copykey}`,
|
|
284
|
+
Key: targetObj.key
|
|
285
|
+
}, (err: any, data: any) => {
|
|
286
|
+
if (err) {
|
|
287
|
+
console.error(err)
|
|
288
|
+
reject(err)
|
|
289
|
+
} else {
|
|
290
|
+
// console.log(data)
|
|
291
|
+
resolve(targetObj)
|
|
292
|
+
}
|
|
293
|
+
})
|
|
294
|
+
} else {
|
|
295
|
+
throw Error(`暂不支持${provider?.name}存储类型`)
|
|
296
|
+
}
|
|
297
|
+
})
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
|
|
180
302
|
export default {
|
|
181
|
-
upload
|
|
303
|
+
upload,
|
|
304
|
+
copy
|
|
182
305
|
}
|
package/src/types/index.d.ts
CHANGED
|
@@ -66,8 +66,14 @@ interface IUpload {
|
|
|
66
66
|
onprogress?: (p: number, _checkpoint?: any) => void
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
interface ICopy {
|
|
70
|
+
copykey: string
|
|
71
|
+
storagetype?: StorageType
|
|
72
|
+
}
|
|
73
|
+
|
|
69
74
|
interface IUploadService {
|
|
70
75
|
upload: (options: IUpload) => Promise<any>
|
|
76
|
+
copy: (options: ICopy) => Promise<any>
|
|
71
77
|
}
|
|
72
78
|
|
|
73
79
|
// interface ISPUWebPluginOptions {
|
|
@@ -111,6 +117,13 @@ export const spuConfig: any
|
|
|
111
117
|
export const globalConfig: any
|
|
112
118
|
export const downloadService: IDownloadService
|
|
113
119
|
export const uploadService: IUploadService
|
|
120
|
+
export const getServToken: () => Promise<{
|
|
121
|
+
accesskeyid: string
|
|
122
|
+
accesskeysecret: string
|
|
123
|
+
securitytoken: string
|
|
124
|
+
expiration: string
|
|
125
|
+
}>
|
|
126
|
+
export const getCloudServ: () => any
|
|
114
127
|
export const getUniqueid: () => string
|
|
115
128
|
export const getUuid: () => string
|
|
116
129
|
export const functionCheck: (functioncode?: string) => boolean
|