@cloudbase/manager-node 5.0.0 → 5.1.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.
@@ -1477,14 +1477,16 @@ class FunctionService {
1477
1477
  });
1478
1478
  }
1479
1479
  /**
1480
- * 通过scf COS 上传方式(通过 GetTempCosInfo + COS SDK 上传)
1480
+ * 通过 SCF COS 上传方式(通过 GetTempCosInfo + COS SDK 上传)
1481
1481
  * 返回 TempCosObjectName 用于创建/更新函数
1482
1482
  */
1483
- async uploadFunctionZipToCosLegacy(options, installDependency) {
1483
+ async uploadFunctionZipToCos(options, installDependency) {
1484
1484
  const { func, functionPath, functionRootPath } = options;
1485
- const { env } = this.getFunctionConfig();
1486
- const { CloudAppId } = await this.userService.getTcbAccountInfo();
1487
- const objectPath = `${CloudAppId}/${env}/${func.name}.zip`;
1485
+ const { env, appId } = this.getFunctionConfig();
1486
+ if (!appId) {
1487
+ throw new error_1.CloudBaseError('无法获取 AppId,请确认环境已开通存储服务');
1488
+ }
1489
+ const objectPath = `${appId}/${env}/${func.name}.zip`;
1488
1490
  // 1. 生成存放函数包的临时 Cos 目录
1489
1491
  const { Date: cosDate, Sign } = await this.scfService.request('GetTempCosInfo', {
1490
1492
  ObjectPath: `${objectPath}`
@@ -1545,10 +1547,11 @@ class FunctionService {
1545
1547
  });
1546
1548
  }
1547
1549
  /**
1548
- * 新的 COS 上传方式(通过 DescribeBuildServiceCosInfo + PUT 上传)
1550
+ * 旧的 COS 上传方式(通过 DescribeBuildServiceCosInfo + PUT 上传)
1549
1551
  * 返回 CosTimestamp 用于创建/更新函数
1552
+ * @deprecated 请使用 uploadFunctionZipToCos 代替
1550
1553
  */
1551
- async uploadFunctionZipToCos(options, installDependency) {
1554
+ async uploadFunctionZipToCosLegacy(options, installDependency) {
1552
1555
  const { func, functionPath, functionRootPath } = options;
1553
1556
  const { env } = this.getFunctionConfig();
1554
1557
  // 1. 生成存放函数包的临时 Cos 目录
@@ -1649,13 +1652,13 @@ class FunctionService {
1649
1652
  ZipFile: base64
1650
1653
  };
1651
1654
  }
1652
- // 默认走 COS 上传
1655
+ // 默认走 COS 上传(GetTempCosInfo + COS SDK)
1653
1656
  console.log(`[${func.name}] 部署方式: COS 上传`);
1654
1657
  const region = this.environment.cloudBaseContext.region || constant_1.SCF_TEMP_COS.DEFAULT_REGION;
1655
- const legacyResult = await this.uploadFunctionZipToCosLegacy(options, installDependency);
1658
+ const result = await this.uploadFunctionZipToCos(options, installDependency);
1656
1659
  return {
1657
1660
  CosBucketRegion: region,
1658
- TempCosObjectName: `/${legacyResult.Key}`
1661
+ TempCosObjectName: `/${result.Key}`
1659
1662
  };
1660
1663
  }
1661
1664
  async createAccessPath(name, path) {
@@ -1717,11 +1720,14 @@ class FunctionService {
1717
1720
  * @memberof FunctionService
1718
1721
  */
1719
1722
  getFunctionConfig() {
1720
- var _a, _b, _c, _d;
1723
+ var _a, _b, _c, _d, _e;
1721
1724
  const envConfig = this.environment.lazyEnvironmentConfig;
1722
1725
  // Functions 可能为空
1723
1726
  const namespace = ((_b = (_a = envConfig.Functions) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.Namespace) || '';
1724
- const appId = (_d = (_c = envConfig.Storages) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.AppId;
1727
+ // AppId 可能为空字符串,从 Bucket 名称中提取
1728
+ // COS Bucket 格式: {BucketName}-{APPID},APPID 为纯数字
1729
+ const storage = (_c = envConfig.Storages) === null || _c === void 0 ? void 0 : _c[0];
1730
+ const appId = (storage === null || storage === void 0 ? void 0 : storage.AppId) || ((_e = (_d = storage === null || storage === void 0 ? void 0 : storage.Bucket) === null || _d === void 0 ? void 0 : _d.match(/-(\d+)$/)) === null || _e === void 0 ? void 0 : _e[1]) || '';
1725
1731
  const { proxy } = this.environment.cloudBaseContext;
1726
1732
  return {
1727
1733
  proxy,
@@ -1882,10 +1888,10 @@ __decorate([
1882
1888
  ], FunctionService.prototype, "getFunctionAlias", null);
1883
1889
  __decorate([
1884
1890
  (0, utils_1.preLazy)()
1885
- ], FunctionService.prototype, "uploadFunctionZipToCosLegacy", null);
1891
+ ], FunctionService.prototype, "uploadFunctionZipToCos", null);
1886
1892
  __decorate([
1887
1893
  (0, utils_1.preLazy)()
1888
- ], FunctionService.prototype, "uploadFunctionZipToCos", null);
1894
+ ], FunctionService.prototype, "uploadFunctionZipToCosLegacy", null);
1889
1895
  __decorate([
1890
1896
  (0, utils_1.preLazy)()
1891
1897
  ], FunctionService.prototype, "getCodeParams", null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/manager-node",
3
- "version": "5.0.0",
3
+ "version": "5.1.0",
4
4
  "description": "The node manage service api for cloudbase.",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {