@cloudbase/manager-node 3.9.3 → 3.10.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.
package/lib/context.js CHANGED
@@ -2,12 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CloudBaseContext = void 0;
4
4
  class CloudBaseContext {
5
- constructor({ secretId = '', secretKey = '', token = '', proxy = '', region = '' }) {
5
+ constructor({ secretId = '', secretKey = '', token = '', proxy = '', region = '', envType = '' }) {
6
6
  this.secretId = secretId;
7
7
  this.secretKey = secretKey;
8
8
  this.token = token;
9
9
  this.proxy = proxy;
10
10
  this.region = region;
11
+ this.envType = envType;
11
12
  }
12
13
  }
13
14
  exports.CloudBaseContext = CloudBaseContext;
package/lib/env/index.js CHANGED
@@ -21,6 +21,7 @@ class EnvService {
21
21
  constructor(environment) {
22
22
  this.environment = environment;
23
23
  this.envId = environment.getEnvId();
24
+ this.envType = environment.getEnvType();
24
25
  this.cloudService = new utils_1.CloudService(environment.cloudBaseContext, 'tcb', '2018-06-08');
25
26
  this.camService = new cam_1.CamService(environment.cloudBaseContext);
26
27
  this.billService = new billing_1.BillingService(environment.cloudBaseContext);
@@ -331,9 +332,13 @@ class EnvService {
331
332
  */
332
333
  async getEnvInfo() {
333
334
  // NOTE: DescribeEnv 接口废弃,需要使用 DescribeEnvs 接口
334
- const { EnvList, RequestId } = await this.cloudService.request('DescribeEnvs', {
335
+ const params = {
335
336
  EnvId: this.envId
336
- });
337
+ };
338
+ if (this.envType === 'run') {
339
+ params.EnvType = 'run';
340
+ }
341
+ const { EnvList, RequestId } = await this.cloudService.request('DescribeEnvs', params);
337
342
  return {
338
343
  EnvInfo: (EnvList === null || EnvList === void 0 ? void 0 : EnvList.length) ? EnvList[0] : {},
339
344
  RequestId
@@ -19,6 +19,7 @@ class Environment {
19
19
  this.inited = false;
20
20
  this.envId = envId;
21
21
  this.cloudBaseContext = context;
22
+ this.envType = context.envType;
22
23
  // 拉取当前环境 的环境信息 todo
23
24
  this.functionService = new function_1.FunctionService(this);
24
25
  this.databaseService = new database_1.DatabaseService(this);
@@ -49,6 +50,9 @@ class Environment {
49
50
  getEnvId() {
50
51
  return this.envId;
51
52
  }
53
+ getEnvType() {
54
+ return this.envType;
55
+ }
52
56
  getStorageService() {
53
57
  return this.storageService;
54
58
  }
@@ -23,7 +23,7 @@ function isNodeFunction(runtime) {
23
23
  }
24
24
  // 解析函数配置,换成请求参数
25
25
  function configToParams(options) {
26
- var _a, _b, _c;
26
+ var _a, _b, _c, _d, _e;
27
27
  const { func, codeSecret, baseParams } = options;
28
28
  let installDependency;
29
29
  // Node 函数默认安装依赖
@@ -53,11 +53,13 @@ function configToParams(options) {
53
53
  params.Timeout = Number(func.timeout) || 10;
54
54
  // 默认运行环境 Nodejs8.9
55
55
  params.Runtime = func.runtime || 'Nodejs8.9';
56
- // VPC 网络
57
- params.VpcConfig = {
58
- SubnetId: ((_a = func === null || func === void 0 ? void 0 : func.vpc) === null || _a === void 0 ? void 0 : _a.subnetId) || '',
59
- VpcId: ((_b = func === null || func === void 0 ? void 0 : func.vpc) === null || _b === void 0 ? void 0 : _b.vpcId) || ''
60
- };
56
+ if (((_a = func === null || func === void 0 ? void 0 : func.vpc) === null || _a === void 0 ? void 0 : _a.subnetId) !== undefined && ((_b = func === null || func === void 0 ? void 0 : func.vpc) === null || _b === void 0 ? void 0 : _b.vpcId) !== undefined) {
57
+ // VPC 网络
58
+ params.VpcConfig = {
59
+ SubnetId: (_c = func === null || func === void 0 ? void 0 : func.vpc) === null || _c === void 0 ? void 0 : _c.subnetId,
60
+ VpcId: (_d = func === null || func === void 0 ? void 0 : func.vpc) === null || _d === void 0 ? void 0 : _d.vpcId
61
+ };
62
+ }
61
63
  // 运行内存
62
64
  params.MemorySize = func.memorySize || 256;
63
65
  // 自动安装依赖
@@ -67,7 +69,7 @@ function configToParams(options) {
67
69
  params.CodeSecret = codeSecret || func.codeSecret;
68
70
  }
69
71
  // 函数层
70
- if ((_c = func === null || func === void 0 ? void 0 : func.layers) === null || _c === void 0 ? void 0 : _c.length) {
72
+ if ((_e = func === null || func === void 0 ? void 0 : func.layers) === null || _e === void 0 ? void 0 : _e.length) {
71
73
  const transformLayers = func.layers.map(item => ({
72
74
  LayerName: item.name,
73
75
  LayerVersion: item.version
@@ -339,7 +341,7 @@ class FunctionService {
339
341
  * @returns {Promise<IResponseInfo>}
340
342
  */
341
343
  async updateFunctionConfig(func) {
342
- var _a, _b, _c;
344
+ var _a, _b, _c, _d, _e;
343
345
  const { namespace } = this.getFunctionConfig();
344
346
  const envVariables = Object.keys(func.envVariables || {}).map(key => ({
345
347
  Key: key,
@@ -359,11 +361,13 @@ class FunctionService {
359
361
  func.timeout && (params.Timeout = func.timeout);
360
362
  // 运行时
361
363
  func.runtime && (params.Runtime = func.runtime);
362
- // VPC 网络
363
- params.VpcConfig = {
364
- SubnetId: ((_a = func === null || func === void 0 ? void 0 : func.vpc) === null || _a === void 0 ? void 0 : _a.subnetId) || '',
365
- VpcId: ((_b = func === null || func === void 0 ? void 0 : func.vpc) === null || _b === void 0 ? void 0 : _b.vpcId) || ''
366
- };
364
+ if (((_a = func === null || func === void 0 ? void 0 : func.vpc) === null || _a === void 0 ? void 0 : _a.subnetId) !== undefined && ((_b = func === null || func === void 0 ? void 0 : func.vpc) === null || _b === void 0 ? void 0 : _b.vpcId) !== undefined) {
365
+ // VPC 网络
366
+ params.VpcConfig = {
367
+ SubnetId: (_c = func === null || func === void 0 ? void 0 : func.vpc) === null || _c === void 0 ? void 0 : _c.subnetId,
368
+ VpcId: (_d = func === null || func === void 0 ? void 0 : func.vpc) === null || _d === void 0 ? void 0 : _d.vpcId
369
+ };
370
+ }
367
371
  // 内存
368
372
  func.memorySize && (params.MemorySize = func.memorySize);
369
373
  // Node 函数默认安装依赖
@@ -373,7 +377,7 @@ class FunctionService {
373
377
  params.InstallDependency = func.installDependency ? 'TRUE' : 'FALSE';
374
378
  }
375
379
  // 函数层
376
- if ((_c = func === null || func === void 0 ? void 0 : func.layers) === null || _c === void 0 ? void 0 : _c.length) {
380
+ if ((_e = func === null || func === void 0 ? void 0 : func.layers) === null || _e === void 0 ? void 0 : _e.length) {
377
381
  const transformLayers = func.layers.map(item => ({
378
382
  LayerName: item.name,
379
383
  LayerVersion: item.version
package/lib/index.js CHANGED
@@ -4,7 +4,7 @@ const environmentManager_1 = require("./environmentManager");
4
4
  class CloudBase {
5
5
  constructor(config = {}) {
6
6
  this.cloudBaseConfig = {};
7
- let { secretId, secretKey, token, envId, proxy, region } = config;
7
+ let { secretId, secretKey, token, envId, proxy, region, envType } = config;
8
8
  // config 中传入的 secretId secretkey 必须同时存在
9
9
  if ((secretId && !secretKey) || (!secretId && secretKey)) {
10
10
  throw new Error('secretId and secretKey must be a pair');
@@ -14,6 +14,7 @@ class CloudBase {
14
14
  secretKey,
15
15
  token,
16
16
  envId,
17
+ envType,
17
18
  proxy,
18
19
  region
19
20
  };
@@ -134,18 +134,24 @@ class StorageService {
134
134
  * 上传文件夹
135
135
  * @param {string} localPath 本地文件夹路径
136
136
  * @param {string} cloudPath 云端文件夹
137
+ * @param {number} parallel 并发量
138
+ * @param {number} retryCount 重试次数
139
+ * @param {number} retryInterval 重试时间间隔(毫秒)
137
140
  * @param {(string | string[])} ignore
138
141
  * @param {(string | string[])} ignore
139
142
  * @returns {Promise<void>}
140
143
  */
141
144
  async uploadDirectory(options) {
142
- const { localPath, cloudPath = '', ignore, onProgress, onFileFinish } = options;
145
+ const { localPath, cloudPath = '', ignore, onProgress, onFileFinish, parallel, retryCount, retryInterval } = options;
143
146
  // 此处不检查路径是否存在
144
147
  // 绝对路径 /var/blog/xxxx
145
148
  const { bucket, region } = this.getStorageConfig();
146
149
  return this.uploadDirectoryCustom({
147
150
  localPath,
148
151
  cloudPath,
152
+ parallel,
153
+ retryCount,
154
+ retryInterval,
149
155
  bucket,
150
156
  region,
151
157
  ignore,
@@ -157,13 +163,16 @@ class StorageService {
157
163
  * 上传文件夹,支持自定义 Region 和 Bucket
158
164
  * @param {string} localPath
159
165
  * @param {string} cloudPath
166
+ * @param {number} parallel
167
+ * @param {number} retryCount
168
+ * @param {number} retryInterval
160
169
  * @param {string} bucket
161
170
  * @param {string} region
162
171
  * @param {IOptions} options
163
172
  * @returns {Promise<void>}
164
173
  */
165
174
  async uploadDirectoryCustom(options) {
166
- const { localPath, cloudPath, bucket, region, onProgress, onFileFinish, ignore, fileId = true, parallel = 20 } = options;
175
+ const { localPath, cloudPath, bucket, region, onProgress, onFileFinish, ignore, fileId = true, parallel = 20, retryCount = 0, retryInterval = 500 } = options;
167
176
  // 此处不检查路径是否存在
168
177
  // 绝对路径 /var/blog/xxxx
169
178
  const resolvePath = path_1.default.resolve(localPath);
@@ -229,11 +238,18 @@ class StorageService {
229
238
  // 对文件上传进行处理
230
239
  const cos = this.getCos(parallel);
231
240
  const uploadFiles = util_1.default.promisify(cos.uploadFiles).bind(cos);
232
- return uploadFiles({
241
+ const params = {
233
242
  files,
234
243
  SliceSize: BIG_FILE_SIZE,
235
244
  onProgress,
236
245
  onFileFinish
246
+ };
247
+ return this.uploadFilesWithRetry({
248
+ uploadFiles,
249
+ options: params,
250
+ times: retryCount,
251
+ interval: retryInterval,
252
+ failedFiles: []
237
253
  });
238
254
  }
239
255
  /**
@@ -847,6 +863,42 @@ class StorageService {
847
863
  env: envConfig.EnvId
848
864
  };
849
865
  }
866
+ /**
867
+ * 带重试功能的上传多文件函数
868
+ * @param uploadFiles sdk上传函数
869
+ * @param options sdk上传函数参数
870
+ * @param times 重试次数
871
+ * @param interval 重试时间间隔(毫秒)
872
+ * @param failedFiles 失败文件列表
873
+ * @returns
874
+ */
875
+ async uploadFilesWithRetry({ uploadFiles, options, times, interval, failedFiles }) {
876
+ console.log('times', times);
877
+ const { files, onFileFinish } = options;
878
+ const tempFailedFiles = [];
879
+ const res = await uploadFiles(Object.assign(Object.assign({}, options), { files: failedFiles.length
880
+ ? files.filter(file => failedFiles.includes(file.Key))
881
+ : files, onFileFinish: (...args) => {
882
+ console.log('args', args);
883
+ const error = args[0];
884
+ const fileInfo = args[2];
885
+ if (error) {
886
+ tempFailedFiles.push(fileInfo.Key);
887
+ }
888
+ onFileFinish === null || onFileFinish === void 0 ? void 0 : onFileFinish.apply(null, args);
889
+ } }));
890
+ if (!(tempFailedFiles === null || tempFailedFiles === void 0 ? void 0 : tempFailedFiles.length) || times <= 0)
891
+ return res;
892
+ if (times > 0) {
893
+ setTimeout(() => this.uploadFilesWithRetry({
894
+ uploadFiles,
895
+ options,
896
+ times: times - 1,
897
+ interval,
898
+ failedFiles: tempFailedFiles
899
+ }), interval);
900
+ }
901
+ }
850
902
  }
851
903
  __decorate([
852
904
  utils_1.preLazy()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/manager-node",
3
- "version": "3.9.3",
3
+ "version": "3.10.0",
4
4
  "description": "The node manage service api for cloudbase.",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
package/src/context.ts CHANGED
@@ -5,12 +5,14 @@ export class CloudBaseContext {
5
5
  public readonly proxy: string
6
6
  public readonly envId: string
7
7
  public readonly region: string
8
+ public readonly envType: string // baas/run/weda/hosting
8
9
 
9
- constructor({ secretId = '', secretKey = '', token = '', proxy = '', region = '' }) {
10
+ constructor({ secretId = '', secretKey = '', token = '', proxy = '', region = '', envType = '' }) {
10
11
  this.secretId = secretId
11
12
  this.secretKey = secretKey
12
13
  this.token = token
13
14
  this.proxy = proxy
14
15
  this.region = region
16
+ this.envType = envType
15
17
  }
16
18
  }
package/src/env/index.ts CHANGED
@@ -64,10 +64,12 @@ export class EnvService {
64
64
  private cloudService: CloudService
65
65
  private camService: CamService
66
66
  private billService: BillingService
67
+ private envType?: string
67
68
 
68
69
  constructor(environment: Environment) {
69
70
  this.environment = environment
70
71
  this.envId = environment.getEnvId()
72
+ this.envType = environment.getEnvType()
71
73
  this.cloudService = new CloudService(environment.cloudBaseContext, 'tcb', '2018-06-08')
72
74
  this.camService = new CamService(environment.cloudBaseContext)
73
75
  this.billService = new BillingService(environment.cloudBaseContext)
@@ -420,9 +422,15 @@ export class EnvService {
420
422
  RequestId: string
421
423
  }> {
422
424
  // NOTE: DescribeEnv 接口废弃,需要使用 DescribeEnvs 接口
423
- const { EnvList, RequestId } = await this.cloudService.request('DescribeEnvs', {
425
+ const params: any = {
424
426
  EnvId: this.envId
425
- })
427
+ }
428
+
429
+ if (this.envType === 'run') {
430
+ params.EnvType = 'run'
431
+ }
432
+
433
+ const { EnvList, RequestId } = await this.cloudService.request('DescribeEnvs', params)
426
434
 
427
435
  return {
428
436
  EnvInfo: EnvList?.length ? EnvList[0] : {},
@@ -21,6 +21,7 @@ export class Environment {
21
21
  public cloudBaseContext: CloudBaseContext
22
22
  public lazyEnvironmentConfig: EnvInfo
23
23
  private envId: string
24
+ private envType?: string
24
25
 
25
26
  private functionService: FunctionService
26
27
  private databaseService: DatabaseService
@@ -35,6 +36,7 @@ export class Environment {
35
36
  constructor(context: CloudBaseContext, envId: string) {
36
37
  this.envId = envId
37
38
  this.cloudBaseContext = context
39
+ this.envType = context.envType
38
40
 
39
41
  // 拉取当前环境 的环境信息 todo
40
42
  this.functionService = new FunctionService(this)
@@ -69,6 +71,10 @@ export class Environment {
69
71
  return this.envId
70
72
  }
71
73
 
74
+ public getEnvType(): string {
75
+ return this.envType
76
+ }
77
+
72
78
  public getStorageService(): StorageService {
73
79
  return this.storageService
74
80
  }
@@ -174,10 +174,13 @@ function configToParams(options: {
174
174
  params.Timeout = Number(func.timeout) || 10
175
175
  // 默认运行环境 Nodejs8.9
176
176
  params.Runtime = func.runtime || 'Nodejs8.9'
177
- // VPC 网络
178
- params.VpcConfig = {
179
- SubnetId: func?.vpc?.subnetId || '',
180
- VpcId: func?.vpc?.vpcId || ''
177
+
178
+ if (func?.vpc?.subnetId !== undefined && func?.vpc?.vpcId !== undefined) {
179
+ // VPC 网络
180
+ params.VpcConfig = {
181
+ SubnetId: func?.vpc?.subnetId,
182
+ VpcId: func?.vpc?.vpcId
183
+ }
181
184
  }
182
185
  // 运行内存
183
186
  params.MemorySize = func.memorySize || 256
@@ -563,11 +566,15 @@ export class FunctionService {
563
566
  func.timeout && (params.Timeout = func.timeout)
564
567
  // 运行时
565
568
  func.runtime && (params.Runtime = func.runtime)
566
- // VPC 网络
567
- params.VpcConfig = {
568
- SubnetId: func?.vpc?.subnetId || '',
569
- VpcId: func?.vpc?.vpcId || ''
569
+
570
+ if (func?.vpc?.subnetId !== undefined && func?.vpc?.vpcId !== undefined) {
571
+ // VPC 网络
572
+ params.VpcConfig = {
573
+ SubnetId: func?.vpc?.subnetId,
574
+ VpcId: func?.vpc?.vpcId
575
+ }
570
576
  }
577
+
571
578
  // 内存
572
579
  func.memorySize && (params.MemorySize = func.memorySize)
573
580
 
package/src/index.ts CHANGED
@@ -19,6 +19,7 @@ interface CloudBaseConfig {
19
19
  envId?: string
20
20
  proxy?: string
21
21
  region?: string
22
+ envType?: string
22
23
  }
23
24
 
24
25
  class CloudBase {
@@ -45,7 +46,7 @@ class CloudBase {
45
46
  private environmentManager: EnvironmentManager
46
47
 
47
48
  public constructor(config: CloudBaseConfig = {}) {
48
- let { secretId, secretKey, token, envId, proxy, region } = config
49
+ let { secretId, secretKey, token, envId, proxy, region, envType } = config
49
50
  // config 中传入的 secretId secretkey 必须同时存在
50
51
  if ((secretId && !secretKey) || (!secretId && secretKey)) {
51
52
  throw new Error('secretId and secretKey must be a pair')
@@ -56,6 +57,7 @@ class CloudBase {
56
57
  secretKey,
57
58
  token,
58
59
  envId,
60
+ envType,
59
61
  proxy,
60
62
  region
61
63
  }
@@ -49,6 +49,12 @@ export interface IFileOptions extends IOptions {
49
49
  localPath: string
50
50
  // cloudPath 可以为空
51
51
  cloudPath?: string
52
+ // 并发数量
53
+ parallel?: number
54
+ // 重试次数
55
+ retryCount?: number
56
+ // 重试时间间隔(毫秒)
57
+ retryInterval?: number
52
58
  }
53
59
 
54
60
  export interface IFilesOptions extends IOptions {
@@ -230,19 +236,34 @@ export class StorageService {
230
236
  * 上传文件夹
231
237
  * @param {string} localPath 本地文件夹路径
232
238
  * @param {string} cloudPath 云端文件夹
239
+ * @param {number} parallel 并发量
240
+ * @param {number} retryCount 重试次数
241
+ * @param {number} retryInterval 重试时间间隔(毫秒)
233
242
  * @param {(string | string[])} ignore
234
243
  * @param {(string | string[])} ignore
235
244
  * @returns {Promise<void>}
236
245
  */
237
246
  @preLazy()
238
247
  public async uploadDirectory(options: IFileOptions): Promise<void> {
239
- const { localPath, cloudPath = '', ignore, onProgress, onFileFinish } = options
248
+ const {
249
+ localPath,
250
+ cloudPath = '',
251
+ ignore,
252
+ onProgress,
253
+ onFileFinish,
254
+ parallel,
255
+ retryCount,
256
+ retryInterval
257
+ } = options
240
258
  // 此处不检查路径是否存在
241
259
  // 绝对路径 /var/blog/xxxx
242
260
  const { bucket, region } = this.getStorageConfig()
243
261
  return this.uploadDirectoryCustom({
244
262
  localPath,
245
263
  cloudPath,
264
+ parallel,
265
+ retryCount,
266
+ retryInterval,
246
267
  bucket,
247
268
  region,
248
269
  ignore,
@@ -255,6 +276,9 @@ export class StorageService {
255
276
  * 上传文件夹,支持自定义 Region 和 Bucket
256
277
  * @param {string} localPath
257
278
  * @param {string} cloudPath
279
+ * @param {number} parallel
280
+ * @param {number} retryCount
281
+ * @param {number} retryInterval
258
282
  * @param {string} bucket
259
283
  * @param {string} region
260
284
  * @param {IOptions} options
@@ -271,7 +295,9 @@ export class StorageService {
271
295
  onFileFinish,
272
296
  ignore,
273
297
  fileId = true,
274
- parallel = 20
298
+ parallel = 20,
299
+ retryCount = 0,
300
+ retryInterval = 500
275
301
  } = options
276
302
  // 此处不检查路径是否存在
277
303
  // 绝对路径 /var/blog/xxxx
@@ -310,12 +336,13 @@ export class StorageService {
310
336
  const creatingDirController = new AsyncTaskParallelController(parallel, 50)
311
337
  const creatingDirTasks = fileStatsList
312
338
  .filter(info => info.isDir)
313
- .map(info => () =>
314
- this.createCloudDirectroyCustom({
315
- cloudPath: info.cloudFileKey,
316
- bucket,
317
- region
318
- })
339
+ .map(
340
+ info => () =>
341
+ this.createCloudDirectroyCustom({
342
+ cloudPath: info.cloudFileKey,
343
+ bucket,
344
+ region
345
+ })
319
346
  )
320
347
 
321
348
  creatingDirController.loadTasks(creatingDirTasks)
@@ -348,15 +375,20 @@ export class StorageService {
348
375
  // 对文件上传进行处理
349
376
  const cos = this.getCos(parallel)
350
377
  const uploadFiles = Util.promisify(cos.uploadFiles).bind(cos)
351
-
352
- return uploadFiles({
378
+ const params = {
353
379
  files,
354
380
  SliceSize: BIG_FILE_SIZE,
355
381
  onProgress,
356
382
  onFileFinish
383
+ }
384
+ return this.uploadFilesWithRetry({
385
+ uploadFiles,
386
+ options: params,
387
+ times: retryCount,
388
+ interval: retryInterval,
389
+ failedFiles: []
357
390
  })
358
391
  }
359
-
360
392
  /**
361
393
  * 批量上传文件
362
394
  * @param options
@@ -735,9 +767,7 @@ export class StorageService {
735
767
  * @returns {Promise<void>}
736
768
  */
737
769
  @preLazy()
738
- public async deleteDirectory(
739
- cloudPath: string
740
- ): Promise<{
770
+ public async deleteDirectory(cloudPath: string): Promise<{
741
771
  Deleted: { Key: string }[]
742
772
  Error: Object[]
743
773
  }> {
@@ -758,9 +788,7 @@ export class StorageService {
758
788
  * @returns {Promise<void>}
759
789
  */
760
790
  @preLazy()
761
- public async deleteDirectoryCustom(
762
- options: { cloudPath: string } & ICustomOptions
763
- ): Promise<{
791
+ public async deleteDirectoryCustom(options: { cloudPath: string } & ICustomOptions): Promise<{
764
792
  Deleted: { Key: string }[]
765
793
  Error: Object[]
766
794
  }> {
@@ -1127,4 +1155,47 @@ export class StorageService {
1127
1155
  env: envConfig.EnvId
1128
1156
  }
1129
1157
  }
1158
+ /**
1159
+ * 带重试功能的上传多文件函数
1160
+ * @param uploadFiles sdk上传函数
1161
+ * @param options sdk上传函数参数
1162
+ * @param times 重试次数
1163
+ * @param interval 重试时间间隔(毫秒)
1164
+ * @param failedFiles 失败文件列表
1165
+ * @returns
1166
+ */
1167
+ private async uploadFilesWithRetry({ uploadFiles, options, times, interval, failedFiles }) {
1168
+ console.log('times', times)
1169
+ const { files, onFileFinish } = options
1170
+ const tempFailedFiles = []
1171
+ const res = await uploadFiles({
1172
+ ...options,
1173
+ files: failedFiles.length
1174
+ ? files.filter(file => failedFiles.includes(file.Key))
1175
+ : files,
1176
+ onFileFinish: (...args) => {
1177
+ console.log('args', args)
1178
+ const error = args[0]
1179
+ const fileInfo = (args as any)[2]
1180
+ if (error) {
1181
+ tempFailedFiles.push(fileInfo.Key)
1182
+ }
1183
+ onFileFinish?.apply(null, args)
1184
+ }
1185
+ })
1186
+ if (!tempFailedFiles?.length || times <= 0) return res
1187
+ if (times > 0) {
1188
+ setTimeout(
1189
+ () =>
1190
+ this.uploadFilesWithRetry({
1191
+ uploadFiles,
1192
+ options,
1193
+ times: times - 1,
1194
+ interval,
1195
+ failedFiles: tempFailedFiles
1196
+ }),
1197
+ interval
1198
+ )
1199
+ }
1200
+ }
1130
1201
  }
@@ -5,11 +5,13 @@ export declare class CloudBaseContext {
5
5
  readonly proxy: string;
6
6
  readonly envId: string;
7
7
  readonly region: string;
8
- constructor({ secretId, secretKey, token, proxy, region }: {
8
+ readonly envType: string;
9
+ constructor({ secretId, secretKey, token, proxy, region, envType }: {
9
10
  secretId?: string;
10
11
  secretKey?: string;
11
12
  token?: string;
12
13
  proxy?: string;
13
14
  region?: string;
15
+ envType?: string;
14
16
  });
15
17
  }
@@ -34,6 +34,7 @@ export declare class EnvService {
34
34
  private cloudService;
35
35
  private camService;
36
36
  private billService;
37
+ private envType?;
37
38
  constructor(environment: Environment);
38
39
  /**
39
40
  * 列出所有环境
@@ -15,6 +15,7 @@ export declare class Environment {
15
15
  cloudBaseContext: CloudBaseContext;
16
16
  lazyEnvironmentConfig: EnvInfo;
17
17
  private envId;
18
+ private envType?;
18
19
  private functionService;
19
20
  private databaseService;
20
21
  private storageService;
@@ -27,6 +28,7 @@ export declare class Environment {
27
28
  constructor(context: CloudBaseContext, envId: string);
28
29
  lazyInit(): Promise<any>;
29
30
  getEnvId(): string;
31
+ getEnvType(): string;
30
32
  getStorageService(): StorageService;
31
33
  getDatabaseService(): DatabaseService;
32
34
  getFunctionService(): FunctionService;
package/types/index.d.ts CHANGED
@@ -17,6 +17,7 @@ interface CloudBaseConfig {
17
17
  envId?: string;
18
18
  proxy?: string;
19
19
  region?: string;
20
+ envType?: string;
20
21
  }
21
22
  declare class CloudBase {
22
23
  private static cloudBase;
@@ -17,6 +17,9 @@ export interface IOptions {
17
17
  export interface IFileOptions extends IOptions {
18
18
  localPath: string;
19
19
  cloudPath?: string;
20
+ parallel?: number;
21
+ retryCount?: number;
22
+ retryInterval?: number;
20
23
  }
21
24
  export interface IFilesOptions extends IOptions {
22
25
  ignore?: string | string[];
@@ -87,6 +90,9 @@ export declare class StorageService {
87
90
  * 上传文件夹
88
91
  * @param {string} localPath 本地文件夹路径
89
92
  * @param {string} cloudPath 云端文件夹
93
+ * @param {number} parallel 并发量
94
+ * @param {number} retryCount 重试次数
95
+ * @param {number} retryInterval 重试时间间隔(毫秒)
90
96
  * @param {(string | string[])} ignore
91
97
  * @param {(string | string[])} ignore
92
98
  * @returns {Promise<void>}
@@ -96,6 +102,9 @@ export declare class StorageService {
96
102
  * 上传文件夹,支持自定义 Region 和 Bucket
97
103
  * @param {string} localPath
98
104
  * @param {string} cloudPath
105
+ * @param {number} parallel
106
+ * @param {number} retryCount
107
+ * @param {number} retryInterval
99
108
  * @param {string} bucket
100
109
  * @param {string} region
101
110
  * @param {IOptions} options
@@ -284,5 +293,15 @@ export declare class StorageService {
284
293
  * 获取存储桶配置
285
294
  */
286
295
  private getStorageConfig;
296
+ /**
297
+ * 带重试功能的上传多文件函数
298
+ * @param uploadFiles sdk上传函数
299
+ * @param options sdk上传函数参数
300
+ * @param times 重试次数
301
+ * @param interval 重试时间间隔(毫秒)
302
+ * @param failedFiles 失败文件列表
303
+ * @returns
304
+ */
305
+ private uploadFilesWithRetry;
287
306
  }
288
307
  export {};