Skip to content

Commit

Permalink
fix #84 (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
walle233 authored May 15, 2022
1 parent d2a0f75 commit dd48e3d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 4 additions & 4 deletions packages/app-console/src/views/cloudfunction/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,14 @@
/>

<!-- 表单对话框 -->
<el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible">
<el-dialog :title="textMap[dialogStatus]" width="600px" :visible.sync="dialogFormVisible">
<el-form
ref="dataForm"
:rules="rules"
:model="form"
label-position="left"
label-width="120px"
style="width: 400px; margin-left:20px;"
style="width: 500px; margin-left:20px;"
>
<el-form-item v-if="form._id" label="ID" prop="_id">
<div :value="form._id">{{ form._id }}</div>
Expand Down Expand Up @@ -358,8 +358,8 @@ function getDefaultFormValue() {
}
const formRules = {
name: [{ required: true, message: '函数标识不可为空', trigger: 'blur' }],
label: [{ required: true, message: '函数显示名称不可为空', trigger: 'blur' }]
name: [{ required: true, message: '标识不可为空,且只能含字母、数字、下划线及中划线', trigger: 'blur', pattern: /^[a-zA-Z0-9_\-]+$/ }],
label: [{ required: true, message: '显示名称不可为空', trigger: 'blur' }]
}
export default {
Expand Down
6 changes: 5 additions & 1 deletion packages/system-server/src/handler/function/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export async function handleCreateFunction(req: Request, res: Response) {
const body = req.body
if (!body.name) return res.status(422).send('name cannot be empty')
if (!body.code) return res.status(422).send('code cannot be empty')
if (!body.label) return res.status(422).send('label cannot be empty')
//check label
const labelPattern = /^[a-zA-Z0-9_\-]+$/
if (!labelPattern.test(body.label)) return res.status(422).send('label 只能含字母、数字、下划线及中划线')

// function name should be unique
const total = await db.collection(CN_FUNCTIONS)
Expand All @@ -52,7 +56,7 @@ export async function handleCreateFunction(req: Request, res: Response) {
compiledCode: compileTs2js(body.code),
tags: body.tags ?? [],
triggers: [],
label: body.label ?? 'New Function',
label: body.label,
version: 0,
hash: hashFunctionCode(body.code),
created_at: new Date(),
Expand Down

0 comments on commit dd48e3d

Please sign in to comment.