@cloudbase/manager-node 4.10.2 → 4.10.3-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/function/index.js +311 -174
- package/lib/storage/index.js +37 -9
- package/package.json +1 -1
- package/types/function/types.d.ts +12 -0
- package/types/interfaces/function.interface.d.ts +15 -3
- package/types/storage/index.d.ts +27 -6
package/lib/function/index.js
CHANGED
|
@@ -26,117 +26,199 @@ function isNodeFunction(runtime) {
|
|
|
26
26
|
/**
|
|
27
27
|
* 构建镜像配置对象
|
|
28
28
|
* @param imageConfig 镜像配置
|
|
29
|
-
* @param options 可选配置
|
|
30
|
-
* @param options.includeCommandList 是否包含 CommandList/ArgsList(仅 CreateFunction 支持)
|
|
31
29
|
* @returns 构建好的镜像配置对象
|
|
32
30
|
*/
|
|
33
|
-
function buildImageConfig(imageConfig
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
31
|
+
function buildImageConfig(imageConfig) {
|
|
32
|
+
// 先转换大小写
|
|
33
|
+
const config = toPascalCaseKeys(imageConfig);
|
|
34
|
+
// 再补充默认值
|
|
35
|
+
return Object.assign({ ImageType: 'enterprise', ImagePort: 9000 }, config);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* 递归转换对象的 key 从 camelCase 到 PascalCase
|
|
39
|
+
*/
|
|
40
|
+
function toPascalCaseKeys(obj) {
|
|
41
|
+
if (obj === null || obj === undefined)
|
|
42
|
+
return obj;
|
|
43
|
+
if (Array.isArray(obj))
|
|
44
|
+
return obj.map(item => toPascalCaseKeys(item));
|
|
45
|
+
if (typeof obj !== 'object')
|
|
46
|
+
return obj;
|
|
47
|
+
const result = {};
|
|
48
|
+
for (const key of Object.keys(obj)) {
|
|
49
|
+
// 通用规则:首字母大写
|
|
50
|
+
const pascalKey = key.charAt(0).toUpperCase() + key.slice(1);
|
|
51
|
+
result[pascalKey] = toPascalCaseKeys(obj[key]);
|
|
52
|
+
}
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* 将布尔值转换为 API 需要的 'TRUE'/'FALSE' 字符串
|
|
57
|
+
* 支持 boolean | string | undefined 输入
|
|
58
|
+
* @param value 输入值
|
|
59
|
+
* @returns 'TRUE' | 'FALSE' | undefined
|
|
60
|
+
*/
|
|
61
|
+
function toBooleanString(value) {
|
|
62
|
+
if (value === undefined)
|
|
63
|
+
return undefined;
|
|
64
|
+
// 已经是字符串格式
|
|
65
|
+
if (value === 'TRUE' || value === 'FALSE')
|
|
66
|
+
return value;
|
|
67
|
+
// 字符串 'true'/'false' 兼容
|
|
68
|
+
if (typeof value === 'string') {
|
|
69
|
+
return value.toUpperCase() === 'TRUE' ? 'TRUE' : 'FALSE';
|
|
70
|
+
}
|
|
71
|
+
// 布尔值转换
|
|
72
|
+
return value ? 'TRUE' : 'FALSE';
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* 大小写不敏感获取对象字段值
|
|
76
|
+
* @param obj 目标对象
|
|
77
|
+
* @param fieldName 字段名(任意大小写)
|
|
78
|
+
* @returns 字段值,找不到返回 undefined
|
|
79
|
+
*/
|
|
80
|
+
function getFieldIgnoreCase(obj, fieldName) {
|
|
81
|
+
if (!obj || typeof obj !== 'object')
|
|
82
|
+
return undefined;
|
|
83
|
+
const lowerFieldName = fieldName.toLowerCase();
|
|
84
|
+
for (const key of Object.keys(obj)) {
|
|
85
|
+
if (key.toLowerCase() === lowerFieldName) {
|
|
86
|
+
return obj[key];
|
|
46
87
|
}
|
|
47
88
|
}
|
|
48
|
-
return
|
|
89
|
+
return undefined;
|
|
49
90
|
}
|
|
50
|
-
//
|
|
91
|
+
// 解析函数配置,换成请求参数(用于 CreateFunction)
|
|
51
92
|
function configToParams(options) {
|
|
52
|
-
var _a, _b, _c
|
|
53
|
-
const { func, codeSecret, baseParams } = options;
|
|
54
|
-
|
|
55
|
-
//
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
params
|
|
80
|
-
//
|
|
81
|
-
|
|
93
|
+
var _a, _b, _c;
|
|
94
|
+
const { func, codeSecret, baseParams = {} } = options;
|
|
95
|
+
// 白名单:只有这些字段会被透传到 API(大小写不敏感)
|
|
96
|
+
// 参考 SCF API 文档:https://cloud.tencent.com/document/product/583/18586
|
|
97
|
+
// key: 小写用于匹配,value: PascalCase 用于输出
|
|
98
|
+
const AUTO_CONVERT_FIELDS = {
|
|
99
|
+
// 基础配置
|
|
100
|
+
'description': 'Description',
|
|
101
|
+
'memorysize': 'MemorySize',
|
|
102
|
+
'timeout': 'Timeout',
|
|
103
|
+
'runtime': 'Runtime',
|
|
104
|
+
'type': 'Type', // Event/HTTP
|
|
105
|
+
'role': 'Role',
|
|
106
|
+
// 日志配置
|
|
107
|
+
'clslogsetid': 'ClsLogsetId',
|
|
108
|
+
'clstopicid': 'ClsTopicId',
|
|
109
|
+
// 高级配置
|
|
110
|
+
'deadletterconfig': 'DeadLetterConfig',
|
|
111
|
+
'publicnetconfig': 'PublicNetConfig',
|
|
112
|
+
'cfsconfig': 'CfsConfig',
|
|
113
|
+
'inittimeout': 'InitTimeout',
|
|
114
|
+
'tags': 'Tags',
|
|
115
|
+
// 注意:asyncRunEnable/traceEnable/autoDeployClsTopicIndex/autoCreateClsTopic/dnsCache
|
|
116
|
+
// 需要 'TRUE'/'FALSE' 字符串,在特殊处理阶段处理
|
|
117
|
+
'protocoltype': 'ProtocolType', // WS
|
|
118
|
+
'intranetconfig': 'IntranetConfig',
|
|
119
|
+
};
|
|
120
|
+
let params = Object.assign(Object.assign({}, baseParams), { FunctionName: func.name });
|
|
121
|
+
// 第一阶段:白名单字段自动转换(大小写不敏感,统一输出 PascalCase)
|
|
122
|
+
for (const key of Object.keys(func)) {
|
|
123
|
+
const lowerKey = key.toLowerCase();
|
|
124
|
+
const pascalKey = AUTO_CONVERT_FIELDS[lowerKey];
|
|
125
|
+
if (!pascalKey || func[key] === undefined)
|
|
126
|
+
continue;
|
|
127
|
+
params[pascalKey] = toPascalCaseKeys(func[key]);
|
|
128
|
+
}
|
|
129
|
+
// 第二阶段:特殊处理字段
|
|
130
|
+
// 1. 安装依赖标志(支持 boolean | string)
|
|
131
|
+
if (func.installDependency !== undefined) {
|
|
132
|
+
params.InstallDependency = toBooleanString(func.installDependency);
|
|
133
|
+
}
|
|
134
|
+
// 2. L5 配置 - 当不存在时不修改,否则根据 true/false 进行修改
|
|
135
|
+
if (func.l5 !== undefined) {
|
|
136
|
+
params.L5Enable = toBooleanString(func.l5);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
params.L5Enable = null;
|
|
140
|
+
}
|
|
141
|
+
// 3. 需要 'TRUE'/'FALSE' 字符串的布尔字段统一处理(大小写不敏感)
|
|
142
|
+
// key: 小写用于匹配,value: PascalCase 用于输出
|
|
143
|
+
const BOOLEAN_STRING_FIELDS = {
|
|
144
|
+
'asyncrunenable': 'AsyncRunEnable', // 异步属性
|
|
145
|
+
'traceenable': 'TraceEnable', // 事件追踪
|
|
146
|
+
'autodeployclstopicindex': 'AutoDeployClsTopicIndex', // 自动创建 CLS 索引
|
|
147
|
+
'autocreateclstopic': 'AutoCreateClsTopic', // 自动创建 CLS 主题
|
|
148
|
+
'dnscache': 'DnsCache', // Dns 缓存
|
|
149
|
+
};
|
|
150
|
+
for (const key of Object.keys(func)) {
|
|
151
|
+
const lowerKey = key.toLowerCase();
|
|
152
|
+
const pascalKey = BOOLEAN_STRING_FIELDS[lowerKey];
|
|
153
|
+
if (pascalKey && func[key] !== undefined) {
|
|
154
|
+
params[pascalKey] = toBooleanString(func[key]);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
// 5. 环境变量 - 为覆盖式修改,不保留已有字段
|
|
158
|
+
if (func.envVariables && Object.keys(func.envVariables).length > 0) {
|
|
159
|
+
params.Environment = {
|
|
160
|
+
Variables: Object.keys(func.envVariables).map(key => ({
|
|
161
|
+
Key: key,
|
|
162
|
+
Value: func.envVariables[key]
|
|
163
|
+
}))
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
// 4. 函数角色(如果白名单已处理则跳过)
|
|
167
|
+
if (!params.Role && func.role) {
|
|
168
|
+
params.Role = func.role;
|
|
169
|
+
}
|
|
170
|
+
// 5. VPC 配置
|
|
82
171
|
if (((_a = func === null || func === void 0 ? void 0 : func.vpc) === null || _a === void 0 ? void 0 : _a.subnetId) !== undefined && ((_b = func === null || func === void 0 ? void 0 : func.vpc) === null || _b === void 0 ? void 0 : _b.vpcId) !== undefined) {
|
|
83
|
-
// VPC 网络
|
|
84
172
|
params.VpcConfig = {
|
|
85
|
-
SubnetId:
|
|
86
|
-
VpcId:
|
|
173
|
+
SubnetId: func.vpc.subnetId,
|
|
174
|
+
VpcId: func.vpc.vpcId
|
|
87
175
|
};
|
|
88
176
|
}
|
|
89
|
-
//
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
params.InstallDependency = installDependency;
|
|
93
|
-
// 代码保护
|
|
94
|
-
if (codeSecret || func.codeSecret) {
|
|
95
|
-
params.CodeSecret = codeSecret || func.codeSecret;
|
|
96
|
-
}
|
|
97
|
-
// 函数层
|
|
98
|
-
if ((_e = func === null || func === void 0 ? void 0 : func.layers) === null || _e === void 0 ? void 0 : _e.length) {
|
|
99
|
-
const transformLayers = func.layers.map(item => ({
|
|
177
|
+
// 6. 函数层
|
|
178
|
+
if ((_c = func === null || func === void 0 ? void 0 : func.layers) === null || _c === void 0 ? void 0 : _c.length) {
|
|
179
|
+
params.Layers = func.layers.map(item => ({
|
|
100
180
|
LayerName: item.name,
|
|
101
181
|
LayerVersion: item.version
|
|
102
182
|
}));
|
|
103
|
-
params.Layers = transformLayers;
|
|
104
183
|
}
|
|
105
|
-
//
|
|
106
|
-
if (
|
|
107
|
-
params.
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
184
|
+
// 7. 代码保护
|
|
185
|
+
if (codeSecret || func.codeSecret) {
|
|
186
|
+
params.CodeSecret = codeSecret || func.codeSecret;
|
|
187
|
+
}
|
|
188
|
+
// 8. 协议参数(WebSocket,大小写不敏感)
|
|
189
|
+
const protocolParams = getFieldIgnoreCase(func, 'protocolParams');
|
|
190
|
+
if (protocolParams) {
|
|
191
|
+
const wsParams = getFieldIgnoreCase(protocolParams, 'wsParams');
|
|
192
|
+
if (wsParams) {
|
|
114
193
|
params.ProtocolParams = {
|
|
115
|
-
WSParams:
|
|
116
|
-
IdleTimeOut: typeof idleTimeOut === 'number' ? idleTimeOut : 15
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
// 多并发配置
|
|
121
|
-
// 参考文档:https://cloud.tencent.com/document/api/583/17244#InstanceConcurrencyConfig
|
|
122
|
-
if (func === null || func === void 0 ? void 0 : func.instanceConcurrencyConfig) {
|
|
123
|
-
params.InstanceConcurrencyConfig = {
|
|
124
|
-
DynamicEnabled: func.instanceConcurrencyConfig.dynamicEnabled || 'FALSE',
|
|
125
|
-
MaxConcurrency: func.instanceConcurrencyConfig.maxConcurrency || 10
|
|
194
|
+
WSParams: toPascalCaseKeys(wsParams)
|
|
126
195
|
};
|
|
127
196
|
}
|
|
128
197
|
}
|
|
129
|
-
//
|
|
130
|
-
|
|
131
|
-
|
|
198
|
+
// 9. HTTP 云函数特殊处理(type 字段大小写不敏感)
|
|
199
|
+
const funcType = getFieldIgnoreCase(func, 'type');
|
|
200
|
+
if ((funcType === null || funcType === void 0 ? void 0 : funcType.toUpperCase()) === 'HTTP') {
|
|
201
|
+
params.Type = 'HTTP';
|
|
202
|
+
// 多并发配置 - 仅 HTTP 函数支持(大小写不敏感)
|
|
203
|
+
const instanceConcurrencyConfig = getFieldIgnoreCase(func, 'instanceConcurrencyConfig');
|
|
204
|
+
if (instanceConcurrencyConfig) {
|
|
205
|
+
const config = toPascalCaseKeys(instanceConcurrencyConfig);
|
|
206
|
+
// DynamicEnabled 需要特殊处理为 'TRUE'/'FALSE'
|
|
207
|
+
if (config.DynamicEnabled !== undefined) {
|
|
208
|
+
config.DynamicEnabled = toBooleanString(config.DynamicEnabled);
|
|
209
|
+
}
|
|
210
|
+
params.InstanceConcurrencyConfig = config;
|
|
211
|
+
}
|
|
132
212
|
}
|
|
133
|
-
//
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
213
|
+
// 10. 镜像配置(用于镜像部署,大小写不敏感)
|
|
214
|
+
const imageConfig = getFieldIgnoreCase(func, 'imageConfig');
|
|
215
|
+
if (imageConfig) {
|
|
216
|
+
params.Code = params.Code || {};
|
|
217
|
+
params.Code.ImageConfig = buildImageConfig(imageConfig);
|
|
138
218
|
}
|
|
139
|
-
|
|
219
|
+
// 第三阶段:统一应用默认值
|
|
220
|
+
const runtime = params.Runtime || 'Nodejs18.15';
|
|
221
|
+
return Object.assign({ Handler: func.handler || 'index.main', Timeout: 10, Runtime: 'Nodejs18.15', MemorySize: 256, InstallDependency: isNodeFunction(runtime) ? 'TRUE' : 'FALSE' }, params);
|
|
140
222
|
}
|
|
141
223
|
class FunctionService {
|
|
142
224
|
constructor(environment) {
|
|
@@ -153,12 +235,11 @@ class FunctionService {
|
|
|
153
235
|
* @memberof FunctionService
|
|
154
236
|
*/
|
|
155
237
|
async updateFunctionIncrementalCode(funcParam) {
|
|
156
|
-
const {
|
|
238
|
+
const { namespace } = this.getFunctionConfig();
|
|
157
239
|
const { functionRootPath, func, deleteFiles, addFiles } = funcParam;
|
|
158
240
|
const { name, runtime } = func;
|
|
159
241
|
const params = {
|
|
160
242
|
FunctionName: name,
|
|
161
|
-
EnvId: env,
|
|
162
243
|
Namespace: namespace
|
|
163
244
|
};
|
|
164
245
|
let packer;
|
|
@@ -183,7 +264,7 @@ class FunctionService {
|
|
|
183
264
|
}
|
|
184
265
|
params.AddFiles = base64;
|
|
185
266
|
}
|
|
186
|
-
return this.
|
|
267
|
+
return this.scfService.request('UpdateFunctionIncrementalCode', params);
|
|
187
268
|
}
|
|
188
269
|
/**
|
|
189
270
|
* 创建云函数
|
|
@@ -191,25 +272,25 @@ class FunctionService {
|
|
|
191
272
|
* @returns {(Promise<IResponseInfo | ICreateFunctionRes>)}
|
|
192
273
|
*/
|
|
193
274
|
async createFunction(funcParam) {
|
|
194
|
-
var _a;
|
|
195
|
-
const {
|
|
275
|
+
var _a, _b, _c;
|
|
276
|
+
const { namespace } = this.getFunctionConfig();
|
|
196
277
|
const { func, functionRootPath, force = false, base64Code, codeSecret, functionPath, deployMode } = funcParam;
|
|
197
278
|
const funcName = func.name;
|
|
198
279
|
const params = configToParams({
|
|
199
280
|
func,
|
|
200
281
|
codeSecret,
|
|
201
282
|
baseParams: {
|
|
202
|
-
|
|
283
|
+
Namespace: namespace,
|
|
203
284
|
Role: 'TCB_QcsRole',
|
|
204
285
|
Stamp: 'MINI_QCBASE'
|
|
205
286
|
}
|
|
206
287
|
});
|
|
207
288
|
// 根据部署方式处理 Code 参数
|
|
208
289
|
// 优先使用显式指定的 deployMode,如果未指定但存在 imageConfig 则认为是镜像部署
|
|
209
|
-
const isImageDeploy = deployMode === 'image' || (!deployMode &&
|
|
290
|
+
const isImageDeploy = deployMode === 'image' || (!deployMode && ((_a = params.Code) === null || _a === void 0 ? void 0 : _a.ImageConfig));
|
|
210
291
|
if (isImageDeploy) {
|
|
211
292
|
// 镜像部署:Code 参数已在 configToParams 中通过 imageConfig 设置
|
|
212
|
-
if (!((
|
|
293
|
+
if (!((_c = (_b = params.Code) === null || _b === void 0 ? void 0 : _b.ImageConfig) === null || _c === void 0 ? void 0 : _c.ImageUri)) {
|
|
213
294
|
throw new error_1.CloudBaseError('镜像部署需要配置 imageConfig.imageUri');
|
|
214
295
|
}
|
|
215
296
|
// 镜像部署的特殊配置
|
|
@@ -233,7 +314,7 @@ class FunctionService {
|
|
|
233
314
|
params.ClsLogsetId = LogsetId;
|
|
234
315
|
try {
|
|
235
316
|
// 创建云函数
|
|
236
|
-
const res = await this.
|
|
317
|
+
const res = await this.scfService.request('CreateFunction', params);
|
|
237
318
|
// 等待函数状态正常
|
|
238
319
|
await this.waitFunctionActive(funcName, codeSecret);
|
|
239
320
|
// 创建函数触发器、失败自动重试
|
|
@@ -303,9 +384,9 @@ class FunctionService {
|
|
|
303
384
|
*/
|
|
304
385
|
async getFunctionList(limit = 20, offset = 0) {
|
|
305
386
|
// 获取Function 环境配置
|
|
306
|
-
const {
|
|
307
|
-
const res = await this.
|
|
308
|
-
|
|
387
|
+
const { namespace } = this.getFunctionConfig();
|
|
388
|
+
const res = await this.scfService.request('ListFunctions', {
|
|
389
|
+
Namespace: namespace,
|
|
309
390
|
Limit: limit,
|
|
310
391
|
Offset: offset
|
|
311
392
|
});
|
|
@@ -319,9 +400,9 @@ class FunctionService {
|
|
|
319
400
|
*/
|
|
320
401
|
async listFunctions(limit = 20, offset = 0) {
|
|
321
402
|
// 获取Function 环境配置
|
|
322
|
-
const {
|
|
323
|
-
const res = await this.
|
|
324
|
-
|
|
403
|
+
const { namespace } = this.getFunctionConfig();
|
|
404
|
+
const res = await this.scfService.request('ListFunctions', {
|
|
405
|
+
Namespace: namespace,
|
|
325
406
|
Limit: limit,
|
|
326
407
|
Offset: offset
|
|
327
408
|
});
|
|
@@ -352,8 +433,8 @@ class FunctionService {
|
|
|
352
433
|
const { envId } = options;
|
|
353
434
|
while (true) {
|
|
354
435
|
try {
|
|
355
|
-
const res = await this.
|
|
356
|
-
|
|
436
|
+
const res = await this.scfService.request('ListFunctions', {
|
|
437
|
+
Namespace: envId,
|
|
357
438
|
Limit: pageSize,
|
|
358
439
|
Offset: currentOffset
|
|
359
440
|
});
|
|
@@ -436,17 +517,16 @@ class FunctionService {
|
|
|
436
517
|
* @returns {Promise<Record<string, string>>}
|
|
437
518
|
*/
|
|
438
519
|
async getFunctionDetail(name, codeSecret) {
|
|
439
|
-
const {
|
|
520
|
+
const { namespace } = this.getFunctionConfig();
|
|
440
521
|
const params = {
|
|
441
522
|
FunctionName: name,
|
|
442
|
-
EnvId: env,
|
|
443
523
|
ShowCode: 'TRUE',
|
|
444
|
-
Namespace:
|
|
524
|
+
Namespace: namespace
|
|
445
525
|
};
|
|
446
526
|
if (codeSecret) {
|
|
447
527
|
params.CodeSecret = codeSecret;
|
|
448
528
|
}
|
|
449
|
-
const data = await this.
|
|
529
|
+
const data = await this.scfService.request('GetFunction', params);
|
|
450
530
|
// 解析 VPC 配置
|
|
451
531
|
const { VpcId = '', SubnetId = '' } = data.VpcConfig || {};
|
|
452
532
|
if (VpcId && SubnetId) {
|
|
@@ -623,67 +703,110 @@ class FunctionService {
|
|
|
623
703
|
* @returns {Promise<IResponseInfo>}
|
|
624
704
|
*/
|
|
625
705
|
async updateFunctionConfig(func) {
|
|
626
|
-
var _a, _b, _c
|
|
706
|
+
var _a, _b, _c;
|
|
627
707
|
const { namespace } = this.getFunctionConfig();
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
708
|
+
// UpdateFunctionConfiguration API 白名单(大小写不敏感)
|
|
709
|
+
// 参考:https://cloud.tencent.com/document/product/583/18580
|
|
710
|
+
// 注意:Runtime, Handler, Code, Type, ProtocolType 只能在 CreateFunction 时指定
|
|
711
|
+
// key: 小写用于匹配,value: PascalCase 用于输出
|
|
712
|
+
const UPDATE_CONFIG_FIELDS = {
|
|
713
|
+
'description': 'Description',
|
|
714
|
+
'memorysize': 'MemorySize',
|
|
715
|
+
'timeout': 'Timeout',
|
|
716
|
+
'role': 'Role',
|
|
717
|
+
// 日志配置
|
|
718
|
+
'clslogsetid': 'ClsLogsetId',
|
|
719
|
+
'clstopicid': 'ClsTopicId',
|
|
720
|
+
// 高级配置
|
|
721
|
+
'deadletterconfig': 'DeadLetterConfig',
|
|
722
|
+
'publicnetconfig': 'PublicNetConfig',
|
|
723
|
+
'cfsconfig': 'CfsConfig',
|
|
724
|
+
'inittimeout': 'InitTimeout',
|
|
725
|
+
// 注意:asyncRunEnable/traceEnable/autoDeployClsTopicIndex/autoCreateClsTopic
|
|
726
|
+
// 只能在 CreateFunction 时设置,UpdateFunctionConfiguration 不支持
|
|
727
|
+
// 注意:dnsCache 需要 'TRUE'/'FALSE' 字符串,在特殊处理阶段处理
|
|
728
|
+
'intranetconfig': 'IntranetConfig',
|
|
729
|
+
};
|
|
730
|
+
// 构建参数
|
|
634
731
|
const params = {
|
|
635
|
-
FunctionName: func.name,
|
|
636
732
|
Namespace: namespace,
|
|
637
|
-
|
|
733
|
+
FunctionName: func.name
|
|
638
734
|
};
|
|
639
|
-
|
|
640
|
-
|
|
735
|
+
// 白名单字段自动转换(大小写不敏感,统一输出 PascalCase)
|
|
736
|
+
for (const key of Object.keys(func)) {
|
|
737
|
+
const lowerKey = key.toLowerCase();
|
|
738
|
+
const pascalKey = UPDATE_CONFIG_FIELDS[lowerKey];
|
|
739
|
+
if (!pascalKey || func[key] === undefined)
|
|
740
|
+
continue;
|
|
741
|
+
params[pascalKey] = toPascalCaseKeys(func[key]);
|
|
742
|
+
}
|
|
743
|
+
// 特殊处理:安装依赖标志(支持 boolean | string)
|
|
744
|
+
if (func.installDependency !== undefined) {
|
|
745
|
+
params.InstallDependency = toBooleanString(func.installDependency);
|
|
746
|
+
}
|
|
747
|
+
// 特殊处理:L5 配置(支持 boolean | string)
|
|
748
|
+
if (func.l5 !== undefined) {
|
|
749
|
+
params.L5Enable = toBooleanString(func.l5);
|
|
750
|
+
}
|
|
751
|
+
// 特殊处理:DnsCache(支持 boolean | string,大小写不敏感)
|
|
752
|
+
// 注意:asyncRunEnable/traceEnable/autoDeployClsTopicIndex/autoCreateClsTopic
|
|
753
|
+
// 只能在 CreateFunction 时设置,UpdateFunctionConfiguration 不支持这些参数
|
|
754
|
+
const dnsCacheValue = getFieldIgnoreCase(func, 'dnsCache');
|
|
755
|
+
if (dnsCacheValue !== undefined) {
|
|
756
|
+
params.DnsCache = toBooleanString(dnsCacheValue);
|
|
757
|
+
}
|
|
758
|
+
// 特殊处理:Publish - 是否同时发布新版本(支持 boolean | string,大小写不敏感)
|
|
759
|
+
const publishValue = getFieldIgnoreCase(func, 'publish');
|
|
760
|
+
if (publishValue !== undefined) {
|
|
761
|
+
params.Publish = toBooleanString(publishValue);
|
|
641
762
|
}
|
|
642
|
-
//
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
763
|
+
// 特殊处理:环境变量
|
|
764
|
+
if (func.envVariables && Object.keys(func.envVariables).length > 0) {
|
|
765
|
+
params.Environment = {
|
|
766
|
+
Variables: Object.keys(func.envVariables).map(key => ({
|
|
767
|
+
Key: key,
|
|
768
|
+
Value: func.envVariables[key]
|
|
769
|
+
}))
|
|
770
|
+
};
|
|
771
|
+
}
|
|
772
|
+
// 特殊处理:VPC 配置
|
|
649
773
|
if (((_a = func === null || func === void 0 ? void 0 : func.vpc) === null || _a === void 0 ? void 0 : _a.subnetId) !== undefined && ((_b = func === null || func === void 0 ? void 0 : func.vpc) === null || _b === void 0 ? void 0 : _b.vpcId) !== undefined) {
|
|
650
|
-
// VPC 网络
|
|
651
774
|
params.VpcConfig = {
|
|
652
|
-
SubnetId:
|
|
653
|
-
VpcId:
|
|
775
|
+
SubnetId: func.vpc.subnetId,
|
|
776
|
+
VpcId: func.vpc.vpcId
|
|
654
777
|
};
|
|
655
778
|
}
|
|
656
|
-
//
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
isNodeFunction(func.runtime) && (params.InstallDependency = 'TRUE');
|
|
660
|
-
// 是否安装依赖,选项可以覆盖
|
|
661
|
-
if (typeof func.installDependency !== 'undefined') {
|
|
662
|
-
params.InstallDependency = func.installDependency ? 'TRUE' : 'FALSE';
|
|
663
|
-
}
|
|
664
|
-
// 函数层
|
|
665
|
-
if ((_e = func === null || func === void 0 ? void 0 : func.layers) === null || _e === void 0 ? void 0 : _e.length) {
|
|
666
|
-
const transformLayers = func.layers.map(item => ({
|
|
779
|
+
// 特殊处理:函数层
|
|
780
|
+
if ((_c = func === null || func === void 0 ? void 0 : func.layers) === null || _c === void 0 ? void 0 : _c.length) {
|
|
781
|
+
params.Layers = func.layers.map(item => ({
|
|
667
782
|
LayerName: item.name,
|
|
668
783
|
LayerVersion: item.version
|
|
669
784
|
}));
|
|
670
|
-
params.Layers = transformLayers;
|
|
671
785
|
}
|
|
672
|
-
//
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
}
|
|
786
|
+
// 特殊处理:HTTP 函数多并发配置(大小写不敏感)
|
|
787
|
+
const instanceConcurrencyConfig = getFieldIgnoreCase(func, 'instanceConcurrencyConfig');
|
|
788
|
+
if (instanceConcurrencyConfig) {
|
|
789
|
+
const config = toPascalCaseKeys(instanceConcurrencyConfig);
|
|
790
|
+
// DynamicEnabled 需要特殊处理为 'TRUE'/'FALSE'
|
|
791
|
+
if (config.DynamicEnabled !== undefined) {
|
|
792
|
+
config.DynamicEnabled = toBooleanString(config.DynamicEnabled);
|
|
793
|
+
}
|
|
794
|
+
params.InstanceConcurrencyConfig = config;
|
|
680
795
|
}
|
|
681
|
-
//
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
796
|
+
// 特殊处理:HTTP 函数协议参数(WebSocket,大小写不敏感)
|
|
797
|
+
const protocolParams = getFieldIgnoreCase(func, 'protocolParams');
|
|
798
|
+
if (protocolParams) {
|
|
799
|
+
const wsParams = getFieldIgnoreCase(protocolParams, 'wsParams');
|
|
800
|
+
if (wsParams) {
|
|
801
|
+
params.ProtocolParams = {
|
|
802
|
+
WSParams: toPascalCaseKeys(wsParams)
|
|
803
|
+
};
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
// 特殊处理:忽略系统日志上报(Boolean 类型,直接传递,大小写不敏感)
|
|
807
|
+
const ignoreSysLogValue = getFieldIgnoreCase(func, 'ignoreSysLog');
|
|
808
|
+
if (ignoreSysLogValue !== undefined) {
|
|
809
|
+
params.IgnoreSysLog = ignoreSysLogValue;
|
|
687
810
|
}
|
|
688
811
|
try {
|
|
689
812
|
// 如果函数配置中包含触发器,则更新触发器
|
|
@@ -712,26 +835,25 @@ class FunctionService {
|
|
|
712
835
|
* @memberof FunctionService
|
|
713
836
|
*/
|
|
714
837
|
async updateFunctionCode(funcParam) {
|
|
715
|
-
var _a;
|
|
716
838
|
const { func, functionRootPath, base64Code, codeSecret, functionPath, deployMode } = funcParam;
|
|
717
839
|
const funcName = func.name;
|
|
718
|
-
const {
|
|
840
|
+
const { namespace } = this.getFunctionConfig();
|
|
719
841
|
// 镜像部署:使用镜像配置更新函数代码
|
|
720
842
|
if (deployMode === 'image') {
|
|
721
|
-
if (!((_a = func.imageConfig) === null || _a === void 0 ? void 0 : _a.imageUri)) {
|
|
722
|
-
throw new error_1.CloudBaseError('镜像部署需要配置 imageConfig.imageUri');
|
|
723
|
-
}
|
|
724
843
|
const params = {
|
|
725
844
|
FunctionName: funcName,
|
|
726
|
-
|
|
845
|
+
Namespace: namespace,
|
|
727
846
|
Code: {
|
|
728
847
|
ImageConfig: buildImageConfig(func.imageConfig)
|
|
729
848
|
}
|
|
730
849
|
};
|
|
850
|
+
if (!params.Code.ImageConfig.ImageUri) {
|
|
851
|
+
throw new error_1.CloudBaseError('镜像部署需要配置 imageConfig.imageUri');
|
|
852
|
+
}
|
|
731
853
|
try {
|
|
732
854
|
// 等待函数状态正常
|
|
733
855
|
await this.waitFunctionActive(funcName, codeSecret);
|
|
734
|
-
return await this.
|
|
856
|
+
return await this.scfService.request('UpdateFunctionCode', params);
|
|
735
857
|
}
|
|
736
858
|
catch (e) {
|
|
737
859
|
throw new error_1.CloudBaseError(`[${funcName}] 函数代码更新失败:${e.message}`, {
|
|
@@ -744,9 +866,9 @@ class FunctionService {
|
|
|
744
866
|
let installDependency;
|
|
745
867
|
// Node 函数默认安装依赖
|
|
746
868
|
installDependency = isNodeFunction(func.runtime) ? 'TRUE' : 'FALSE';
|
|
747
|
-
//
|
|
748
|
-
if (
|
|
749
|
-
installDependency = func.installDependency
|
|
869
|
+
// 是否安装依赖,选项可以覆盖(支持 boolean | string)
|
|
870
|
+
if (func.installDependency !== undefined) {
|
|
871
|
+
installDependency = toBooleanString(func.installDependency);
|
|
750
872
|
}
|
|
751
873
|
const codeParams = await this.getCodeParams({
|
|
752
874
|
func,
|
|
@@ -757,7 +879,7 @@ class FunctionService {
|
|
|
757
879
|
}, installDependency);
|
|
758
880
|
const params = {
|
|
759
881
|
FunctionName: funcName,
|
|
760
|
-
|
|
882
|
+
Namespace: namespace,
|
|
761
883
|
Handler: func.handler || 'index.main',
|
|
762
884
|
InstallDependency: installDependency,
|
|
763
885
|
Code: codeParams
|
|
@@ -769,7 +891,7 @@ class FunctionService {
|
|
|
769
891
|
// 等待函数状态正常
|
|
770
892
|
await this.waitFunctionActive(funcName, codeSecret);
|
|
771
893
|
// 更新云函数代码
|
|
772
|
-
const res = await this.
|
|
894
|
+
const res = await this.scfService.request('UpdateFunctionCode', params);
|
|
773
895
|
if (installDependency && func.isWaitInstall === true) {
|
|
774
896
|
await this.waitFunctionActive(funcName, codeSecret);
|
|
775
897
|
}
|
|
@@ -1153,7 +1275,8 @@ class FunctionService {
|
|
|
1153
1275
|
if (Status === constant_1.SCF_STATUS.CREATE_FAILED) {
|
|
1154
1276
|
const errorDetails = (StatusReasons === null || StatusReasons === void 0 ? void 0 : StatusReasons.map(item => `[${item.ErrorCode}] ${item.ErrorMessage}`).join('\n')) || '';
|
|
1155
1277
|
const errorMsg = `云函数创建失败${StatusDesc ? `\n状态描述: ${StatusDesc}` : ''}${errorDetails ? `\n失败信息: ${errorDetails}` : ''}`;
|
|
1156
|
-
|
|
1278
|
+
// 注意:这里不传递 RequestId,因为这是 GetFunction 的 RequestId,不是导致失败的 CreateFunction/UpdateFunctionCode 的 RequestId
|
|
1279
|
+
throw new error_1.CloudBaseError(errorMsg);
|
|
1157
1280
|
}
|
|
1158
1281
|
// 函数状态正常
|
|
1159
1282
|
clearInterval(ticker);
|
|
@@ -1333,7 +1456,12 @@ class FunctionService {
|
|
|
1333
1456
|
// 清理临时文件
|
|
1334
1457
|
await packer.clean();
|
|
1335
1458
|
if (err) {
|
|
1336
|
-
|
|
1459
|
+
// 保留完整的错误信息(避免原始错误丢失)
|
|
1460
|
+
const errorMessage = err.message || err.error || String(err);
|
|
1461
|
+
const errorCode = err.code || err.statusCode || '';
|
|
1462
|
+
reject(new error_1.CloudBaseError(`COS 上传失败: ${errorMessage}${errorCode ? ` (${errorCode})` : ''}`, {
|
|
1463
|
+
code: errorCode
|
|
1464
|
+
}));
|
|
1337
1465
|
}
|
|
1338
1466
|
else {
|
|
1339
1467
|
resolve(data);
|
|
@@ -1386,7 +1514,16 @@ class FunctionService {
|
|
|
1386
1514
|
headers
|
|
1387
1515
|
});
|
|
1388
1516
|
if (!response.ok) {
|
|
1389
|
-
|
|
1517
|
+
// 尝试获取响应体中的错误信息
|
|
1518
|
+
let errorDetail = '';
|
|
1519
|
+
try {
|
|
1520
|
+
const responseText = await response.text();
|
|
1521
|
+
errorDetail = responseText ? ` - ${responseText}` : '';
|
|
1522
|
+
}
|
|
1523
|
+
catch (e) {
|
|
1524
|
+
// 忽略响应体解析错误
|
|
1525
|
+
}
|
|
1526
|
+
throw new error_1.CloudBaseError(`上传失败: ${response.status} ${response.statusText}${errorDetail}`);
|
|
1390
1527
|
}
|
|
1391
1528
|
// 清理临时文件
|
|
1392
1529
|
await packer.clean();
|
package/lib/storage/index.js
CHANGED
|
@@ -623,15 +623,25 @@ class StorageService {
|
|
|
623
623
|
* PRIVATE:仅创建者及管理员可读写
|
|
624
624
|
* ADMINWRITE:所有用户可读,仅管理员可写
|
|
625
625
|
* ADMINONLY:仅管理员可读写
|
|
626
|
-
*
|
|
626
|
+
* CUSTOM:自定义安全规则
|
|
627
|
+
* @returns {Promise<{ acl: AclType, rule?: IStorageAclRule }>}
|
|
627
628
|
*/
|
|
628
629
|
async getStorageAcl() {
|
|
629
630
|
const { bucket, env } = this.getStorageConfig();
|
|
630
|
-
const res = await this.tcbService.request('
|
|
631
|
+
const res = await this.tcbService.request('DescribeStorageSafeRule', {
|
|
631
632
|
EnvId: env,
|
|
632
633
|
Bucket: bucket
|
|
633
634
|
});
|
|
634
|
-
|
|
635
|
+
const result = { acl: res.AclTag };
|
|
636
|
+
if (res.AclTag === 'CUSTOM' && res.Rule) {
|
|
637
|
+
try {
|
|
638
|
+
result.rule = JSON.parse(res.Rule);
|
|
639
|
+
}
|
|
640
|
+
catch (_a) {
|
|
641
|
+
// Rule 可能不是 JSON 格式,忽略解析错误
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
return result;
|
|
635
645
|
}
|
|
636
646
|
/**
|
|
637
647
|
* 设置文件存储权限
|
|
@@ -639,20 +649,38 @@ class StorageService {
|
|
|
639
649
|
* PRIVATE:仅创建者及管理员可读写
|
|
640
650
|
* ADMINWRITE:所有用户可读,仅管理员可写
|
|
641
651
|
* ADMINONLY:仅管理员可读写
|
|
642
|
-
*
|
|
652
|
+
* CUSTOM:自定义安全规则(需要传入 rule 参数)
|
|
653
|
+
* @param {AclType} acl 权限类型
|
|
654
|
+
* @param {IStorageAclRule} [rule] 自定义安全规则,当 acl 为 CUSTOM 时必填
|
|
643
655
|
* @returns
|
|
656
|
+
* @example
|
|
657
|
+
* // 设置简易权限
|
|
658
|
+
* await storage.setStorageAcl('READONLY')
|
|
659
|
+
*
|
|
660
|
+
* // 设置自定义安全规则
|
|
661
|
+
* await storage.setStorageAcl('CUSTOM', {
|
|
662
|
+
* read: true,
|
|
663
|
+
* write: 'resource.openid == auth.uid'
|
|
664
|
+
* })
|
|
644
665
|
*/
|
|
645
|
-
async setStorageAcl(acl) {
|
|
646
|
-
const validAcl = ['READONLY', 'PRIVATE', 'ADMINWRITE', 'ADMINONLY'];
|
|
666
|
+
async setStorageAcl(acl, rule) {
|
|
667
|
+
const validAcl = ['READONLY', 'PRIVATE', 'ADMINWRITE', 'ADMINONLY', 'CUSTOM'];
|
|
647
668
|
if (!validAcl.includes(acl)) {
|
|
648
|
-
throw new error_1.CloudBaseError('
|
|
669
|
+
throw new error_1.CloudBaseError(`非法的权限类型: "${acl}", 有效值: ${validAcl.join(', ')}`);
|
|
670
|
+
}
|
|
671
|
+
if (acl === 'CUSTOM' && !rule) {
|
|
672
|
+
throw new error_1.CloudBaseError('使用 CUSTOM 权限类型时,必须提供 rule 参数');
|
|
649
673
|
}
|
|
650
674
|
const { bucket, env } = this.getStorageConfig();
|
|
651
|
-
|
|
675
|
+
const params = {
|
|
652
676
|
EnvId: env,
|
|
653
677
|
Bucket: bucket,
|
|
654
678
|
AclTag: acl
|
|
655
|
-
}
|
|
679
|
+
};
|
|
680
|
+
if (acl === 'CUSTOM' && rule) {
|
|
681
|
+
params.Rule = JSON.stringify(rule);
|
|
682
|
+
}
|
|
683
|
+
return this.tcbService.request('ModifyStorageSafeRule', params);
|
|
656
684
|
}
|
|
657
685
|
/**
|
|
658
686
|
* 遍历云端文件夹
|
package/package.json
CHANGED
|
@@ -185,6 +185,18 @@ export interface IFunctionCode {
|
|
|
185
185
|
TempCosObjectName?: string;
|
|
186
186
|
ZipFile?: string;
|
|
187
187
|
CosTimestamp?: string;
|
|
188
|
+
ImageConfig?: {
|
|
189
|
+
ImageType?: string;
|
|
190
|
+
ImageUri?: string;
|
|
191
|
+
RegistryId?: string;
|
|
192
|
+
EntryPoint?: string;
|
|
193
|
+
Command?: string;
|
|
194
|
+
Args?: string;
|
|
195
|
+
ContainerImageAccelerate?: boolean;
|
|
196
|
+
ImagePort?: number;
|
|
197
|
+
CommandList?: string[];
|
|
198
|
+
ArgsList?: string[];
|
|
199
|
+
};
|
|
188
200
|
}
|
|
189
201
|
export interface ILayerVersionItem {
|
|
190
202
|
LayerName: string;
|
|
@@ -12,8 +12,15 @@ export interface ICloudFunctionConfig {
|
|
|
12
12
|
envVariables?: Record<string, string | number | boolean>;
|
|
13
13
|
runtime?: string;
|
|
14
14
|
vpc?: IFunctionVPC;
|
|
15
|
-
installDependency?: boolean;
|
|
16
|
-
l5?: boolean;
|
|
15
|
+
installDependency?: boolean | 'TRUE' | 'FALSE';
|
|
16
|
+
l5?: boolean | 'TRUE' | 'FALSE';
|
|
17
|
+
asyncRunEnable?: boolean | 'TRUE' | 'FALSE';
|
|
18
|
+
traceEnable?: boolean | 'TRUE' | 'FALSE';
|
|
19
|
+
autoDeployClsTopicIndex?: boolean | 'TRUE' | 'FALSE';
|
|
20
|
+
autoCreateClsTopic?: boolean | 'TRUE' | 'FALSE';
|
|
21
|
+
dnsCache?: boolean | 'TRUE' | 'FALSE';
|
|
22
|
+
publish?: boolean | 'TRUE' | 'FALSE';
|
|
23
|
+
ignoreSysLog?: boolean;
|
|
17
24
|
memorySize?: number;
|
|
18
25
|
role?: string;
|
|
19
26
|
}
|
|
@@ -44,8 +51,13 @@ export interface ICloudFunction extends ICloudFunctionConfig {
|
|
|
44
51
|
};
|
|
45
52
|
};
|
|
46
53
|
instanceConcurrencyConfig?: {
|
|
47
|
-
dynamicEnabled?: 'FALSE';
|
|
54
|
+
dynamicEnabled?: boolean | 'TRUE' | 'FALSE';
|
|
48
55
|
maxConcurrency?: number;
|
|
56
|
+
instanceIsolationEnabled?: boolean | 'TRUE' | 'FALSE';
|
|
57
|
+
type?: string;
|
|
58
|
+
mixNodeConfig?: any;
|
|
59
|
+
sessionConfig?: any;
|
|
60
|
+
[key: string]: any;
|
|
49
61
|
};
|
|
50
62
|
handler?: string;
|
|
51
63
|
codeSecret?: string;
|
package/types/storage/index.d.ts
CHANGED
|
@@ -59,7 +59,13 @@ export interface IGetBucketOpions {
|
|
|
59
59
|
marker?: string;
|
|
60
60
|
maxKeys?: number;
|
|
61
61
|
}
|
|
62
|
-
export type AclType = 'READONLY' | 'PRIVATE' | 'ADMINWRITE' | 'ADMINONLY';
|
|
62
|
+
export type AclType = 'READONLY' | 'PRIVATE' | 'ADMINWRITE' | 'ADMINONLY' | 'CUSTOM';
|
|
63
|
+
export interface IStorageAclRule {
|
|
64
|
+
/** 读权限规则,true 表示所有用户可读,字符串表示自定义规则表达式 */
|
|
65
|
+
read: boolean | string;
|
|
66
|
+
/** 写权限规则,true 表示所有用户可写,字符串表示自定义规则表达式 */
|
|
67
|
+
write: boolean | string;
|
|
68
|
+
}
|
|
63
69
|
type OnProgress = (progressData: IProgressData) => void;
|
|
64
70
|
type OnFileFinish = (error: Error, res: any, fileData: any) => void;
|
|
65
71
|
export declare class StorageService {
|
|
@@ -220,19 +226,34 @@ export declare class StorageService {
|
|
|
220
226
|
* PRIVATE:仅创建者及管理员可读写
|
|
221
227
|
* ADMINWRITE:所有用户可读,仅管理员可写
|
|
222
228
|
* ADMINONLY:仅管理员可读写
|
|
223
|
-
*
|
|
229
|
+
* CUSTOM:自定义安全规则
|
|
230
|
+
* @returns {Promise<{ acl: AclType, rule?: IStorageAclRule }>}
|
|
224
231
|
*/
|
|
225
|
-
getStorageAcl(): Promise<
|
|
232
|
+
getStorageAcl(): Promise<{
|
|
233
|
+
acl: AclType;
|
|
234
|
+
rule?: IStorageAclRule;
|
|
235
|
+
}>;
|
|
226
236
|
/**
|
|
227
237
|
* 设置文件存储权限
|
|
228
238
|
* READONLY:所有用户可读,仅创建者和管理员可写
|
|
229
239
|
* PRIVATE:仅创建者及管理员可读写
|
|
230
240
|
* ADMINWRITE:所有用户可读,仅管理员可写
|
|
231
241
|
* ADMINONLY:仅管理员可读写
|
|
232
|
-
*
|
|
242
|
+
* CUSTOM:自定义安全规则(需要传入 rule 参数)
|
|
243
|
+
* @param {AclType} acl 权限类型
|
|
244
|
+
* @param {IStorageAclRule} [rule] 自定义安全规则,当 acl 为 CUSTOM 时必填
|
|
233
245
|
* @returns
|
|
234
|
-
|
|
235
|
-
|
|
246
|
+
* @example
|
|
247
|
+
* // 设置简易权限
|
|
248
|
+
* await storage.setStorageAcl('READONLY')
|
|
249
|
+
*
|
|
250
|
+
* // 设置自定义安全规则
|
|
251
|
+
* await storage.setStorageAcl('CUSTOM', {
|
|
252
|
+
* read: true,
|
|
253
|
+
* write: 'resource.openid == auth.uid'
|
|
254
|
+
* })
|
|
255
|
+
*/
|
|
256
|
+
setStorageAcl(acl: AclType, rule?: IStorageAclRule): Promise<IResponseInfo>;
|
|
236
257
|
/**
|
|
237
258
|
* 遍历云端文件夹
|
|
238
259
|
* @param {string} prefix
|