@cloudbase/manager-node 4.2.0 → 4.2.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.
Files changed (54) hide show
  1. package/CHANGELOG.md +0 -4
  2. package/lib/constant.js +1 -5
  3. package/lib/env/index.js +209 -10
  4. package/lib/function/index.js +5 -3
  5. package/lib/storage/index.js +3 -19
  6. package/lib/utils/cloud-api-request.js +0 -7
  7. package/lib/utils/http-request.js +3 -3
  8. package/package.json +3 -4
  9. package/src/access/index.ts +168 -0
  10. package/src/access/types.ts +55 -0
  11. package/src/billing/index.ts +43 -0
  12. package/src/cam/index.ts +106 -0
  13. package/src/cloudBaseRun/index.ts +40 -0
  14. package/src/cloudBaseRun/types.ts +24 -0
  15. package/src/common/index.ts +54 -0
  16. package/src/constant.ts +56 -0
  17. package/src/context.ts +18 -0
  18. package/src/database/index.ts +369 -0
  19. package/src/debug.ts +34 -0
  20. package/src/env/index.ts +614 -0
  21. package/src/environment.ts +156 -0
  22. package/src/environmentManager.ts +50 -0
  23. package/src/error.ts +27 -0
  24. package/src/function/index.ts +1362 -0
  25. package/src/function/packer.ts +164 -0
  26. package/src/function/types.ts +164 -0
  27. package/src/hosting/index.ts +698 -0
  28. package/src/index.ts +127 -0
  29. package/src/interfaces/base.interface.ts +8 -0
  30. package/src/interfaces/billing.interface.ts +21 -0
  31. package/src/interfaces/cam.interface.ts +28 -0
  32. package/src/interfaces/flexdb.interface.ts +104 -0
  33. package/src/interfaces/function.interface.ts +75 -0
  34. package/src/interfaces/index.ts +7 -0
  35. package/src/interfaces/storage.interface.ts +29 -0
  36. package/src/interfaces/tcb.interface.ts +636 -0
  37. package/src/storage/index.ts +1281 -0
  38. package/src/third/index.ts +24 -0
  39. package/src/user/index.ts +174 -0
  40. package/src/user/types.ts +21 -0
  41. package/src/utils/auth.ts +112 -0
  42. package/src/utils/cloud-api-request.ts +252 -0
  43. package/src/utils/cloudbase-request.ts +109 -0
  44. package/src/utils/envLazy.ts +15 -0
  45. package/src/utils/fs.ts +57 -0
  46. package/src/utils/http-request.ts +37 -0
  47. package/src/utils/index.ts +103 -0
  48. package/src/utils/parallel.ts +82 -0
  49. package/src/utils/uuid.ts +14 -0
  50. package/types/constant.d.ts +0 -7
  51. package/types/env/index.d.ts +17 -0
  52. package/types/function/index.d.ts +2 -1
  53. package/lib/utils/runenv.js +0 -8
  54. package/types/utils/runenv.d.ts +0 -1
@@ -0,0 +1,106 @@
1
+ import { CloudService } from '../utils'
2
+ import { CloudBaseContext } from '../context'
3
+ import {
4
+ IServiceVersion,
5
+ IRoleListRes,
6
+ ICreateRoleRes,
7
+ IResponseInfo,
8
+ IGetRoleRes
9
+ } from '../interfaces'
10
+
11
+ export class CamService {
12
+ static camServiceVersion: IServiceVersion = {
13
+ service: 'cam',
14
+ version: '2019-01-16'
15
+ }
16
+ private camService: CloudService
17
+
18
+ constructor(context: CloudBaseContext) {
19
+ this.camService = new CloudService(
20
+ context,
21
+ CamService.camServiceVersion.service,
22
+ CamService.camServiceVersion.version
23
+ )
24
+ }
25
+
26
+ /**
27
+ * 查询账户角色列表
28
+ * @param {number} page
29
+ * @param {number} rp
30
+ * @returns {Promise<IRoleListRes>}
31
+ * @memberof CamService
32
+ */
33
+ public async describeRoleList(page: number, rp: number): Promise<IRoleListRes> {
34
+ return this.camService.request<IRoleListRes>('DescribeRoleList', {
35
+ Page: page,
36
+ Rp: rp
37
+ })
38
+ }
39
+
40
+ /**
41
+ * 获取角色详情
42
+ * @param {string} roleName
43
+ * @returns {Promise<IGetRoleRes>}
44
+ * @memberof CamService
45
+ */
46
+ public async getRole(roleName: string): Promise<IGetRoleRes> {
47
+ return this.camService.request<IGetRoleRes>('GetRole', {
48
+ RoleName: roleName
49
+ })
50
+ }
51
+
52
+ /**
53
+ * 创建角色
54
+ * @param {{
55
+ * RoleName: string
56
+ * PolicyDocument: string
57
+ * Description: string
58
+ * }} param
59
+ * @returns {Promise<ICreateRoleRes>}
60
+ * @memberof CamService
61
+ */
62
+ public async createRole(param: {
63
+ RoleName: string
64
+ PolicyDocument: string
65
+ Description: string
66
+ }): Promise<ICreateRoleRes> {
67
+ return this.camService.request<ICreateRoleRes>('CreateRole', param)
68
+ }
69
+
70
+ /**
71
+ * 绑定角色策略
72
+ * @param {{
73
+ * PolicyId: number
74
+ * AttachRoleName: string
75
+ * }} param
76
+ * @returns {Promise<IResponseInfo>}
77
+ * @memberof CamService
78
+ */
79
+ public async attachRolePolicy(param: {
80
+ PolicyId: number
81
+ AttachRoleName: string
82
+ }): Promise<IResponseInfo> {
83
+ return this.camService.request<IResponseInfo>('AttachRolePolicy', param)
84
+ }
85
+
86
+ public async attachRolePolicies(param: {
87
+ RoleId?: number
88
+ RoleName?: string
89
+ PolicyId?: number[]
90
+ PolicyName?: string[]
91
+ }): Promise<IResponseInfo> {
92
+ return this.camService.request<IResponseInfo>('AttachRolePolicies', param)
93
+ }
94
+
95
+ /**
96
+ * 删除角色
97
+ * @param {string} roleName
98
+ * @returns {Promise<IResponseInfo>}
99
+ * @memberof CamService
100
+ */
101
+ public async deleteRole(roleName: string): Promise<IResponseInfo> {
102
+ return this.camService.request<IResponseInfo>('DeleteRole', {
103
+ RoleName: roleName
104
+ })
105
+ }
106
+ }
@@ -0,0 +1,40 @@
1
+ import { Environment } from '../environment'
2
+ import { CloudService, preLazy, upperCaseObjKey } from '../utils'
3
+ import { IModifyServerFlowOption } from './types'
4
+ import { IResponseInfo } from '../interfaces'
5
+
6
+ export class CloudBaseRunService {
7
+ private tcbService: CloudService
8
+ private environment: Environment
9
+
10
+ constructor(environment: Environment) {
11
+ this.environment = environment
12
+ this.tcbService = new CloudService(environment.cloudBaseContext, 'tcb', '2018-06-08')
13
+ }
14
+
15
+ // 修改容器内版本流量配置
16
+ @preLazy()
17
+ public async modifyServerFlow(
18
+ options: IModifyServerFlowOption
19
+ ): Promise<{
20
+ Result: string // succ代表成功
21
+ RequestId: string // 请求ID
22
+ }> {
23
+ const { envId } = this.getEnvInfo()
24
+
25
+ return this.tcbService.request('ModifyCloudBaseRunServerFlowConf', {
26
+ EnvId: envId,
27
+ ServerName: options.serverName,
28
+ VersionFlowItems: upperCaseObjKey(options.versionFlowItems)
29
+ // TrafficType: options.trafficType
30
+ })
31
+ }
32
+
33
+ private getEnvInfo() {
34
+ const envConfig = this.environment.lazyEnvironmentConfig
35
+
36
+ return {
37
+ envId: envConfig.EnvId
38
+ }
39
+ }
40
+ }
@@ -0,0 +1,24 @@
1
+ export interface IModifyServerFlowOption {
2
+ serverName: string
3
+ versionFlowItems?: ICloudBaseRunVersionFlowItem[]
4
+ trafficType?: string
5
+ }
6
+
7
+ export interface ICloudBaseRunVersionFlowItem {
8
+ versionName: string // 版本名称
9
+ flowRatio: number // 流量占比
10
+ urlParam?: IObjectKV // 流量参数
11
+ priority?: number // 优先级(数值越小,优先级越高)
12
+ isDefaultPriority?: boolean // 是否是默认兜底版本
13
+ }
14
+
15
+ export interface IObjectKV {
16
+ key: string
17
+ value: string
18
+ }
19
+
20
+ export interface IClouBaseRunKVPriority {
21
+ key: string
22
+ value: string
23
+ priority: number
24
+ }
@@ -0,0 +1,54 @@
1
+ import { CloudService, preLazy } from '../utils'
2
+ import { CloudBaseContext } from '../context'
3
+ import { CloudBaseError } from '../error'
4
+ import { Environment } from '../environment'
5
+
6
+ interface ICommonApiServiceOption {
7
+ Action: string // 接口名称
8
+ Param: Record<string, any> // 接口传参
9
+ }
10
+ /**
11
+ * 公共的云api调用方法 透传用户参数 无业务逻辑处理
12
+ * @export
13
+ * @class CommonService
14
+ */
15
+
16
+ const ActionVersionMap = {
17
+ tcb: '2018-06-08',
18
+ flexdb: '2018-11-27',
19
+ scf: '2018-04-16',
20
+ sts: '2018-04-16',
21
+ cam: '2018-04-16',
22
+ lowcode: '2021-01-08'
23
+ }
24
+
25
+ export class CommonService {
26
+ private commonService: CloudService
27
+ private environment: Environment
28
+
29
+ constructor(environment: Environment, serviceType: string, serviceVersion: string) {
30
+ this.environment = environment
31
+ this.commonService = new CloudService(
32
+ environment.cloudBaseContext,
33
+ serviceType,
34
+ serviceVersion || ActionVersionMap[serviceType]
35
+ )
36
+ }
37
+
38
+ /**
39
+ * 公共方法调用
40
+ * @param {ICommonApiServiceParam} param
41
+ * @returns {Promise<any>}
42
+ * @memberof CommonService
43
+ */
44
+ public async call(options: ICommonApiServiceOption): Promise<any> {
45
+ const { Action, Param = {} } = options
46
+ if (!Action) {
47
+ throw new CloudBaseError('缺少必填参数 Action')
48
+ }
49
+
50
+ const res = await this.commonService.request(Action, { ...Param })
51
+
52
+ return res
53
+ }
54
+ }
@@ -0,0 +1,56 @@
1
+ // // cloudbase cli 配置的字段名
2
+ // export class ConfigItems {
3
+ // static credentail = 'credential'
4
+ // }
5
+
6
+ export const ENV_NAME = {
7
+ ENV_SECRETID: 'TENCENTCLOUD_SECRETID',
8
+ ENV_SECRETKEY: 'TENCENTCLOUD_SECRETKEY',
9
+ ENV_SESSIONTOKEN: 'TENCENTCLOUD_SESSIONTOKEN',
10
+ ENV_TCB_ENV_ID: 'TENCENTCLOUD_TCB_ENVID',
11
+ ENV_RUNENV: 'TENCENTCLOUD_RUNENV',
12
+ ENV_RUNENV_SCF: 'TENCENTCLOUD_RUNENV=SCF'
13
+ }
14
+
15
+ export const SDK_VERSION = 'TCB-NODE-MANAGER/1.0.O'
16
+
17
+ export const RUN_ENV = {
18
+ SCF: 'SCF'
19
+ }
20
+
21
+ export const ENDPOINT = {
22
+ TCB: 'tcb.tencentcloudapi.com',
23
+ SCF: 'scf.tencentcloudapi.com',
24
+ COS: 'cos.tencentcloudapi.com',
25
+ FLEXDB: 'flexdb.tencentcloudapi.com'
26
+ }
27
+
28
+ export const SERVICE_TYPE = {
29
+ TCB: 'tcb'
30
+ }
31
+
32
+ export const ERROR = {
33
+ MISS_SECRET_INFO_IN_ENV: 'MISS_SECRET_INFO_IN_ENV',
34
+ MISS_SECRET_INFO_IN_ARGS: 'MISS_SECRET_INFO_IN_ARGS',
35
+ CURRENT_ENVIRONMENT_IS_NULL: 'CURRENT_ENVIRONMENT_IS_NULL',
36
+ ENV_ID_NOT_EXISTS: 'ENV_ID_NOT_EXISTS'
37
+ }
38
+
39
+ export const PUBLIC_RSA_KEY = `
40
+ -----BEGIN PUBLIC KEY-----
41
+ MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC0ZLB0ZpWWFsHPnDDw++Nc2wI3
42
+ nl2uyOrIJ5FUfxt4GAmt1Faf5pgMxAnL9exEUrrUDUX8Ri1R0KyfnHQQwCvKt8T8
43
+ bgILIJe9UB8e9dvFqgqH2oA8Vqwi0YqDcvFLFJk2BJbm/0QYtZ563FumW8LEXAgu
44
+ UeHi/0OZN9vQ33jWMQIDAQAB
45
+ -----END PUBLIC KEY-----
46
+ `
47
+ export const ROLE_NAME = {
48
+ TCB: 'TCB_QcsRole'
49
+ }
50
+
51
+ export const SCF_STATUS = {
52
+ ACTIVE: 'Active',
53
+ CREATING: 'Creating',
54
+ UPDATING: 'Updating',
55
+ CREATE_FAILED: 'CreateFailed'
56
+ }
package/src/context.ts ADDED
@@ -0,0 +1,18 @@
1
+ export class CloudBaseContext {
2
+ public readonly secretId: string
3
+ public readonly secretKey: string
4
+ public readonly token: string
5
+ public readonly proxy: string
6
+ public readonly envId: string
7
+ public readonly region: string
8
+ public readonly envType: string // baas/run/weda/hosting
9
+
10
+ constructor({ secretId = '', secretKey = '', token = '', proxy = '', region = '', envType = '' }) {
11
+ this.secretId = secretId
12
+ this.secretKey = secretKey
13
+ this.token = token
14
+ this.proxy = proxy
15
+ this.region = region
16
+ this.envType = envType
17
+ }
18
+ }
@@ -0,0 +1,369 @@
1
+ import path from 'path'
2
+ import {
3
+ IServiceVersion,
4
+ IExistsRes,
5
+ CreateIndex,
6
+ DropIndex,
7
+ IndexInfo,
8
+ TableInfo,
9
+ Pager,
10
+ IResponseInfo,
11
+ CollectionDispension
12
+ } from '../interfaces/'
13
+ import { CloudBaseError } from '../error'
14
+ import { Environment } from '../environment'
15
+ import { CloudService } from '../utils'
16
+
17
+ interface IDatabaseConfig {
18
+ Tag: string
19
+ }
20
+
21
+ interface IIndexiesInfo {
22
+ CreateIndexes?: Array<CreateIndex>
23
+ DropIndexes?: Array<DropIndex>
24
+ }
25
+
26
+ interface ITableInfo extends IResponseInfo {
27
+ Indexes?: Array<IndexInfo>
28
+ IndexNum?: number
29
+ }
30
+
31
+ interface IMgoQueryInfo {
32
+ MgoLimit?: number
33
+ MgoOffset?: number
34
+ }
35
+
36
+ interface ICollectionInfo extends IResponseInfo {
37
+ Collections: Array<TableInfo>
38
+ Pager: Pager
39
+ }
40
+
41
+ interface ICollectionExistInfo extends IResponseInfo {
42
+ IsCreated: boolean
43
+ ExistsResult: IExistsRes
44
+ }
45
+
46
+ interface IDistributionInfo extends IResponseInfo {
47
+ Collections: CollectionDispension
48
+ Count: number
49
+ Total: number
50
+ }
51
+
52
+ interface IDatabaseMigrateQueryInfo extends IResponseInfo {
53
+ Status: string
54
+ RecordSuccess: number
55
+ RecordFail: number
56
+ ErrorMsg: string
57
+ FileUrl: string
58
+ }
59
+
60
+ interface IDatabaseImportAndExportInfo extends IResponseInfo {
61
+ JobId: number
62
+ }
63
+
64
+ function preLazy() {
65
+ return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
66
+ let oldFunc = descriptor.value
67
+ descriptor.value = async function () {
68
+ // 检查当前环境对象上是否已加载好环境信息
69
+ const currentEnvironment = this.environment
70
+
71
+ if (!currentEnvironment.inited) {
72
+ await currentEnvironment.lazyInit()
73
+ }
74
+ let result = await oldFunc.apply(this, arguments)
75
+ return result
76
+ }
77
+ }
78
+ }
79
+
80
+ export class DatabaseService {
81
+ static tcbServiceVersion: IServiceVersion = {
82
+ service: 'tcb',
83
+ version: '2018-06-08'
84
+ }
85
+
86
+ static flexdbServiceVersion: IServiceVersion = {
87
+ service: 'flexdb',
88
+ version: '2018-11-27'
89
+ }
90
+
91
+ private environment: Environment
92
+ private envId: string
93
+ private dbOpService: CloudService
94
+ private collOpService: CloudService
95
+ private DEFAULT_MGO_OFFSET = 0
96
+ private DEFAULT_MGO_LIMIT = 100
97
+
98
+ constructor(environment: Environment) {
99
+ this.environment = environment
100
+ this.envId = environment.getEnvId()
101
+
102
+ this.dbOpService = new CloudService(
103
+ environment.cloudBaseContext,
104
+ DatabaseService.tcbServiceVersion.service,
105
+ DatabaseService.tcbServiceVersion.version
106
+ )
107
+
108
+ this.collOpService = new CloudService(
109
+ environment.cloudBaseContext,
110
+ DatabaseService.flexdbServiceVersion.service,
111
+ DatabaseService.flexdbServiceVersion.version
112
+ )
113
+ }
114
+
115
+ public getCurrEnvironment(): Environment {
116
+ return this.environment
117
+ }
118
+
119
+ public getDatabaseConfig(): IDatabaseConfig {
120
+ const currEnv = this.environment
121
+ const { Databases } = currEnv.lazyEnvironmentConfig
122
+ return {
123
+ Tag: Databases[0].InstanceId
124
+ }
125
+ }
126
+
127
+ public async checkCollectionExists(collectionName: string): Promise<IExistsRes> {
128
+ try {
129
+ const result = await this.describeCollection(collectionName)
130
+
131
+ return {
132
+ RequestId: result.RequestId,
133
+ Exists: true
134
+ }
135
+ } catch (e) {
136
+ return {
137
+ RequestId: e.requestId,
138
+ Msg: e.message,
139
+ Exists: false
140
+ }
141
+ }
142
+ }
143
+
144
+ @preLazy()
145
+ public async createCollection(collectionName: string): Promise<any> {
146
+ let { Tag } = this.getDatabaseConfig()
147
+
148
+ const res = await this.collOpService.request('CreateTable', {
149
+ Tag,
150
+ TableName: collectionName
151
+ })
152
+ return res
153
+ }
154
+
155
+ @preLazy()
156
+ public async deleteCollection(collectionName: string): Promise<any> {
157
+ // 先检查当前集合是否存在
158
+ const existRes = await this.checkCollectionExists(collectionName)
159
+ if (existRes.Exists) {
160
+ let { Tag } = this.getDatabaseConfig()
161
+
162
+ const res = await this.collOpService.request('DeleteTable', {
163
+ Tag,
164
+ TableName: collectionName
165
+ })
166
+ return res
167
+ } else {
168
+ return existRes
169
+ }
170
+ }
171
+
172
+ @preLazy()
173
+ public async updateCollection(
174
+ collectionName: string,
175
+ indexiesInfo: IIndexiesInfo
176
+ ): Promise<any> {
177
+ let { Tag } = this.getDatabaseConfig()
178
+
179
+ const res = await this.collOpService.request('UpdateTable', {
180
+ Tag,
181
+ TableName: collectionName,
182
+ ...indexiesInfo
183
+ })
184
+ return res
185
+ }
186
+
187
+ @preLazy()
188
+ public async describeCollection(collectionName: string): Promise<ITableInfo> {
189
+ let { Tag } = this.getDatabaseConfig()
190
+
191
+ return this.collOpService.request<ITableInfo>('DescribeTable', {
192
+ Tag,
193
+ TableName: collectionName
194
+ })
195
+ }
196
+
197
+ // 获取
198
+ @preLazy()
199
+ public async listCollections(
200
+ options: IMgoQueryInfo = {
201
+ MgoLimit: this.DEFAULT_MGO_LIMIT,
202
+ MgoOffset: this.DEFAULT_MGO_OFFSET
203
+ }
204
+ ): Promise<ICollectionInfo> {
205
+ let { Tag } = this.getDatabaseConfig()
206
+
207
+ if (options.MgoLimit === undefined) {
208
+ options.MgoLimit = this.DEFAULT_MGO_LIMIT
209
+ }
210
+
211
+ if (options.MgoOffset === undefined) {
212
+ options.MgoOffset = this.DEFAULT_MGO_OFFSET
213
+ }
214
+
215
+ const res = await this.collOpService.request<{
216
+ RequestId: string
217
+ Pager: Pager
218
+ Tables?: TableInfo[]
219
+ Collections: TableInfo[]
220
+ }>('ListTables', {
221
+ Tag,
222
+ ...options
223
+ })
224
+
225
+ if (res.Tables === null) {
226
+ // 无集合
227
+ res.Collections = []
228
+ } else {
229
+ // 云 API 返回转换为与TCB一致
230
+ res.Collections = res.Tables.map(item => {
231
+ item.CollectionName = item.TableName
232
+ delete item.TableName
233
+ return item
234
+ })
235
+ }
236
+
237
+ delete res.Tables
238
+ return res
239
+ }
240
+
241
+ public async createCollectionIfNotExists(
242
+ collectionName: string
243
+ ): Promise<ICollectionExistInfo> {
244
+ const existRes = await this.checkCollectionExists(collectionName)
245
+ let res
246
+ if (!existRes.Exists) {
247
+ res = await this.createCollection(collectionName)
248
+ return {
249
+ RequestId: res.RequestId,
250
+ IsCreated: true,
251
+ ExistsResult: existRes
252
+ }
253
+ } else {
254
+ return {
255
+ RequestId: '',
256
+ IsCreated: false,
257
+ ExistsResult: existRes
258
+ }
259
+ }
260
+ }
261
+
262
+ // 检查集合中是否存在某索引
263
+ public async checkIndexExists(collectionName: string, indexName: string): Promise<IExistsRes> {
264
+ const result = await this.describeCollection(collectionName)
265
+ let exists = result.Indexes.some(item => {
266
+ return item.Name === indexName
267
+ })
268
+
269
+ return {
270
+ RequestId: result.RequestId,
271
+ Exists: exists
272
+ }
273
+ }
274
+
275
+ // 查询DB的数据存储分布
276
+ public async distribution(): Promise<IDistributionInfo> {
277
+ const res: any = await this.dbOpService.request('DescribeDbDistribution', {
278
+ EnvId: this.envId
279
+ })
280
+
281
+ return res
282
+ }
283
+
284
+ // 查询DB 迁移进度
285
+ public async migrateStatus(jobId: number): Promise<IDatabaseMigrateQueryInfo> {
286
+ const res: IDatabaseMigrateQueryInfo = await this.dbOpService.request(
287
+ 'DatabaseMigrateQueryInfo',
288
+ {
289
+ EnvId: this.envId,
290
+ JobId: jobId
291
+ }
292
+ )
293
+
294
+ return res
295
+ }
296
+
297
+ // 数据库导入数据
298
+ public async import(
299
+ collectionName: string,
300
+ file: any,
301
+ options: any
302
+ ): Promise<IDatabaseImportAndExportInfo> {
303
+ let filePath
304
+ let fileType
305
+ if (file['FilePath']) {
306
+ let temp = 'tmp/db-imports/'
307
+ if (options['ObjectKeyPrefix']) {
308
+ temp = options['ObjectKeyPrefix']
309
+ delete options['ObjectKeyPrefix']
310
+ }
311
+ filePath = path.join(temp, path.basename(file['FilePath']))
312
+
313
+ // 调用cos接口 上传文件 todo
314
+ await this.environment.getStorageService().uploadFile({
315
+ localPath: file['FilePath'],
316
+ cloudPath: filePath
317
+ })
318
+
319
+ fileType = path.extname(filePath).substring(1)
320
+ } else if (file['ObjectKey']) {
321
+ delete options['ObjectKeyPrefix']
322
+ filePath = file['ObjectKey']
323
+ fileType = path.extname(filePath).substring(1)
324
+ } else {
325
+ throw new CloudBaseError('Miss file.filePath or file.objectKey')
326
+ }
327
+
328
+ if (file['FileType']) {
329
+ fileType = file['FileType']
330
+ }
331
+
332
+ return this.dbOpService.request('DatabaseMigrateImport', {
333
+ CollectionName: collectionName,
334
+ FilePath: filePath,
335
+ FileType: fileType,
336
+ EnvId: this.envId,
337
+ ...options
338
+ })
339
+ }
340
+
341
+ // 数据库导出数据
342
+ public async export(
343
+ collectionName: string,
344
+ file: any,
345
+ options: any
346
+ ): Promise<IDatabaseImportAndExportInfo> {
347
+ let filePath
348
+ let fileType
349
+
350
+ if (file['ObjectKey']) {
351
+ filePath = file['ObjectKey']
352
+ fileType = path.extname(filePath).substring(1)
353
+ } else {
354
+ throw new CloudBaseError('Miss file.filePath or file.objectKey')
355
+ }
356
+
357
+ if (file['FileType']) {
358
+ fileType = file['FileType']
359
+ }
360
+
361
+ return this.dbOpService.request('DatabaseMigrateExport', {
362
+ CollectionName: collectionName,
363
+ FilePath: filePath,
364
+ FileType: fileType,
365
+ EnvId: this.envId,
366
+ ...options
367
+ })
368
+ }
369
+ }
package/src/debug.ts ADDED
@@ -0,0 +1,34 @@
1
+ import CloudBase from './index'
2
+ // import { cloudBaseConfig } from '../test/config'
3
+
4
+ // const app = new CloudBase(cloudBaseConfig)
5
+ const app = new CloudBase({})
6
+
7
+ async function test() {
8
+ // const hosting = await app.hosting.getInfo()
9
+ // const { Bucket, Regoin } = hosting[0]
10
+ // const res = await app.storage.uploadFilesCustom({
11
+ // files: [
12
+ // {
13
+ // localPath: 'test/storage/test_data/data.txt',
14
+ // cloudPath: 'test/storage/test_data/data.txt'
15
+ // },
16
+ // {
17
+ // localPath: 'test/storage/test_data/download.txt',
18
+ // cloudPath: 'test/storage/test_data/download.txt'
19
+ // }
20
+ // ],
21
+ // region: Regoin,
22
+ // bucket: Bucket
23
+ // })
24
+
25
+ const res = await app.hosting.uploadFiles({
26
+ localPath: '/Users/wuyiqing/Desktop/cloudbase-demo/functions/node-sdk',
27
+ cloudPath: '',
28
+ onProgress: console.log
29
+ })
30
+
31
+ console.log(res)
32
+ }
33
+
34
+ test().catch(console.log)