@cloudbase/manager-node 5.5.7-beta.0 → 5.5.7-beta.1

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.
@@ -452,11 +452,34 @@ class StorageService {
452
452
  // 每批次重新获取 COS 实例(刷新 STS 临时凭证)
453
453
  const cos = this.getCos(parallel);
454
454
  const uploadFiles = util_1.default.promisify(cos.uploadFiles).bind(cos);
455
+ // 跟踪本批次中真正失败的文件(通过 onFileFinish 回调)
456
+ const batchFailedFiles = [];
457
+ const batchSuccessFiles = new Set();
455
458
  const params = {
456
459
  files: batchFiles,
457
460
  SliceSize: BIG_FILE_SIZE,
458
461
  onProgress,
459
- onFileFinish
462
+ onFileFinish: (error, result, file) => {
463
+ // 空值检查:防止 file 为 null/undefined
464
+ if (!file) {
465
+ console.warn('[parallel-upload] onFileFinish received null/undefined file');
466
+ return;
467
+ }
468
+ const fileKey = file.Key || file.cloudFileKey;
469
+ if (error) {
470
+ batchFailedFiles.push({
471
+ filePath: file.FilePath || file.filePath,
472
+ cloudFileKey: fileKey,
473
+ error: error.message || String(error)
474
+ });
475
+ }
476
+ else {
477
+ batchSuccessFiles.add(fileKey);
478
+ }
479
+ // 继续调用用户传入的回调(转换参数格式)
480
+ // 注意:cloudFileKey 和 filePath 是 CLI 期望的格式
481
+ onFileFinish === null || onFileFinish === void 0 ? void 0 : onFileFinish(error, result, Object.assign(Object.assign({}, file), { cloudFileKey: fileKey, filePath: file.FilePath || file.filePath }));
482
+ }
460
483
  };
461
484
  try {
462
485
  await this.uploadFilesWithRetry({
@@ -470,12 +493,20 @@ class StorageService {
470
493
  }
471
494
  catch (error) {
472
495
  console.error(`[parallel-upload] 第 ${Math.floor(batchStart / BATCH_SIZE) + 1} 批次上传失败:`, error.message || error.code || error);
473
- // 记录当前批次所有文件为失败
474
- allFailedFiles.push(...batchFiles.map(f => ({
475
- filePath: f.FilePath || f.filePath,
476
- cloudFileKey: f.Key || f.cloudFileKey,
477
- error: error.message || String(error)
478
- })));
496
+ // 只记录真正失败的文件(通过 onFileFinish 回调跟踪)
497
+ // 如果 onFileFinish 没有被调用(如 socket hang up),则标记整个批次为失败
498
+ if (batchFailedFiles.length === 0 && batchSuccessFiles.size === 0) {
499
+ // onFileFinish 未被调用,整个批次失败
500
+ allFailedFiles.push(...batchFiles.map(f => ({
501
+ filePath: f.FilePath || f.filePath,
502
+ cloudFileKey: f.Key || f.cloudFileKey,
503
+ error: error.message || String(error)
504
+ })));
505
+ }
506
+ else {
507
+ // onFileFinish 已被调用,只记录失败的文件
508
+ allFailedFiles.push(...batchFailedFiles);
509
+ }
479
510
  }
480
511
  }
481
512
  // 返回失败文件列表(不抛异常,让调用方决定是否走串行重试)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/manager-node",
3
- "version": "5.5.7-beta.0",
3
+ "version": "5.5.7-beta.1",
4
4
  "description": "The node manage service api for cloudbase.",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {