@cloudbase/manager-node 4.2.10 → 4.3.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/access/index.js +9 -9
- package/lib/cloudBaseRun/index.js +3 -3
- package/lib/cloudrun/index.js +157 -0
- package/lib/cloudrun/type.js +14 -0
- package/lib/database/index.js +1 -1
- package/lib/env/index.js +9 -8
- package/lib/environment.js +9 -4
- package/lib/function/index.js +39 -36
- package/lib/function/packer.js +42 -9
- package/lib/hosting/index.js +19 -19
- package/lib/index.js +17 -14
- package/lib/interfaces/index.js +6 -2
- package/lib/storage/index.js +38 -38
- package/lib/user/index.js +7 -7
- package/lib/utils/auth.js +1 -2
- package/lib/utils/cloud-api-request.js +5 -5
- package/lib/utils/cloudbase-request.js +3 -4
- package/lib/utils/envLazy.js +1 -2
- package/lib/utils/fs.js +5 -6
- package/lib/utils/http-request.js +6 -7
- package/lib/utils/index.js +70 -17
- package/lib/utils/runenv.js +1 -2
- package/lib/utils/uuid.js +2 -3
- package/package.json +16 -6
- package/scripts/link.js +98 -0
- package/tsconfig.json +2 -1
- package/types/cloudrun/index.d.ts +81 -0
- package/types/cloudrun/type.d.ts +315 -0
- package/types/env/index.d.ts +1 -1
- package/types/environment.d.ts +3 -0
- package/types/function/types.d.ts +1 -1
- package/types/hosting/index.d.ts +3 -4
- package/types/index.d.ts +2 -0
- package/types/storage/index.d.ts +3 -4
- package/types/user/types.d.ts +1 -1
- package/types/utils/fs.d.ts +1 -1
- package/types/utils/http-request.d.ts +3 -2
- package/types/utils/index.d.ts +18 -3
- package/types/utils/parallel.d.ts +1 -1
package/lib/hosting/index.js
CHANGED
|
@@ -23,7 +23,7 @@ const HostingStatusMap = {
|
|
|
23
23
|
online: '上线',
|
|
24
24
|
destroying: '销毁中',
|
|
25
25
|
offline: '下线',
|
|
26
|
-
create_fail: '初始化失败',
|
|
26
|
+
create_fail: '初始化失败', // eslint-disable-line
|
|
27
27
|
destroy_fail: '销毁失败' // eslint-disable-line
|
|
28
28
|
};
|
|
29
29
|
class HostingService {
|
|
@@ -140,8 +140,8 @@ class HostingService {
|
|
|
140
140
|
if (localPath) {
|
|
141
141
|
const resolvePath = path_1.default.resolve(localPath);
|
|
142
142
|
// 检查路径是否存在
|
|
143
|
-
utils_1.checkReadable(resolvePath, true);
|
|
144
|
-
if (utils_1.isDirectory(resolvePath)) {
|
|
143
|
+
(0, utils_1.checkReadable)(resolvePath, true);
|
|
144
|
+
if ((0, utils_1.isDirectory)(resolvePath)) {
|
|
145
145
|
return storageService.uploadDirectoryCustom({
|
|
146
146
|
localPath: resolvePath,
|
|
147
147
|
cloudPath,
|
|
@@ -220,7 +220,7 @@ class HostingService {
|
|
|
220
220
|
const { cloudPath, localPath } = options;
|
|
221
221
|
if (localPath) {
|
|
222
222
|
const fileDir = path_1.default.dirname(localPath);
|
|
223
|
-
utils_1.checkFullAccess(fileDir, true);
|
|
223
|
+
(0, utils_1.checkFullAccess)(fileDir, true);
|
|
224
224
|
}
|
|
225
225
|
const envConfig = this.environment.lazyEnvironmentConfig;
|
|
226
226
|
const cacheHosting = envDomainCache.get(envConfig.EnvId);
|
|
@@ -237,7 +237,7 @@ class HostingService {
|
|
|
237
237
|
}
|
|
238
238
|
const url = new URL(cloudPath, `https://${CdnDomain}`).toString();
|
|
239
239
|
const { proxy } = await this.environment.getAuthConfig();
|
|
240
|
-
const res = await utils_1.fetchStream(url, {}, proxy);
|
|
240
|
+
const res = await (0, utils_1.fetchStream)(url, {}, proxy);
|
|
241
241
|
// localPath 不存在时,返回 ReadableStream
|
|
242
242
|
if (!localPath) {
|
|
243
243
|
return res.body;
|
|
@@ -280,7 +280,7 @@ class HostingService {
|
|
|
280
280
|
const localFilePath = path_1.default.join(resolveLocalPath, fileRelativePath);
|
|
281
281
|
// 创建文件的父文件夹
|
|
282
282
|
const fileDir = path_1.default.dirname(localFilePath);
|
|
283
|
-
await make_dir_1.default(fileDir);
|
|
283
|
+
await (0, make_dir_1.default)(fileDir);
|
|
284
284
|
return this.downloadFile({
|
|
285
285
|
cloudPath: file.Key,
|
|
286
286
|
localPath: localFilePath
|
|
@@ -424,40 +424,40 @@ class HostingService {
|
|
|
424
424
|
return cloudPath[cloudPath.length - 1] === '/' ? cloudPath : `${cloudPath}/`;
|
|
425
425
|
}
|
|
426
426
|
}
|
|
427
|
+
exports.HostingService = HostingService;
|
|
427
428
|
__decorate([
|
|
428
|
-
utils_1.preLazy()
|
|
429
|
+
(0, utils_1.preLazy)()
|
|
429
430
|
], HostingService.prototype, "getInfo", null);
|
|
430
431
|
__decorate([
|
|
431
|
-
utils_1.preLazy()
|
|
432
|
+
(0, utils_1.preLazy)()
|
|
432
433
|
], HostingService.prototype, "enableService", null);
|
|
433
434
|
__decorate([
|
|
434
|
-
utils_1.preLazy()
|
|
435
|
+
(0, utils_1.preLazy)()
|
|
435
436
|
], HostingService.prototype, "listFiles", null);
|
|
436
437
|
__decorate([
|
|
437
|
-
utils_1.preLazy()
|
|
438
|
+
(0, utils_1.preLazy)()
|
|
438
439
|
], HostingService.prototype, "destroyService", null);
|
|
439
440
|
__decorate([
|
|
440
|
-
utils_1.preLazy()
|
|
441
|
+
(0, utils_1.preLazy)()
|
|
441
442
|
], HostingService.prototype, "uploadFiles", null);
|
|
442
443
|
__decorate([
|
|
443
|
-
utils_1.preLazy()
|
|
444
|
+
(0, utils_1.preLazy)()
|
|
444
445
|
], HostingService.prototype, "deleteFiles", null);
|
|
445
446
|
__decorate([
|
|
446
|
-
utils_1.preLazy()
|
|
447
|
+
(0, utils_1.preLazy)()
|
|
447
448
|
], HostingService.prototype, "downloadFile", null);
|
|
448
449
|
__decorate([
|
|
449
|
-
utils_1.preLazy()
|
|
450
|
+
(0, utils_1.preLazy)()
|
|
450
451
|
], HostingService.prototype, "downloadDirectory", null);
|
|
451
452
|
__decorate([
|
|
452
|
-
utils_1.preLazy()
|
|
453
|
+
(0, utils_1.preLazy)()
|
|
453
454
|
], HostingService.prototype, "walkLocalDir", null);
|
|
454
455
|
__decorate([
|
|
455
|
-
utils_1.preLazy()
|
|
456
|
+
(0, utils_1.preLazy)()
|
|
456
457
|
], HostingService.prototype, "CreateHostingDomain", null);
|
|
457
458
|
__decorate([
|
|
458
|
-
utils_1.preLazy()
|
|
459
|
+
(0, utils_1.preLazy)()
|
|
459
460
|
], HostingService.prototype, "deleteHostingDomain", null);
|
|
460
461
|
__decorate([
|
|
461
|
-
utils_1.preLazy()
|
|
462
|
+
(0, utils_1.preLazy)()
|
|
462
463
|
], HostingService.prototype, "checkStatus", null);
|
|
463
|
-
exports.HostingService = HostingService;
|
package/lib/index.js
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
const context_1 = require("./context");
|
|
3
3
|
const environmentManager_1 = require("./environmentManager");
|
|
4
4
|
class CloudBase {
|
|
5
|
+
/**
|
|
6
|
+
* init 初始化 为单例
|
|
7
|
+
*
|
|
8
|
+
* @static
|
|
9
|
+
* @param {ManagerConfig} config
|
|
10
|
+
* @returns {CloudBase}
|
|
11
|
+
* @memberof CloudBase
|
|
12
|
+
*/
|
|
13
|
+
static init(config) {
|
|
14
|
+
if (!CloudBase.cloudBase) {
|
|
15
|
+
CloudBase.cloudBase = new CloudBase(config);
|
|
16
|
+
}
|
|
17
|
+
return CloudBase.cloudBase;
|
|
18
|
+
}
|
|
5
19
|
constructor(config = {}) {
|
|
6
20
|
this.cloudBaseConfig = {};
|
|
7
21
|
let { secretId, secretKey, token, envId, proxy, region, envType } = config;
|
|
@@ -23,20 +37,6 @@ class CloudBase {
|
|
|
23
37
|
this.environmentManager = new environmentManager_1.EnvironmentManager(this.context);
|
|
24
38
|
this.environmentManager.add(envId || '');
|
|
25
39
|
}
|
|
26
|
-
/**
|
|
27
|
-
* init 初始化 为单例
|
|
28
|
-
*
|
|
29
|
-
* @static
|
|
30
|
-
* @param {ManagerConfig} config
|
|
31
|
-
* @returns {CloudBase}
|
|
32
|
-
* @memberof CloudBase
|
|
33
|
-
*/
|
|
34
|
-
static init(config) {
|
|
35
|
-
if (!CloudBase.cloudBase) {
|
|
36
|
-
CloudBase.cloudBase = new CloudBase(config);
|
|
37
|
-
}
|
|
38
|
-
return CloudBase.cloudBase;
|
|
39
|
-
}
|
|
40
40
|
addEnvironment(envId) {
|
|
41
41
|
this.environmentManager.add(envId);
|
|
42
42
|
}
|
|
@@ -46,6 +46,9 @@ class CloudBase {
|
|
|
46
46
|
get functions() {
|
|
47
47
|
return this.currentEnvironment().getFunctionService();
|
|
48
48
|
}
|
|
49
|
+
get cloudrun() {
|
|
50
|
+
return this.currentEnvironment().getCloudRunService();
|
|
51
|
+
}
|
|
49
52
|
get storage() {
|
|
50
53
|
return this.currentEnvironment().getStorageService();
|
|
51
54
|
}
|
package/lib/interfaces/index.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
8
12
|
}));
|
|
9
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
-
for (var p in m) if (p !== "default" && !
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
15
|
};
|
|
12
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
17
|
__exportStar(require("./function.interface"), exports);
|
package/lib/storage/index.js
CHANGED
|
@@ -76,13 +76,13 @@ class StorageService {
|
|
|
76
76
|
const { localPath, cloudPath, bucket, region, onProgress, fileId = true } = options;
|
|
77
77
|
let localFilePath = '';
|
|
78
78
|
let resolveLocalPath = path_1.default.resolve(localPath);
|
|
79
|
-
utils_1.checkFullAccess(resolveLocalPath, true);
|
|
79
|
+
(0, utils_1.checkFullAccess)(resolveLocalPath, true);
|
|
80
80
|
// 如果 localPath 是一个文件夹,尝试在文件下寻找 cloudPath 中的文件
|
|
81
81
|
const fileStats = fs_1.default.statSync(resolveLocalPath);
|
|
82
82
|
if (fileStats.isDirectory()) {
|
|
83
83
|
const fileName = path_1.default.parse(cloudPath).base;
|
|
84
84
|
const attemptFilePath = path_1.default.join(localPath, fileName);
|
|
85
|
-
if (utils_1.checkFullAccess(attemptFilePath)) {
|
|
85
|
+
if ((0, utils_1.checkFullAccess)(attemptFilePath)) {
|
|
86
86
|
localFilePath = path_1.default.resolve(attemptFilePath);
|
|
87
87
|
}
|
|
88
88
|
}
|
|
@@ -191,7 +191,7 @@ class StorageService {
|
|
|
191
191
|
const fileKeyPath = filePath.replace(resolveLocalPath, '').replace(/\\/g, '/');
|
|
192
192
|
// 解析 cloudPath
|
|
193
193
|
let cloudFileKey = path_1.default.join(cloudPath, fileKeyPath).replace(/\\/g, '/');
|
|
194
|
-
if (utils_1.isDirectory(filePath)) {
|
|
194
|
+
if ((0, utils_1.isDirectory)(filePath)) {
|
|
195
195
|
cloudFileKey = this.getCloudKey(cloudFileKey);
|
|
196
196
|
return {
|
|
197
197
|
filePath,
|
|
@@ -358,11 +358,11 @@ class StorageService {
|
|
|
358
358
|
const { cloudPath, localPath } = options;
|
|
359
359
|
const resolveLocalPath = path_1.default.resolve(localPath);
|
|
360
360
|
const fileDir = path_1.default.dirname(localPath);
|
|
361
|
-
utils_1.checkFullAccess(fileDir, true);
|
|
361
|
+
(0, utils_1.checkFullAccess)(fileDir, true);
|
|
362
362
|
const urlList = await this.getTemporaryUrl([cloudPath]);
|
|
363
363
|
const { url } = urlList[0];
|
|
364
364
|
const { proxy } = await this.environment.getAuthConfig();
|
|
365
|
-
const res = await utils_1.fetchStream(url, {}, proxy);
|
|
365
|
+
const res = await (0, utils_1.fetchStream)(url, {}, proxy);
|
|
366
366
|
// localPath 不存在时,返回 ReadableStream
|
|
367
367
|
if (!localPath) {
|
|
368
368
|
return res.body;
|
|
@@ -386,7 +386,7 @@ class StorageService {
|
|
|
386
386
|
async downloadDirectory(options) {
|
|
387
387
|
const { cloudPath, localPath, parallel = 20 } = options;
|
|
388
388
|
const resolveLocalPath = path_1.default.resolve(localPath);
|
|
389
|
-
utils_1.checkFullAccess(resolveLocalPath, true);
|
|
389
|
+
(0, utils_1.checkFullAccess)(resolveLocalPath, true);
|
|
390
390
|
const cloudDirectoryKey = this.getCloudKey(cloudPath);
|
|
391
391
|
const files = await this.walkCloudDir(cloudDirectoryKey);
|
|
392
392
|
const promises = files.map(file => async () => {
|
|
@@ -462,7 +462,7 @@ class StorageService {
|
|
|
462
462
|
max_age: item.maxAge
|
|
463
463
|
}));
|
|
464
464
|
const config = this.environment.getAuthConfig();
|
|
465
|
-
const res = await utils_1.cloudBaseRequest({
|
|
465
|
+
const res = await (0, utils_1.cloudBaseRequest)({
|
|
466
466
|
config,
|
|
467
467
|
params: {
|
|
468
468
|
file_list: data,
|
|
@@ -492,7 +492,7 @@ class StorageService {
|
|
|
492
492
|
const { bucket, env } = this.getStorageConfig();
|
|
493
493
|
const fileIdList = cloudPathList.map(filePath => this.cloudPathToFileId(filePath));
|
|
494
494
|
const config = this.environment.getAuthConfig();
|
|
495
|
-
const res = await utils_1.cloudBaseRequest({
|
|
495
|
+
const res = await (0, utils_1.cloudBaseRequest)({
|
|
496
496
|
config,
|
|
497
497
|
params: {
|
|
498
498
|
action: 'storage.batchDeleteFile',
|
|
@@ -738,7 +738,7 @@ class StorageService {
|
|
|
738
738
|
*/
|
|
739
739
|
async getUploadMetadata(path) {
|
|
740
740
|
const config = this.environment.getAuthConfig();
|
|
741
|
-
const res = await utils_1.cloudBaseRequest({
|
|
741
|
+
const res = await (0, utils_1.cloudBaseRequest)({
|
|
742
742
|
config,
|
|
743
743
|
params: {
|
|
744
744
|
path,
|
|
@@ -847,12 +847,12 @@ class StorageService {
|
|
|
847
847
|
SecretKey: secretKey,
|
|
848
848
|
Proxy: cosProxy || proxy,
|
|
849
849
|
SecurityToken: token,
|
|
850
|
-
Domain: constant_1.USE_INTERNAL_ENDPOINT ? "{Bucket}.cos-internal.{Region}.tencentcos.cn" /* INTERNAL */ : "{Bucket}.cos.{Region}.tencentcos.cn" /* PUBLIC */,
|
|
850
|
+
Domain: constant_1.USE_INTERNAL_ENDPOINT ? "{Bucket}.cos-internal.{Region}.tencentcos.cn" /* COS_ENDPOINT.INTERNAL */ : "{Bucket}.cos.{Region}.tencentcos.cn" /* COS_ENDPOINT.PUBLIC */,
|
|
851
851
|
};
|
|
852
852
|
if (constant_1.COS_SDK_PROTOCOL) {
|
|
853
|
-
cosConfig.Protocol = constant_1.COS_SDK_PROTOCOL.endsWith(':')
|
|
853
|
+
cosConfig.Protocol = (constant_1.COS_SDK_PROTOCOL.endsWith(':')
|
|
854
854
|
? constant_1.COS_SDK_PROTOCOL.toLowerCase()
|
|
855
|
-
: constant_1.COS_SDK_PROTOCOL.toLowerCase() + ':';
|
|
855
|
+
: constant_1.COS_SDK_PROTOCOL.toLowerCase() + ':');
|
|
856
856
|
}
|
|
857
857
|
if (constant_1.USE_INTERNAL_ENDPOINT) {
|
|
858
858
|
cosConfig.Protocol = 'http:';
|
|
@@ -861,7 +861,7 @@ class StorageService {
|
|
|
861
861
|
if (constant_1.COS_SDK_KEEPALIVE) {
|
|
862
862
|
cosConfig.KeepAlive = { true: true, false: false }[constant_1.COS_SDK_KEEPALIVE];
|
|
863
863
|
}
|
|
864
|
-
else if (runenv_1.checkIsInScf()) {
|
|
864
|
+
else if ((0, runenv_1.checkIsInScf)()) {
|
|
865
865
|
cosConfig.KeepAlive = false;
|
|
866
866
|
}
|
|
867
867
|
return new cos_nodejs_sdk_v5_1.default(cosConfig);
|
|
@@ -965,7 +965,7 @@ class StorageService {
|
|
|
965
965
|
const localFilePath = path_1.default.join(resolveLocalPath, fileRelativePath);
|
|
966
966
|
// 创建文件的父文件夹
|
|
967
967
|
const fileDir = path_1.default.dirname(localFilePath);
|
|
968
|
-
await make_dir_1.default(fileDir);
|
|
968
|
+
await (0, make_dir_1.default)(fileDir);
|
|
969
969
|
return this.downloadFile({
|
|
970
970
|
cloudPath: file.Key,
|
|
971
971
|
localPath: localFilePath
|
|
@@ -982,73 +982,73 @@ class StorageService {
|
|
|
982
982
|
return resultErrorArr;
|
|
983
983
|
}
|
|
984
984
|
}
|
|
985
|
+
exports.StorageService = StorageService;
|
|
985
986
|
__decorate([
|
|
986
|
-
utils_1.preLazy()
|
|
987
|
+
(0, utils_1.preLazy)()
|
|
987
988
|
], StorageService.prototype, "uploadFile", null);
|
|
988
989
|
__decorate([
|
|
989
|
-
utils_1.preLazy()
|
|
990
|
+
(0, utils_1.preLazy)()
|
|
990
991
|
], StorageService.prototype, "uploadFiles", null);
|
|
991
992
|
__decorate([
|
|
992
|
-
utils_1.preLazy()
|
|
993
|
+
(0, utils_1.preLazy)()
|
|
993
994
|
], StorageService.prototype, "uploadFileCustom", null);
|
|
994
995
|
__decorate([
|
|
995
|
-
utils_1.preLazy()
|
|
996
|
+
(0, utils_1.preLazy)()
|
|
996
997
|
], StorageService.prototype, "uploadDirectory", null);
|
|
997
998
|
__decorate([
|
|
998
|
-
utils_1.preLazy()
|
|
999
|
+
(0, utils_1.preLazy)()
|
|
999
1000
|
], StorageService.prototype, "uploadDirectoryCustom", null);
|
|
1000
1001
|
__decorate([
|
|
1001
|
-
utils_1.preLazy()
|
|
1002
|
+
(0, utils_1.preLazy)()
|
|
1002
1003
|
], StorageService.prototype, "uploadFilesCustom", null);
|
|
1003
1004
|
__decorate([
|
|
1004
|
-
utils_1.preLazy()
|
|
1005
|
+
(0, utils_1.preLazy)()
|
|
1005
1006
|
], StorageService.prototype, "createCloudDirectroy", null);
|
|
1006
1007
|
__decorate([
|
|
1007
|
-
utils_1.preLazy()
|
|
1008
|
+
(0, utils_1.preLazy)()
|
|
1008
1009
|
], StorageService.prototype, "createCloudDirectroyCustom", null);
|
|
1009
1010
|
__decorate([
|
|
1010
|
-
utils_1.preLazy()
|
|
1011
|
+
(0, utils_1.preLazy)()
|
|
1011
1012
|
], StorageService.prototype, "downloadFile", null);
|
|
1012
1013
|
__decorate([
|
|
1013
|
-
utils_1.preLazy()
|
|
1014
|
+
(0, utils_1.preLazy)()
|
|
1014
1015
|
], StorageService.prototype, "downloadDirectory", null);
|
|
1015
1016
|
__decorate([
|
|
1016
|
-
utils_1.preLazy()
|
|
1017
|
+
(0, utils_1.preLazy)()
|
|
1017
1018
|
], StorageService.prototype, "listDirectoryFiles", null);
|
|
1018
1019
|
__decorate([
|
|
1019
|
-
utils_1.preLazy()
|
|
1020
|
+
(0, utils_1.preLazy)()
|
|
1020
1021
|
], StorageService.prototype, "getTemporaryUrl", null);
|
|
1021
1022
|
__decorate([
|
|
1022
|
-
utils_1.preLazy()
|
|
1023
|
+
(0, utils_1.preLazy)()
|
|
1023
1024
|
], StorageService.prototype, "deleteFile", null);
|
|
1024
1025
|
__decorate([
|
|
1025
|
-
utils_1.preLazy()
|
|
1026
|
+
(0, utils_1.preLazy)()
|
|
1026
1027
|
], StorageService.prototype, "deleteFileCustom", null);
|
|
1027
1028
|
__decorate([
|
|
1028
|
-
utils_1.preLazy()
|
|
1029
|
+
(0, utils_1.preLazy)()
|
|
1029
1030
|
], StorageService.prototype, "getFileInfo", null);
|
|
1030
1031
|
__decorate([
|
|
1031
|
-
utils_1.preLazy()
|
|
1032
|
+
(0, utils_1.preLazy)()
|
|
1032
1033
|
], StorageService.prototype, "deleteDirectory", null);
|
|
1033
1034
|
__decorate([
|
|
1034
|
-
utils_1.preLazy()
|
|
1035
|
+
(0, utils_1.preLazy)()
|
|
1035
1036
|
], StorageService.prototype, "deleteDirectoryCustom", null);
|
|
1036
1037
|
__decorate([
|
|
1037
|
-
utils_1.preLazy()
|
|
1038
|
+
(0, utils_1.preLazy)()
|
|
1038
1039
|
], StorageService.prototype, "getStorageAcl", null);
|
|
1039
1040
|
__decorate([
|
|
1040
|
-
utils_1.preLazy()
|
|
1041
|
+
(0, utils_1.preLazy)()
|
|
1041
1042
|
], StorageService.prototype, "setStorageAcl", null);
|
|
1042
1043
|
__decorate([
|
|
1043
|
-
utils_1.preLazy()
|
|
1044
|
+
(0, utils_1.preLazy)()
|
|
1044
1045
|
], StorageService.prototype, "walkCloudDir", null);
|
|
1045
1046
|
__decorate([
|
|
1046
|
-
utils_1.preLazy()
|
|
1047
|
+
(0, utils_1.preLazy)()
|
|
1047
1048
|
], StorageService.prototype, "walkCloudDirCustom", null);
|
|
1048
1049
|
__decorate([
|
|
1049
|
-
utils_1.preLazy()
|
|
1050
|
+
(0, utils_1.preLazy)()
|
|
1050
1051
|
], StorageService.prototype, "putBucketWebsite", null);
|
|
1051
1052
|
__decorate([
|
|
1052
|
-
utils_1.preLazy()
|
|
1053
|
+
(0, utils_1.preLazy)()
|
|
1053
1054
|
], StorageService.prototype, "getBucket", null);
|
|
1054
|
-
exports.StorageService = StorageService;
|
package/lib/user/index.js
CHANGED
|
@@ -115,22 +115,22 @@ class UserService {
|
|
|
115
115
|
return typeof obj === 'string' && obj.trim().length > 0;
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
|
+
exports.UserService = UserService;
|
|
118
119
|
__decorate([
|
|
119
|
-
utils_1.preLazy()
|
|
120
|
+
(0, utils_1.preLazy)()
|
|
120
121
|
], UserService.prototype, "getEndUserList", null);
|
|
121
122
|
__decorate([
|
|
122
|
-
utils_1.preLazy()
|
|
123
|
+
(0, utils_1.preLazy)()
|
|
123
124
|
], UserService.prototype, "setEndUserStatus", null);
|
|
124
125
|
__decorate([
|
|
125
|
-
utils_1.preLazy()
|
|
126
|
+
(0, utils_1.preLazy)()
|
|
126
127
|
], UserService.prototype, "deleteEndUsers", null);
|
|
127
128
|
__decorate([
|
|
128
|
-
utils_1.preLazy()
|
|
129
|
+
(0, utils_1.preLazy)()
|
|
129
130
|
], UserService.prototype, "createEndUser", null);
|
|
130
131
|
__decorate([
|
|
131
|
-
utils_1.preLazy()
|
|
132
|
+
(0, utils_1.preLazy)()
|
|
132
133
|
], UserService.prototype, "modifyEndUser", null);
|
|
133
134
|
__decorate([
|
|
134
|
-
utils_1.preLazy()
|
|
135
|
+
(0, utils_1.preLazy)()
|
|
135
136
|
], UserService.prototype, "updateEndUser", null);
|
|
136
|
-
exports.UserService = UserService;
|
package/lib/utils/auth.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getAuth =
|
|
6
|
+
exports.getAuth = getAuth;
|
|
7
7
|
const crypto_1 = __importDefault(require("crypto"));
|
|
8
8
|
function camSafeUrlEncode(str) {
|
|
9
9
|
return encodeURIComponent(str)
|
|
@@ -94,4 +94,3 @@ function getAuth(options) {
|
|
|
94
94
|
].join('&');
|
|
95
95
|
return authorization;
|
|
96
96
|
}
|
|
97
|
-
exports.getAuth = getAuth;
|
|
@@ -94,11 +94,11 @@ class CloudService {
|
|
|
94
94
|
// request执行时一般处于main函数内部,取环境变量逻辑写这里更可靠
|
|
95
95
|
if (!secretId || !secretKey) {
|
|
96
96
|
// 未主动传入密钥,从环境变量中读取
|
|
97
|
-
const envSecretId = utils_1.getEnvVar(constant_1.ENV_NAME.ENV_SECRETID);
|
|
98
|
-
const envSecretKey = utils_1.getEnvVar(constant_1.ENV_NAME.ENV_SECRETKEY);
|
|
99
|
-
const envToken = utils_1.getEnvVar(constant_1.ENV_NAME.ENV_SESSIONTOKEN);
|
|
97
|
+
const envSecretId = (0, utils_1.getEnvVar)(constant_1.ENV_NAME.ENV_SECRETID);
|
|
98
|
+
const envSecretKey = (0, utils_1.getEnvVar)(constant_1.ENV_NAME.ENV_SECRETKEY);
|
|
99
|
+
const envToken = (0, utils_1.getEnvVar)(constant_1.ENV_NAME.ENV_SESSIONTOKEN);
|
|
100
100
|
if (!envSecretId || !envSecretKey) {
|
|
101
|
-
if (utils_1.getRuntime() === constant_1.RUN_ENV.SCF) {
|
|
101
|
+
if ((0, utils_1.getRuntime)() === constant_1.RUN_ENV.SCF) {
|
|
102
102
|
throw new Error('missing authoration key, redeploy the function');
|
|
103
103
|
}
|
|
104
104
|
else {
|
|
@@ -181,7 +181,7 @@ class CloudService {
|
|
|
181
181
|
}
|
|
182
182
|
const sign = this.getRequestSign(timestamp);
|
|
183
183
|
config.headers['Authorization'] = sign;
|
|
184
|
-
return http_request_1.fetch(this.url, config, proxy);
|
|
184
|
+
return (0, http_request_1.fetch)(this.url, config, proxy);
|
|
185
185
|
}
|
|
186
186
|
getRequestSign(timestamp) {
|
|
187
187
|
const { method = 'POST', url, service, secretId, secretKey } = this;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.cloudBaseRequest =
|
|
3
|
+
exports.cloudBaseRequest = cloudBaseRequest;
|
|
4
4
|
const auth_1 = require("./auth");
|
|
5
5
|
const http_request_1 = require("./http-request");
|
|
6
6
|
const SUPPORT_REGIONS = ['ap-shanghai', 'ap-guangzhou'];
|
|
@@ -57,13 +57,12 @@ async function cloudBaseRequest(options) {
|
|
|
57
57
|
params: requestData,
|
|
58
58
|
headers: requestHeaders
|
|
59
59
|
};
|
|
60
|
-
const authorization = auth_1.getAuth(authData);
|
|
60
|
+
const authorization = (0, auth_1.getAuth)(authData);
|
|
61
61
|
const requestBody = Object.assign(Object.assign({}, requestData), { sessionToken: token, authorization });
|
|
62
|
-
const res = await http_request_1.fetch(url, {
|
|
62
|
+
const res = await (0, http_request_1.fetch)(url, {
|
|
63
63
|
method,
|
|
64
64
|
body: JSON.stringify(requestBody),
|
|
65
65
|
headers: requestHeaders
|
|
66
66
|
}, process.env.TCB_ADMIN_PROXY || proxy);
|
|
67
67
|
return res;
|
|
68
68
|
}
|
|
69
|
-
exports.cloudBaseRequest = cloudBaseRequest;
|
package/lib/utils/envLazy.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.preLazy =
|
|
3
|
+
exports.preLazy = preLazy;
|
|
4
4
|
function preLazy() {
|
|
5
5
|
return function (target, propertyKey, descriptor) {
|
|
6
6
|
let oldFunc = descriptor.value;
|
|
@@ -15,4 +15,3 @@ function preLazy() {
|
|
|
15
15
|
};
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
|
-
exports.preLazy = preLazy;
|
package/lib/utils/fs.js
CHANGED
|
@@ -3,7 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.checkFullAccess = checkFullAccess;
|
|
7
|
+
exports.checkReadable = checkReadable;
|
|
8
|
+
exports.isDirectory = isDirectory;
|
|
9
|
+
exports.formateFileSize = formateFileSize;
|
|
10
|
+
exports.delSync = delSync;
|
|
7
11
|
const fs_1 = __importDefault(require("fs"));
|
|
8
12
|
const error_1 = require("../error");
|
|
9
13
|
const del_1 = __importDefault(require("del"));
|
|
@@ -25,7 +29,6 @@ function checkFullAccess(dest, throwError = false) {
|
|
|
25
29
|
}
|
|
26
30
|
}
|
|
27
31
|
}
|
|
28
|
-
exports.checkFullAccess = checkFullAccess;
|
|
29
32
|
// 检查路径是否可以写
|
|
30
33
|
function checkReadable(dest, throwError = false) {
|
|
31
34
|
try {
|
|
@@ -43,12 +46,10 @@ function checkReadable(dest, throwError = false) {
|
|
|
43
46
|
}
|
|
44
47
|
}
|
|
45
48
|
}
|
|
46
|
-
exports.checkReadable = checkReadable;
|
|
47
49
|
function isDirectory(dest) {
|
|
48
50
|
checkFullAccess(dest, true);
|
|
49
51
|
return fs_1.default.statSync(dest).isDirectory();
|
|
50
52
|
}
|
|
51
|
-
exports.isDirectory = isDirectory;
|
|
52
53
|
function formateFileSize(size, unit) {
|
|
53
54
|
const unitMap = {
|
|
54
55
|
KB: 1024,
|
|
@@ -57,8 +58,6 @@ function formateFileSize(size, unit) {
|
|
|
57
58
|
};
|
|
58
59
|
return Number(size / unitMap[unit]).toFixed(2);
|
|
59
60
|
}
|
|
60
|
-
exports.formateFileSize = formateFileSize;
|
|
61
61
|
function delSync(patterns) {
|
|
62
62
|
del_1.default.sync(patterns, { force: true });
|
|
63
63
|
}
|
|
64
|
-
exports.delSync = delSync;
|
|
@@ -3,13 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.fetch = fetch;
|
|
7
|
+
exports.fetchStream = fetchStream;
|
|
7
8
|
const url_1 = require("url");
|
|
8
9
|
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
9
10
|
const https_proxy_agent_1 = require("https-proxy-agent");
|
|
10
11
|
const error_1 = require("../error");
|
|
11
12
|
// 使用 fetch + 代理
|
|
12
|
-
async function fetch(url, config = {}, proxy) {
|
|
13
|
+
async function fetch(url, config = {}, proxy = null) {
|
|
13
14
|
if (proxy || process.env.http_proxy) {
|
|
14
15
|
config.agent = new https_proxy_agent_1.HttpsProxyAgent(proxy || process.env.http_proxy);
|
|
15
16
|
}
|
|
@@ -18,7 +19,7 @@ async function fetch(url, config = {}, proxy) {
|
|
|
18
19
|
let json;
|
|
19
20
|
let text;
|
|
20
21
|
try {
|
|
21
|
-
const res = await node_fetch_1.default(escapeUrl, config);
|
|
22
|
+
const res = await (0, node_fetch_1.default)(escapeUrl, config);
|
|
22
23
|
text = await res.text();
|
|
23
24
|
json = JSON.parse(text);
|
|
24
25
|
}
|
|
@@ -32,13 +33,11 @@ async function fetch(url, config = {}, proxy) {
|
|
|
32
33
|
}
|
|
33
34
|
return json;
|
|
34
35
|
}
|
|
35
|
-
|
|
36
|
-
async function fetchStream(url, config = {}, proxy) {
|
|
36
|
+
async function fetchStream(url, config = {}, proxy = null) {
|
|
37
37
|
if (proxy || process.env.http_proxy) {
|
|
38
38
|
config.agent = new https_proxy_agent_1.HttpsProxyAgent(proxy || process.env.http_proxy);
|
|
39
39
|
}
|
|
40
40
|
// 解决中文编码问题
|
|
41
41
|
const escapeUrl = new url_1.URL(url).toString();
|
|
42
|
-
return node_fetch_1.default(escapeUrl, config);
|
|
42
|
+
return (0, node_fetch_1.default)(escapeUrl, config);
|
|
43
43
|
}
|
|
44
|
-
exports.fetchStream = fetchStream;
|