@cloudbase/manager-node 4.2.3 → 4.2.4
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/CHANGELOG.md +4 -0
- package/package.json +4 -3
- package/lib/access/index.js +0 -141
- package/lib/access/types.js +0 -2
- package/lib/billing/index.js +0 -36
- package/lib/cam/index.js +0 -77
- package/lib/cloudBaseRun/index.js +0 -36
- package/lib/cloudBaseRun/types.js +0 -2
- package/lib/common/index.js +0 -39
- package/lib/constant.js +0 -51
- package/lib/context.js +0 -14
- package/lib/database/index.js +0 -244
- package/lib/debug.js +0 -34
- package/lib/env/index.js +0 -488
- package/lib/environment.js +0 -124
- package/lib/environmentManager.js +0 -44
- package/lib/error.js +0 -16
- package/lib/function/index.js +0 -1022
- package/lib/function/packer.js +0 -129
- package/lib/function/types.js +0 -2
- package/lib/hosting/index.js +0 -461
- package/lib/index.js +0 -83
- package/lib/interfaces/base.interface.js +0 -2
- package/lib/interfaces/billing.interface.js +0 -2
- package/lib/interfaces/cam.interface.js +0 -2
- package/lib/interfaces/flexdb.interface.js +0 -2
- package/lib/interfaces/function.interface.js +0 -2
- package/lib/interfaces/index.js +0 -19
- package/lib/interfaces/storage.interface.js +0 -2
- package/lib/interfaces/tcb.interface.js +0 -2
- package/lib/storage/index.js +0 -1037
- package/lib/third/index.js +0 -18
- package/lib/user/index.js +0 -136
- package/lib/user/types.js +0 -2
- package/lib/utils/auth.js +0 -97
- package/lib/utils/cloud-api-request.js +0 -205
- package/lib/utils/cloudbase-request.js +0 -69
- package/lib/utils/envLazy.js +0 -18
- package/lib/utils/fs.js +0 -64
- package/lib/utils/http-request.js +0 -44
- package/lib/utils/index.js +0 -103
- package/lib/utils/parallel.js +0 -69
- package/lib/utils/uuid.js +0 -18
- package/src/access/index.ts +0 -168
- package/src/access/types.ts +0 -55
- package/src/billing/index.ts +0 -43
- package/src/cam/index.ts +0 -106
- package/src/cloudBaseRun/index.ts +0 -40
- package/src/cloudBaseRun/types.ts +0 -24
- package/src/common/index.ts +0 -54
- package/src/constant.ts +0 -56
- package/src/context.ts +0 -18
- package/src/database/index.ts +0 -369
- package/src/debug.ts +0 -34
- package/src/env/index.ts +0 -614
- package/src/environment.ts +0 -156
- package/src/environmentManager.ts +0 -50
- package/src/error.ts +0 -27
- package/src/function/index.ts +0 -1378
- package/src/function/packer.ts +0 -164
- package/src/function/types.ts +0 -165
- package/src/hosting/index.ts +0 -698
- package/src/index.ts +0 -127
- package/src/interfaces/base.interface.ts +0 -8
- package/src/interfaces/billing.interface.ts +0 -21
- package/src/interfaces/cam.interface.ts +0 -28
- package/src/interfaces/flexdb.interface.ts +0 -104
- package/src/interfaces/function.interface.ts +0 -75
- package/src/interfaces/index.ts +0 -7
- package/src/interfaces/storage.interface.ts +0 -29
- package/src/interfaces/tcb.interface.ts +0 -642
- package/src/storage/index.ts +0 -1290
- package/src/third/index.ts +0 -24
- package/src/user/index.ts +0 -174
- package/src/user/types.ts +0 -21
- package/src/utils/auth.ts +0 -112
- package/src/utils/cloud-api-request.ts +0 -252
- package/src/utils/cloudbase-request.ts +0 -109
- package/src/utils/envLazy.ts +0 -15
- package/src/utils/fs.ts +0 -57
- package/src/utils/http-request.ts +0 -37
- package/src/utils/index.ts +0 -103
- package/src/utils/parallel.ts +0 -82
- package/src/utils/uuid.ts +0 -14
- package/types/access/index.d.ts +0 -38
- package/types/access/types.d.ts +0 -42
- package/types/billing/index.d.ts +0 -21
- package/types/cam/index.d.ts +0 -63
- package/types/cloudBaseRun/index.d.ts +0 -12
- package/types/cloudBaseRun/types.d.ts +0 -21
- package/types/common/index.d.ts +0 -18
- package/types/constant.d.ts +0 -37
- package/types/context.d.ts +0 -17
- package/types/database/index.d.ts +0 -66
- package/types/debug.d.ts +0 -1
- package/types/env/index.d.ts +0 -144
- package/types/environment.d.ts +0 -51
- package/types/environmentManager.d.ts +0 -13
- package/types/error.d.ts +0 -18
- package/types/function/index.d.ts +0 -379
- package/types/function/packer.d.ts +0 -37
- package/types/function/types.d.ts +0 -156
- package/types/hosting/index.d.ts +0 -253
- package/types/index.d.ts +0 -52
- package/types/interfaces/base.interface.d.ts +0 -7
- package/types/interfaces/billing.interface.d.ts +0 -18
- package/types/interfaces/cam.interface.d.ts +0 -24
- package/types/interfaces/flexdb.interface.d.ts +0 -67
- package/types/interfaces/function.interface.d.ts +0 -65
- package/types/interfaces/index.d.ts +0 -7
- package/types/interfaces/storage.interface.d.ts +0 -26
- package/types/interfaces/tcb.interface.d.ts +0 -305
- package/types/storage/index.d.ts +0 -324
- package/types/third/index.d.ts +0 -11
- package/types/user/index.d.ts +0 -52
- package/types/user/types.d.ts +0 -20
- package/types/utils/auth.d.ts +0 -8
- package/types/utils/cloud-api-request.d.ts +0 -21
- package/types/utils/cloudbase-request.d.ts +0 -14
- package/types/utils/envLazy.d.ts +0 -1
- package/types/utils/fs.d.ts +0 -7
- package/types/utils/http-request.d.ts +0 -2
- package/types/utils/index.d.ts +0 -20
- package/types/utils/parallel.d.ts +0 -17
- package/types/utils/uuid.d.ts +0 -2
package/src/constant.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
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
|
-
}
|
package/src/database/index.ts
DELETED
|
@@ -1,369 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
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)
|