@cloudbase/manager-node 5.8.7 → 5.8.8-beta.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/env/index.js CHANGED
@@ -17,6 +17,7 @@ const signature_nodejs_1 = require("@cloudbase/signature-nodejs");
17
17
  const error_1 = require("../error");
18
18
  const utils_1 = require("../utils");
19
19
  const constant_1 = require("../constant");
20
+ const storage_config_1 = require("../utils/storage-config");
20
21
  const billing_1 = require("../billing");
21
22
  const uuid_1 = require("uuid");
22
23
  class EnvService {
@@ -828,25 +829,6 @@ class EnvService {
828
829
  async deleteHttpServiceRoute(params) {
829
830
  return this.cloudService.request('DeleteHTTPServiceRoute', Object.assign({}, params));
830
831
  }
831
- /**
832
- * 清除HTTP访问服务域名缓存
833
- * 支持 CDN 和 EO 两种缓存类型。CDN 仅支持 PURGE_URL 刷新方式;PURGE_PREFIX / PURGE_HOST 仅 EO 支持
834
- * 清除缓存后会生成任务ID,可通过 DescribeHTTPServiceCachePurgeTask 查询任务进度和详细信息
835
- * @param {PurgeHttpServiceCacheParams} params 清除缓存参数
836
- * @returns {Promise<PurgeHttpServiceCacheRes>}
837
- */
838
- async purgeHttpServiceCache(params) {
839
- return this.cloudService.request('PurgeHTTPServiceCache', Object.assign({}, params));
840
- }
841
- /**
842
- * 查询HTTP访问服务域名缓存清除任务详情
843
- * 通过 purgeHttpServiceCache 清除域名缓存后,可传入任务ID查询清除任务状态、时间、缓存类型等信息;也可不传任务ID查询历史任务记录
844
- * @param {DescribeHttpServiceCachePurgeTaskParams} params 查询参数
845
- * @returns {Promise<DescribeHttpServiceCachePurgeTaskRes>}
846
- */
847
- async describeHttpServiceCachePurgeTask(params) {
848
- return this.cloudService.request('DescribeHTTPServiceCachePurgeTask', Object.assign({}, params));
849
- }
850
832
  /**
851
833
  * 绑定自定义域名到HTTP访问服务
852
834
  * 底层调用 CreateHTTPServiceRoute API,专用于域名绑定场景
@@ -919,7 +901,14 @@ class EnvService {
919
901
  return res.CORSRules;
920
902
  }
921
903
  // 添加 COS CORS 域名,和 Web 端行为保持一致
904
+ // 共享桶(ExternalStorage)环境直接跳过:桶的 CORS 规则作用于桶内所有环境,不能随单个环境的安全域名覆盖;
905
+ // 调用方未 await 此方法,这里不抛错,避免产生未处理的 Promise rejection
922
906
  async modifyCosCorsDomain(domain, deleted = false) {
907
+ var _a, _b, _c;
908
+ const storage = (_b = (_a = this.environment.lazyEnvironmentConfig) === null || _a === void 0 ? void 0 : _a.Storages) === null || _b === void 0 ? void 0 : _b[0];
909
+ if (!(storage === null || storage === void 0 ? void 0 : storage.Bucket) && ((_c = storage === null || storage === void 0 ? void 0 : storage.ExternalStorage) === null || _c === void 0 ? void 0 : _c.Enabled) === true) {
910
+ return;
911
+ }
923
912
  const cos = this.getCos();
924
913
  const putBucketCors = util_1.default.promisify(cos.putBucketCors).bind(cos);
925
914
  const { bucket, region } = this.getStorageConfig();
@@ -966,15 +955,7 @@ class EnvService {
966
955
  return new cos_nodejs_sdk_v5_1.default(cosConfig);
967
956
  }
968
957
  getStorageConfig() {
969
- var _a;
970
- const envConfig = this.environment.lazyEnvironmentConfig;
971
- const storageConfig = (_a = envConfig === null || envConfig === void 0 ? void 0 : envConfig.Storages) === null || _a === void 0 ? void 0 : _a[0];
972
- const { Region, Bucket } = storageConfig;
973
- return {
974
- env: envConfig.EnvId,
975
- region: Region,
976
- bucket: Bucket
977
- };
958
+ return (0, storage_config_1.resolveStorageConfig)(this.environment.lazyEnvironmentConfig);
978
959
  }
979
960
  parseBillTags(billTags) {
980
961
  if (typeof billTags !== 'string') {
@@ -16,6 +16,7 @@ const make_dir_1 = __importDefault(require("make-dir"));
16
16
  const error_1 = require("../error");
17
17
  const utils_1 = require("../utils");
18
18
  const parallel_1 = require("../utils/parallel");
19
+ const storage_config_1 = require("../utils/storage-config");
19
20
  const envDomainCache = new Map();
20
21
  const HostingStatusMap = {
21
22
  init: '初始化中',
@@ -66,13 +67,13 @@ class HostingService {
66
67
  };
67
68
  }
68
69
  async findFiles(options) {
69
- const hosting = await this.checkStatus();
70
- const { Bucket, Regoin } = hosting;
70
+ const { bucket, region, basePath } = await this.getHostingBucket();
71
71
  const { maxKeys, marker, prefix } = options;
72
72
  const storageService = await this.environment.getStorageService();
73
73
  const res = await storageService.getBucket({
74
- bucket: Bucket,
75
- region: Regoin,
74
+ bucket,
75
+ region,
76
+ basePath,
76
77
  maxKeys,
77
78
  marker,
78
79
  prefix
@@ -83,13 +84,13 @@ class HostingService {
83
84
  * 展示文件列表
84
85
  */
85
86
  async listFiles() {
86
- const hosting = await this.checkStatus();
87
- const { Bucket, Regoin } = hosting;
87
+ const { bucket, region, basePath } = await this.getHostingBucket();
88
88
  const storageService = await this.environment.getStorageService();
89
89
  const list = await storageService.walkCloudDirCustom({
90
90
  prefix: '',
91
- bucket: Bucket,
92
- region: Regoin
91
+ bucket,
92
+ region,
93
+ basePath
93
94
  });
94
95
  return list;
95
96
  }
@@ -132,8 +133,7 @@ class HostingService {
132
133
  */
133
134
  async uploadFiles(options) {
134
135
  const { localPath, cloudPath, entryFiles, files = [], onProgress, onFileFinish, parallel = 20, ignore = ['.DS_Store'], retryCount, retryInterval, verify = false, safe = false, prune = false } = options;
135
- const hosting = await this.checkStatus();
136
- const { Bucket, Regoin } = hosting;
136
+ const { bucket, region, basePath } = await this.getHostingBucket();
137
137
  const storageService = await this.environment.getStorageService();
138
138
  let uploadFiles = Array.isArray(files) ? files : [];
139
139
  // localPath 存在,上传文件夹/文件
@@ -147,8 +147,9 @@ class HostingService {
147
147
  localPath: resolvePath,
148
148
  cloudPath,
149
149
  entries: entryFiles,
150
- bucket: Bucket,
151
- region: Regoin,
150
+ bucket,
151
+ region,
152
+ basePath,
152
153
  onProgress,
153
154
  onFileFinish,
154
155
  fileId: false,
@@ -165,12 +166,14 @@ class HostingService {
165
166
  localPath: resolvePath,
166
167
  cloudPath,
167
168
  entryFiles,
168
- bucket: Bucket,
169
- region: Regoin,
169
+ bucket,
170
+ region,
171
+ basePath,
170
172
  onProgress,
171
173
  onFileFinish,
172
174
  fileId: false,
173
175
  ignore,
176
+ parallel,
174
177
  retryCount,
175
178
  retryInterval,
176
179
  });
@@ -190,8 +193,9 @@ class HostingService {
190
193
  parallel,
191
194
  onProgress,
192
195
  onFileFinish,
193
- bucket: Bucket,
194
- region: Regoin,
196
+ bucket,
197
+ region,
198
+ basePath,
195
199
  files: uploadFiles,
196
200
  fileId: false,
197
201
  retryCount,
@@ -204,19 +208,20 @@ class HostingService {
204
208
  */
205
209
  async deleteFiles(options) {
206
210
  const { cloudPath, isDir } = options;
207
- const hosting = await this.checkStatus();
208
- const { Bucket, Regoin } = hosting;
211
+ const { bucket, region, basePath } = await this.getHostingBucket();
209
212
  const storageService = await this.environment.getStorageService();
210
213
  if (isDir) {
211
214
  return storageService.deleteDirectoryCustom({
212
215
  cloudPath,
213
- bucket: Bucket,
214
- region: Regoin
216
+ bucket,
217
+ region,
218
+ basePath
215
219
  });
216
220
  }
217
221
  else {
218
222
  try {
219
- await storageService.deleteFileCustom([cloudPath], Bucket, Regoin);
223
+ // deleteFileCustom 按 COS 原始 Key 删除,共享桶下需先换算为物理 Key
224
+ await storageService.deleteFileCustom([(0, storage_config_1.toPhysicalKey)(basePath, cloudPath)], bucket, region);
220
225
  return {
221
226
  Deleted: [{ Key: cloudPath }],
222
227
  Error: []
@@ -281,14 +286,15 @@ class HostingService {
281
286
  async downloadDirectory(options) {
282
287
  const { cloudPath, localPath } = options;
283
288
  const resolveLocalPath = path_1.default.resolve(localPath);
284
- const hosting = await this.checkStatus();
285
- const { Bucket, Regoin } = hosting;
289
+ const { bucket, region, basePath } = await this.getHostingBucket();
286
290
  const cloudDirectoryKey = this.getCloudKey(cloudPath);
287
291
  const storageService = await this.environment.getStorageService();
292
+ // 返回逻辑路径,downloadFile 通过托管域名访问,网关会自动拼接 BasePath
288
293
  const files = await storageService.walkCloudDirCustom({
289
294
  prefix: cloudDirectoryKey,
290
- bucket: Bucket,
291
- region: Regoin
295
+ bucket,
296
+ region,
297
+ basePath
292
298
  });
293
299
  const tasks = files.map(file => async () => {
294
300
  const fileRelativePath = file.Key.replace(cloudDirectoryKey, '');
@@ -389,10 +395,9 @@ class HostingService {
389
395
  * @memberof HostingService
390
396
  */
391
397
  async getWebsiteConfig() {
392
- const hosting = await this.checkStatus();
393
- const { Bucket, Regoin } = hosting;
398
+ const { bucket, region } = await this.getHostingBucket();
394
399
  const storageService = await this.environment.getStorageService();
395
- const res = await storageService.getWebsiteConfig({ bucket: Bucket, region: Regoin });
400
+ const res = await storageService.getWebsiteConfig({ bucket, region });
396
401
  return res;
397
402
  }
398
403
  /**
@@ -401,12 +406,15 @@ class HostingService {
401
406
  */
402
407
  async setWebsiteDocument(options) {
403
408
  const { indexDocument, errorDocument, originalHttpStatus, charity404, autoAddressing, routingRules } = options;
404
- const hosting = await this.checkStatus();
405
- const { Bucket, Regoin } = hosting;
409
+ const { bucket, region, basePath } = await this.getHostingBucket();
410
+ // 共享桶的静态网站配置作用于桶内所有环境,按兼容边界(桶级操作不可作用于共享桶本身)明确拒绝
411
+ if (basePath) {
412
+ throw new error_1.CloudBaseError('当前环境的静态托管使用共享桶(ExternalStorage),静态网站配置作用于整个共享桶,由平台统一管理,不支持修改', { code: 'INVALID_OPERATION' });
413
+ }
406
414
  const storageService = await this.environment.getStorageService();
407
415
  const res = await storageService.putBucketWebsite({
408
- bucket: Bucket,
409
- region: Regoin,
416
+ bucket,
417
+ region,
410
418
  indexDocument,
411
419
  errorDocument,
412
420
  originalHttpStatus,
@@ -434,6 +442,19 @@ class HostingService {
434
442
  }
435
443
  return website;
436
444
  }
445
+ /**
446
+ * 检查 hosting 服务状态并解析有效桶,兼容共享桶(ExternalStorage)环境
447
+ * 静态托管的共享桶与 BasePath 独立于云存储,不能复用 StorageService.getStorageConfig
448
+ */
449
+ async getHostingBucket() {
450
+ const website = await this.checkStatus();
451
+ return (0, storage_config_1.resolveBucketConfig)({
452
+ envId: this.environment.getEnvId(),
453
+ bucket: website.Bucket,
454
+ region: website.Regoin,
455
+ externalStorage: website.ExternalStorage
456
+ });
457
+ }
437
458
  /**
438
459
  * 获取配置
439
460
  */