@cloudbase/manager-node 3.10.0 → 3.11.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.
@@ -131,7 +131,7 @@ class HostingService {
131
131
  * @param options
132
132
  */
133
133
  async uploadFiles(options) {
134
- const { localPath, cloudPath, files = [], onProgress, onFileFinish, parallel = 20, ignore } = options;
134
+ const { localPath, cloudPath, files = [], onProgress, onFileFinish, parallel = 20, ignore, retryCount, retryInterval } = options;
135
135
  const hosting = await this.checkStatus();
136
136
  const { Bucket, Regoin } = hosting;
137
137
  const storageService = await this.environment.getStorageService();
@@ -150,7 +150,9 @@ class HostingService {
150
150
  onProgress,
151
151
  onFileFinish,
152
152
  fileId: false,
153
- ignore
153
+ ignore,
154
+ retryCount,
155
+ retryInterval,
154
156
  });
155
157
  }
156
158
  else {
@@ -171,7 +173,9 @@ class HostingService {
171
173
  bucket: Bucket,
172
174
  region: Regoin,
173
175
  files: uploadFiles,
174
- fileId: false
176
+ fileId: false,
177
+ retryCount,
178
+ retryInterval,
175
179
  });
176
180
  }
177
181
  /**
@@ -49,7 +49,7 @@ class StorageService {
49
49
  * @param options
50
50
  */
51
51
  async uploadFiles(options) {
52
- const { files, onProgress, parallel, onFileFinish, ignore } = options;
52
+ const { files, onProgress, parallel, onFileFinish, ignore, retryCount, retryInterval } = options;
53
53
  const { bucket, region } = this.getStorageConfig();
54
54
  return this.uploadFilesCustom({
55
55
  files,
@@ -58,7 +58,9 @@ class StorageService {
58
58
  ignore,
59
59
  parallel,
60
60
  onProgress,
61
- onFileFinish
61
+ onFileFinish,
62
+ retryCount,
63
+ retryInterval
62
64
  });
63
65
  }
64
66
  /**
@@ -257,7 +259,7 @@ class StorageService {
257
259
  * @param options
258
260
  */
259
261
  async uploadFilesCustom(options) {
260
- const { files, bucket, region, ignore, onProgress, onFileFinish, fileId = true, parallel = 20 } = options;
262
+ const { files, bucket, region, ignore, onProgress, onFileFinish, fileId = true, parallel = 20, retryCount = 0, retryInterval = 500 } = options;
261
263
  if (!files || !files.length) {
262
264
  return;
263
265
  }
@@ -291,11 +293,24 @@ class StorageService {
291
293
  fileList = await asyncTaskController.run();
292
294
  const cos = this.getCos(parallel);
293
295
  const uploadFiles = util_1.default.promisify(cos.uploadFiles).bind(cos);
294
- return uploadFiles({
295
- onProgress,
296
- onFileFinish,
296
+ const params = {
297
297
  files: fileList,
298
- SliceSize: BIG_FILE_SIZE
298
+ SliceSize: BIG_FILE_SIZE,
299
+ onProgress,
300
+ onFileFinish
301
+ };
302
+ // return uploadFiles({
303
+ // onProgress,
304
+ // onFileFinish,
305
+ // files: fileList,
306
+ // SliceSize: BIG_FILE_SIZE
307
+ // })
308
+ return this.uploadFilesWithRetry({
309
+ uploadFiles,
310
+ options: params,
311
+ times: retryCount,
312
+ interval: retryInterval,
313
+ failedFiles: []
299
314
  });
300
315
  }
301
316
  /**
@@ -790,7 +805,6 @@ class StorageService {
790
805
  params.WebsiteConfiguration.RoutingRules.push(routeItem);
791
806
  }
792
807
  }
793
- console.log('params:', JSON.stringify(params));
794
808
  const res = await putBucketWebsite(params);
795
809
  return res;
796
810
  }
@@ -873,13 +887,11 @@ class StorageService {
873
887
  * @returns
874
888
  */
875
889
  async uploadFilesWithRetry({ uploadFiles, options, times, interval, failedFiles }) {
876
- console.log('times', times);
877
890
  const { files, onFileFinish } = options;
878
891
  const tempFailedFiles = [];
879
892
  const res = await uploadFiles(Object.assign(Object.assign({}, options), { files: failedFiles.length
880
893
  ? files.filter(file => failedFiles.includes(file.Key))
881
894
  : files, onFileFinish: (...args) => {
882
- console.log('args', args);
883
895
  const error = args[0];
884
896
  const fileInfo = args[2];
885
897
  if (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/manager-node",
3
- "version": "3.10.0",
3
+ "version": "3.11.0",
4
4
  "description": "The node manage service api for cloudbase.",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -38,6 +38,10 @@ export interface IHostingFileOptions {
38
38
  onProgress?: OnProgress
39
39
  onFileFinish?: OnFileFinish
40
40
  ignore?: string | string[]
41
+ // 重试次数
42
+ retryCount?: number
43
+ // 重试时间间隔(毫秒)
44
+ retryInterval?: number
41
45
  }
42
46
 
43
47
  export interface IHostingFilesOptions {
@@ -52,6 +56,10 @@ export interface IHostingFilesOptions {
52
56
  onProgress?: OnProgress
53
57
  onFileFinish?: OnFileFinish
54
58
  ignore?: string | string[]
59
+ // 重试次数
60
+ retryCount?: number
61
+ // 重试时间间隔(毫秒)
62
+ retryInterval?: number
55
63
  }
56
64
 
57
65
  export type IHostingOptions = IHostingFileOptions | IHostingFilesOptions
@@ -331,7 +339,9 @@ export class HostingService {
331
339
  onProgress,
332
340
  onFileFinish,
333
341
  parallel = 20,
334
- ignore
342
+ ignore,
343
+ retryCount,
344
+ retryInterval
335
345
  } = options
336
346
 
337
347
  const hosting = await this.checkStatus()
@@ -355,7 +365,9 @@ export class HostingService {
355
365
  onProgress,
356
366
  onFileFinish,
357
367
  fileId: false,
358
- ignore
368
+ ignore,
369
+ retryCount,
370
+ retryInterval,
359
371
  })
360
372
  } else {
361
373
  // 文件上传统一通过批量上传接口
@@ -376,7 +388,9 @@ export class HostingService {
376
388
  bucket: Bucket,
377
389
  region: Regoin,
378
390
  files: uploadFiles,
379
- fileId: false
391
+ fileId: false,
392
+ retryCount,
393
+ retryInterval,
380
394
  })
381
395
  }
382
396
 
@@ -62,6 +62,11 @@ export interface IFilesOptions extends IOptions {
62
62
  ignore?: string | string[]
63
63
  // 文件列表
64
64
  files: { localPath: string; cloudPath?: string }[]
65
+
66
+ // 重试次数
67
+ retryCount?: number
68
+ // 重试时间间隔(毫秒)
69
+ retryInterval?: number
65
70
  }
66
71
 
67
72
  export interface ICustomOptions {
@@ -141,7 +146,8 @@ export class StorageService {
141
146
  */
142
147
  @preLazy()
143
148
  public async uploadFiles(options: IFilesOptions): Promise<void> {
144
- const { files, onProgress, parallel, onFileFinish, ignore } = options
149
+ const { files, onProgress, parallel, onFileFinish, ignore, retryCount,
150
+ retryInterval } = options
145
151
  const { bucket, region } = this.getStorageConfig()
146
152
 
147
153
  return this.uploadFilesCustom({
@@ -151,7 +157,9 @@ export class StorageService {
151
157
  ignore,
152
158
  parallel,
153
159
  onProgress,
154
- onFileFinish
160
+ onFileFinish,
161
+ retryCount,
162
+ retryInterval
155
163
  })
156
164
  }
157
165
 
@@ -403,7 +411,9 @@ export class StorageService {
403
411
  onProgress,
404
412
  onFileFinish,
405
413
  fileId = true,
406
- parallel = 20
414
+ parallel = 20,
415
+ retryCount = 0,
416
+ retryInterval = 500
407
417
  } = options
408
418
 
409
419
  if (!files || !files.length) {
@@ -446,11 +456,25 @@ export class StorageService {
446
456
  const cos = this.getCos(parallel)
447
457
  const uploadFiles = Util.promisify(cos.uploadFiles).bind(cos)
448
458
 
449
- return uploadFiles({
450
- onProgress,
451
- onFileFinish,
459
+ const params = {
452
460
  files: fileList,
453
- SliceSize: BIG_FILE_SIZE
461
+ SliceSize: BIG_FILE_SIZE,
462
+ onProgress,
463
+ onFileFinish
464
+ }
465
+
466
+ // return uploadFiles({
467
+ // onProgress,
468
+ // onFileFinish,
469
+ // files: fileList,
470
+ // SliceSize: BIG_FILE_SIZE
471
+ // })
472
+ return this.uploadFilesWithRetry({
473
+ uploadFiles,
474
+ options: params,
475
+ times: retryCount,
476
+ interval: retryInterval,
477
+ failedFiles: []
454
478
  })
455
479
  }
456
480
 
@@ -1068,7 +1092,6 @@ export class StorageService {
1068
1092
  }
1069
1093
  }
1070
1094
 
1071
- console.log('params:', JSON.stringify(params))
1072
1095
  const res = await putBucketWebsite(params)
1073
1096
 
1074
1097
  return res
@@ -1165,7 +1188,6 @@ export class StorageService {
1165
1188
  * @returns
1166
1189
  */
1167
1190
  private async uploadFilesWithRetry({ uploadFiles, options, times, interval, failedFiles }) {
1168
- console.log('times', times)
1169
1191
  const { files, onFileFinish } = options
1170
1192
  const tempFailedFiles = []
1171
1193
  const res = await uploadFiles({
@@ -1174,7 +1196,6 @@ export class StorageService {
1174
1196
  ? files.filter(file => failedFiles.includes(file.Key))
1175
1197
  : files,
1176
1198
  onFileFinish: (...args) => {
1177
- console.log('args', args)
1178
1199
  const error = args[0]
1179
1200
  const fileInfo = (args as any)[2]
1180
1201
  if (error) {
@@ -20,6 +20,8 @@ export interface IHostingFileOptions {
20
20
  onProgress?: OnProgress;
21
21
  onFileFinish?: OnFileFinish;
22
22
  ignore?: string | string[];
23
+ retryCount?: number;
24
+ retryInterval?: number;
23
25
  }
24
26
  export interface IHostingFilesOptions {
25
27
  localPath?: string;
@@ -32,6 +34,8 @@ export interface IHostingFilesOptions {
32
34
  onProgress?: OnProgress;
33
35
  onFileFinish?: OnFileFinish;
34
36
  ignore?: string | string[];
37
+ retryCount?: number;
38
+ retryInterval?: number;
35
39
  }
36
40
  export declare type IHostingOptions = IHostingFileOptions | IHostingFilesOptions;
37
41
  export interface IHostingCloudOptions {
@@ -27,6 +27,8 @@ export interface IFilesOptions extends IOptions {
27
27
  localPath: string;
28
28
  cloudPath?: string;
29
29
  }[];
30
+ retryCount?: number;
31
+ retryInterval?: number;
30
32
  }
31
33
  export interface ICustomOptions {
32
34
  bucket: string;