@smart100/spu-web-plugin 1.0.15 → 1.0.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.
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: (type?: StorageType) => any
114
127
  export const getUniqueid: () => string
115
128
  export const getUuid: () => string
116
129
  export const functionCheck: (functioncode?: string) => boolean
@@ -1,4 +1,4 @@
1
- var version = "1.0.15";
1
+ var version = "1.0.17";
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 = 11;
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
- _context2.next = 9;
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 9:
17226
- _context2.next = 25;
17229
+ case 12:
17230
+ _context2.next = 34;
17227
17231
  break;
17228
- case 11:
17232
+ case 14:
17229
17233
  if (!(type === 'amap')) {
17230
- _context2.next = 19;
17234
+ _context2.next = 25;
17231
17235
  break;
17232
17236
  }
17233
17237
  if (!(!key || !secretkey)) {
17234
- _context2.next = 15;
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 15:
17240
- _context2.next = 17;
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 17:
17243
- _context2.next = 25;
17249
+ case 23:
17250
+ _context2.next = 34;
17244
17251
  break;
17245
- case 19:
17252
+ case 25:
17246
17253
  if (!(type === 'baidu')) {
17247
- _context2.next = 25;
17254
+ _context2.next = 34;
17248
17255
  break;
17249
17256
  }
17250
17257
  if (key) {
17251
- _context2.next = 23;
17258
+ _context2.next = 29;
17252
17259
  break;
17253
17260
  }
17254
17261
  console.error('请填写百度地图 Web App Key');
17255
17262
  return _context2.abrupt("return");
17256
- case 23:
17257
- _context2.next = 25;
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 25:
17269
+ case 34:
17260
17270
  this.isInit = true;
17261
- case 26:
17271
+ case 35:
17262
17272
  case "end":
17263
17273
  return _context2.stop();
17264
17274
  }
@@ -18056,66 +18066,67 @@ var getLocationPromise = /*#__PURE__*/function () {
18056
18066
  location = _context17.sent;
18057
18067
  case 6:
18058
18068
  if (location) {
18059
- _context17.next = 10;
18060
- break;
18061
- }
18062
- _context17.next = 9;
18063
- return getLocationByNavigator();
18064
- case 9:
18065
- location = _context17.sent;
18066
- case 10:
18067
- if (location) {
18068
- _context17.next = 35;
18069
+ _context17.next = 31;
18069
18070
  break;
18070
18071
  }
18071
18072
  if (!(mapService.type === 'amap')) {
18072
- _context17.next = 21;
18073
+ _context17.next = 17;
18073
18074
  break;
18074
18075
  }
18075
- _context17.next = 14;
18076
+ _context17.next = 10;
18076
18077
  return getLocationByAMap();
18077
- case 14:
18078
+ case 10:
18078
18079
  location = _context17.sent;
18079
18080
  if (!(!location && isuseiplocarion)) {
18080
- _context17.next = 19;
18081
+ _context17.next = 15;
18081
18082
  break;
18082
18083
  }
18083
- _context17.next = 18;
18084
+ _context17.next = 14;
18084
18085
  return getCityLocationByAMap();
18085
- case 18:
18086
+ case 14:
18086
18087
  location = _context17.sent;
18087
- case 19:
18088
- _context17.next = 35;
18088
+ case 15:
18089
+ _context17.next = 31;
18089
18090
  break;
18090
- case 21:
18091
+ case 17:
18091
18092
  if (!(mapService.type === 'tencent' && isuseiplocarion)) {
18092
- _context17.next = 27;
18093
+ _context17.next = 23;
18093
18094
  break;
18094
18095
  }
18095
- _context17.next = 24;
18096
+ _context17.next = 20;
18096
18097
  return getIPLocationByTMap();
18097
- case 24:
18098
+ case 20:
18098
18099
  location = _context17.sent;
18099
- _context17.next = 35;
18100
+ _context17.next = 31;
18100
18101
  break;
18101
- case 27:
18102
+ case 23:
18102
18103
  if (!(mapService.type === 'baidu')) {
18103
- _context17.next = 35;
18104
+ _context17.next = 31;
18104
18105
  break;
18105
18106
  }
18106
- _context17.next = 30;
18107
+ _context17.next = 26;
18107
18108
  return getLocationByBMap();
18108
- case 30:
18109
+ case 26:
18109
18110
  location = _context17.sent;
18110
18111
  if (!(!location && isuseiplocarion)) {
18112
+ _context17.next = 31;
18113
+ break;
18114
+ }
18115
+ _context17.next = 30;
18116
+ return getCityLocationByBMap();
18117
+ case 30:
18118
+ location = _context17.sent;
18119
+ case 31:
18120
+ if (location) {
18111
18121
  _context17.next = 35;
18112
18122
  break;
18113
18123
  }
18114
18124
  _context17.next = 34;
18115
- return getCityLocationByBMap();
18125
+ return getLocationByNavigator();
18116
18126
  case 34:
18117
18127
  location = _context17.sent;
18118
18128
  case 35:
18129
+ // location = null
18119
18130
  // 开发模式下为了方便测试提供虚拟定位
18120
18131
  if (!location && urlquery.isvirtuallocation) {
18121
18132
  location = {
@@ -51809,7 +51820,7 @@ var last = 0;
51809
51820
  var servtoken = null;
51810
51821
  var isGetting = false;
51811
51822
  var xhr = null;
51812
- var getServToken = /*#__PURE__*/function () {
51823
+ var requestServToken = /*#__PURE__*/function () {
51813
51824
  var _ref = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee() {
51814
51825
  var response;
51815
51826
  return _regeneratorRuntime$1().wrap(function _callee$(_context) {
@@ -51833,11 +51844,11 @@ var getServToken = /*#__PURE__*/function () {
51833
51844
  }
51834
51845
  }, _callee, null, [[0, 7]]);
51835
51846
  }));
51836
- return function getServToken() {
51847
+ return function requestServToken() {
51837
51848
  return _ref.apply(this, arguments);
51838
51849
  };
51839
51850
  }();
51840
- var initServToken = function initServToken() {
51851
+ var getServToken = function getServToken() {
51841
51852
  return new Promise(function (resolve, reject) {
51842
51853
  // 在请求中,排队列
51843
51854
  if (isGetting && xhr) {
@@ -51864,7 +51875,7 @@ var initServToken = function initServToken() {
51864
51875
  if (!last || last - Date.now() < 1000 * 60 * 5) {
51865
51876
  // 过期了 重新请求
51866
51877
  isGetting = true;
51867
- xhr = getServToken();
51878
+ xhr = requestServToken();
51868
51879
  xhr.then(function (res) {
51869
51880
  servtoken = res;
51870
51881
  last = new Date(res.expiration).getTime();
@@ -51974,7 +51985,7 @@ var getUrl = /*#__PURE__*/function () {
51974
51985
  throw Error('无可用存储设置');
51975
51986
  case 4:
51976
51987
  _context.next = 6;
51977
- return initServToken();
51988
+ return getServToken();
51978
51989
  case 6:
51979
51990
  servToken = _context.sent;
51980
51991
  if (servToken) {
@@ -52056,7 +52067,8 @@ var getUrl = /*#__PURE__*/function () {
52056
52067
  res = obs.createSignedUrlSync(Params);
52057
52068
  signedUrl = res.SignedUrl; // const expires = get(qs.parse(signedUrl), 'Expires') as string
52058
52069
  // if (expires) setCacheUrl(cacheKey, signedUrl, +expires)
52059
- return _context.abrupt("return", signedUrl);
52070
+ // 华为云通过 createSignedUrlSync 生产的签名链接默认带有 :80 或者 :443 端口 后端删除时需要去除
52071
+ return _context.abrupt("return", signedUrl.replace(/:(80|443)/, ''));
52060
52072
  case 37:
52061
52073
  _context.prev = 37;
52062
52074
  _context.t0 = _context["catch"](29);
@@ -52669,7 +52681,7 @@ var upload = /*#__PURE__*/function () {
52669
52681
  throw Error('无可用存储设置');
52670
52682
  case 6:
52671
52683
  _context4.next = 8;
52672
- return initServToken();
52684
+ return getServToken();
52673
52685
  case 8:
52674
52686
  servToken = _context4.sent;
52675
52687
  if (servToken) {
@@ -52727,9 +52739,10 @@ var upload = /*#__PURE__*/function () {
52727
52739
  onprogress && onprogress(p, _checkpoint);
52728
52740
  if (p === 1) {
52729
52741
  resolve({
52742
+ key: osskey,
52730
52743
  source: source,
52731
52744
  filename: file.name,
52732
- type: file.type,
52745
+ type: type,
52733
52746
  date: date,
52734
52747
  datetime: datetime,
52735
52748
  storage: storagetype,
@@ -52784,9 +52797,10 @@ var upload = /*#__PURE__*/function () {
52784
52797
  uploadRes = _context3.sent;
52785
52798
  if (uploadRes) {
52786
52799
  resolve({
52800
+ key: osskey,
52787
52801
  source: source,
52788
52802
  filename: file.name,
52789
- type: file.type,
52803
+ type: type,
52790
52804
  date: date,
52791
52805
  datetime: datetime,
52792
52806
  storage: storagetype,
@@ -52840,7 +52854,7 @@ var upload = /*#__PURE__*/function () {
52840
52854
  key: osskey,
52841
52855
  source: source,
52842
52856
  filename: file.name,
52843
- type: file.type,
52857
+ type: type,
52844
52858
  date: date,
52845
52859
  datetime: datetime,
52846
52860
  storage: storagetype,
@@ -52873,8 +52887,177 @@ var upload = /*#__PURE__*/function () {
52873
52887
  return _ref2.apply(this, arguments);
52874
52888
  };
52875
52889
  }();
52890
+ var createTargetObj = function createTargetObj(copykey) {
52891
+ var storagetype = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'storage';
52892
+ var uuid = v4();
52893
+ var datetime = Date.now().toString();
52894
+ var date = dayjs(Number(datetime)).format('YYYYMMDD');
52895
+ var arr = copykey.split('/');
52896
+ arr[0] = uuid.slice(0, 3);
52897
+ arr[2] = date;
52898
+ var arr2 = arr[arr.length - 1].split('.');
52899
+ var ext = arr2[arr2.length - 1];
52900
+ arr[arr.length - 1] = "".concat(uuid, ".").concat(ext);
52901
+ return {
52902
+ key: arr.join('/'),
52903
+ source: arr[arr.length - 1],
52904
+ datetime: datetime,
52905
+ date: date,
52906
+ type: arr[1],
52907
+ storage: storagetype
52908
+ };
52909
+ };
52910
+ var copy = /*#__PURE__*/function () {
52911
+ var _ref5 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee5(_ref4) {
52912
+ var _ref4$copykey, copykey, _ref4$storagetype, storagetype, storageConfig, servToken, provider, targetObj;
52913
+ return _regeneratorRuntime$1().wrap(function _callee5$(_context6) {
52914
+ while (1) switch (_context6.prev = _context6.next) {
52915
+ case 0:
52916
+ _ref4$copykey = _ref4.copykey, copykey = _ref4$copykey === void 0 ? '' : _ref4$copykey, _ref4$storagetype = _ref4.storagetype, storagetype = _ref4$storagetype === void 0 ? 'storage' : _ref4$storagetype;
52917
+ storageConfig = cloudServ.get(storagetype);
52918
+ if (storageConfig) {
52919
+ _context6.next = 4;
52920
+ break;
52921
+ }
52922
+ throw Error('无可用存储设置');
52923
+ case 4:
52924
+ _context6.next = 6;
52925
+ return getServToken();
52926
+ case 6:
52927
+ servToken = _context6.sent;
52928
+ if (servToken) {
52929
+ _context6.next = 9;
52930
+ break;
52931
+ }
52932
+ throw Error('无可用servToken');
52933
+ case 9:
52934
+ provider = cloudServ.getProvider(storagetype);
52935
+ targetObj = createTargetObj(copykey, storagetype);
52936
+ return _context6.abrupt("return", new Promise( /*#__PURE__*/function () {
52937
+ var _ref6 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee4(resolve, reject) {
52938
+ var ossClient, obs, s3;
52939
+ return _regeneratorRuntime$1().wrap(function _callee4$(_context5) {
52940
+ while (1) switch (_context5.prev = _context5.next) {
52941
+ case 0:
52942
+ if (!(provider !== null && provider !== void 0 && provider.isAliyun)) {
52943
+ _context5.next = 5;
52944
+ break;
52945
+ }
52946
+ ossClient = new AliClient({
52947
+ // region: cloudServ.cloudserv_storage_storageendpoint,
52948
+ endpoint: storageConfig.cloudserv_storage_storageendpoint,
52949
+ accessKeyId: servToken.accesskeyid,
52950
+ accessKeySecret: servToken.accesskeysecret,
52951
+ stsToken: servToken.securitytoken,
52952
+ bucket: storageConfig.cloudserv_storage_storagebucket,
52953
+ secure: true
52954
+ // sldEnable: true // 二级域名,ip地址
52955
+ });
52956
+
52957
+ co$1(ossClient.copy(targetObj.key, copykey)).then(function (res) {
52958
+ var _res$res, _res$data;
52959
+ // console.log(res)
52960
+ // debugger
52961
+ // resolve(targetObj)
52962
+ 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) {
52963
+ resolve(targetObj);
52964
+ } else {
52965
+ console.error(res);
52966
+ reject(res);
52967
+ }
52968
+ })["catch"](function (e) {
52969
+ console.error(e);
52970
+ // debugger
52971
+ reject(e);
52972
+ });
52973
+ _context5.next = 16;
52974
+ break;
52975
+ case 5:
52976
+ if (!(provider !== null && provider !== void 0 && provider.isHuawei)) {
52977
+ _context5.next = 10;
52978
+ break;
52979
+ }
52980
+ obs = new ObsClient({
52981
+ access_key_id: servToken.accesskeyid,
52982
+ secret_access_key: servToken.accesskeysecret,
52983
+ server: storageConfig.cloudserv_storage_storageendpoint,
52984
+ security_token: servToken.securitytoken
52985
+ });
52986
+ obs.copyObject({
52987
+ Bucket: storageConfig.cloudserv_storage_storagebucket,
52988
+ Key: targetObj.key,
52989
+ CopySource: "".concat(storageConfig.cloudserv_storage_storagebucket, "/").concat(copykey)
52990
+ }).then(function (res) {
52991
+ var _res$CommonMsg;
52992
+ 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) {
52993
+ resolve(targetObj);
52994
+ } else {
52995
+ console.error(res);
52996
+ reject(res);
52997
+ }
52998
+ })["catch"](function (e) {
52999
+ console.error(e);
53000
+ reject(e);
53001
+ });
53002
+ _context5.next = 16;
53003
+ break;
53004
+ case 10:
53005
+ if (!(provider !== null && provider !== void 0 && provider.isMinio || provider !== null && provider !== void 0 && provider.isAwss3)) {
53006
+ _context5.next = 15;
53007
+ break;
53008
+ }
53009
+ // debugger
53010
+ // debugger
53011
+ s3 = new S3Client({
53012
+ accessKeyId: servToken.accesskeyid,
53013
+ secretAccessKey: servToken.accesskeysecret,
53014
+ sessionToken: servToken.securitytoken,
53015
+ region: storageConfig.cloudserv_storage_region,
53016
+ endpoint: storageConfig.cloudserv_storage_storageendpoint,
53017
+ signatureVersion: 'v4',
53018
+ s3ForcePathStyle: provider !== null && provider !== void 0 && provider.isMinio ? true : undefined
53019
+ }); // console.log(s3)
53020
+ // debugger
53021
+ s3.copyObject({
53022
+ Bucket: storageConfig.cloudserv_storage_storagebucket,
53023
+ CopySource: "".concat(storageConfig.cloudserv_storage_storagebucket, "/").concat(copykey),
53024
+ Key: targetObj.key
53025
+ }, function (err, data) {
53026
+ if (err) {
53027
+ console.error(err);
53028
+ reject(err);
53029
+ } else {
53030
+ // console.log(data)
53031
+ resolve(targetObj);
53032
+ }
53033
+ });
53034
+ _context5.next = 16;
53035
+ break;
53036
+ case 15:
53037
+ throw Error("\u6682\u4E0D\u652F\u6301".concat(provider === null || provider === void 0 ? void 0 : provider.name, "\u5B58\u50A8\u7C7B\u578B"));
53038
+ case 16:
53039
+ case "end":
53040
+ return _context5.stop();
53041
+ }
53042
+ }, _callee4);
53043
+ }));
53044
+ return function (_x5, _x6) {
53045
+ return _ref6.apply(this, arguments);
53046
+ };
53047
+ }()));
53048
+ case 12:
53049
+ case "end":
53050
+ return _context6.stop();
53051
+ }
53052
+ }, _callee5);
53053
+ }));
53054
+ return function copy(_x4) {
53055
+ return _ref5.apply(this, arguments);
53056
+ };
53057
+ }();
52876
53058
  var uploadService = {
52877
- upload: upload
53059
+ upload: upload,
53060
+ copy: copy
52878
53061
  };
52879
53062
 
52880
53063
  var isinit = false;
@@ -70043,4 +70226,4 @@ var SPUWebPlugin = {
70043
70226
  version: version
70044
70227
  };
70045
70228
 
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 };
70229
+ 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smart100/spu-web-plugin",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "dev": "npm run build:types && rollup -c -w",
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'
@@ -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
package/src/map/index.ts CHANGED
@@ -95,20 +95,19 @@ const getLocationByNavigator = async (): Promise<Location> => {
95
95
  }
96
96
 
97
97
  // ipaas ip 定位
98
- const getIPLocationByIpaas = async (
99
- ip?: string
100
- ): Promise<Location> => {
98
+ const getIPLocationByIpaas = async (ip?: string): Promise<Location> => {
101
99
  console.log('getIPLocationByIpaas start...')
102
100
  return new Promise((resolve, reject) => {
103
101
  const AMapKey = getAMapKey()
104
102
 
105
- axios.post(
106
- 'https://silkroad.wxchina.com/api/openapi/publishEvent?topic=xw-listener&subtopic=xw-listener&apicaseid=6684389338001815271',
107
- {
108
- key: AMapKey.key, // 好像不传也没问题 因为key是在ipaas那边设置的
109
- ip: ip || ''
110
- }
111
- )
103
+ axios
104
+ .post(
105
+ 'https://silkroad.wxchina.com/api/openapi/publishEvent?topic=xw-listener&subtopic=xw-listener&apicaseid=6684389338001815271',
106
+ {
107
+ key: AMapKey.key, // 好像不传也没问题 因为key是在ipaas那边设置的
108
+ ip: ip || ''
109
+ }
110
+ )
112
111
  .then((res: any) => {
113
112
  // console.log(res)
114
113
  // debugger
@@ -134,7 +133,8 @@ const getIPLocationByIpaas = async (
134
133
  console.error('getIPLocationByIpaas fail')
135
134
  resolve(null)
136
135
  }
137
- }).catch((err: any) => {
136
+ })
137
+ .catch((err: any) => {
138
138
  console.error(err)
139
139
  console.error('getIPLocationByIpaas fail')
140
140
  resolve(null)
@@ -150,12 +150,15 @@ const getAddressByIpaas = async (position: Location): Promise<string> => {
150
150
  if (position) {
151
151
  try {
152
152
  const AMapKey = getAMapKey()
153
- const result = await axios.post('https://silkroad.wxchina.com/api/openapi/publishEvent?topic=xw-listener&subtopic=xw-listener&apicaseid=6684389338001809906', {
154
- longitude: position.longitude,
155
- latitude: position.latitude,
156
- key: AMapKey.key
157
- // extensions: 'all'
158
- })
153
+ const result = await axios.post(
154
+ 'https://silkroad.wxchina.com/api/openapi/publishEvent?topic=xw-listener&subtopic=xw-listener&apicaseid=6684389338001809906',
155
+ {
156
+ longitude: position.longitude,
157
+ latitude: position.latitude,
158
+ key: AMapKey.key
159
+ // extensions: 'all'
160
+ }
161
+ )
159
162
  // console.log(result)
160
163
  const address = result?.data?.formatted_address
161
164
  if (address) {
@@ -484,11 +487,6 @@ const getLocationPromise = async (isuseiplocarion = false): Promise<Location> =>
484
487
  location = await getLocationByNative()
485
488
  }
486
489
 
487
- if (!location) {
488
- location = await getLocationByNavigator()
489
- }
490
- // location = null
491
-
492
490
  if (!location) {
493
491
  if (mapService.type === 'amap') {
494
492
  location = await getLocationByAMap()
@@ -509,6 +507,11 @@ const getLocationPromise = async (isuseiplocarion = false): Promise<Location> =>
509
507
  }
510
508
  }
511
509
 
510
+ if (!location) {
511
+ location = await getLocationByNavigator()
512
+ }
513
+ // location = null
514
+
512
515
  // 开发模式下为了方便测试提供虚拟定位
513
516
  if (!location && urlquery.isvirtuallocation) {
514
517
  location = {
@@ -1,4 +1,4 @@
1
- import { lsProxy } from './storageProxy'
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 '../cloudServ'
4
- import { initServToken } from './servtoken'
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 initServToken()
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
- return signedUrl
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)
@@ -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 getServToken = async () => {
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 initServToken = () => {
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 = getServToken()
60
+ xhr = requestServToken()
61
61
  xhr
62
62
  .then((res) => {
63
63
  servtoken = res
@@ -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 '../cloudServ'
8
- import { initServToken } from './servtoken'
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 initServToken()
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: file.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: file.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: file.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
  }
@@ -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: (type?: StorageType) => any
114
127
  export const getUniqueid: () => string
115
128
  export const getUuid: () => string
116
129
  export const functionCheck: (functioncode?: string) => boolean