From 96f588e87c7d079cd255dca28c4f84f3b97a9d2a Mon Sep 17 00:00:00 2001 From: maslow Date: Fri, 6 Aug 2021 15:46:59 +0800 Subject: [PATCH 1/6] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=A2=84=E7=BD=AE?= =?UTF-8?q?=E5=87=BD=E6=95=B0=20admin-edit=20=E7=9A=84=E6=A0=87=E8=AF=86?= =?UTF-8?q?=E9=94=99=E8=AF=AF=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops-server/init/functions/admin-edit/index.ts | 9 ++++++--- .../devops-server/init/functions/admin-edit/meta.json | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/devops-server/init/functions/admin-edit/index.ts b/packages/devops-server/init/functions/admin-edit/index.ts index e2078415b6..303df78fbb 100644 --- a/packages/devops-server/init/functions/admin-edit/index.ts +++ b/packages/devops-server/init/functions/admin-edit/index.ts @@ -4,6 +4,8 @@ import * as crypto from 'crypto' const db = cloud.database() exports.main = async function (ctx) { + console.log(ctx) + const uid = ctx.auth?.uid if (!uid) { return 'Unauthorized' @@ -40,7 +42,7 @@ exports.main = async function (ctx) { // update password if (password) { await db.collection('password') - .where({ uid: uid }) + .where({ uid: _id }) .update({ password: hashPassword(password), updated_at: Date.now() @@ -78,13 +80,14 @@ exports.main = async function (ctx) { data['roles'] = roles } + console.log(_id, data) const r = await db.collection('admins') - .where({ _id: uid }) + .where({ _id: _id }) .update(data) return { ...r, - uid + _id } } diff --git a/packages/devops-server/init/functions/admin-edit/meta.json b/packages/devops-server/init/functions/admin-edit/meta.json index feb55cecf8..27291bd24d 100644 --- a/packages/devops-server/init/functions/admin-edit/meta.json +++ b/packages/devops-server/init/functions/admin-edit/meta.json @@ -1,6 +1,6 @@ { - "label": "后台管理-创建管理员", - "name": "admin-create", + "label": "后台管理-编辑管理员", + "name": "admin-edit", "description": "", "enableHTTP": true, "tags": ["后台管理", "预置"] From 5c1a3ceb79d2ab15839b77b28234e0476823f9db Mon Sep 17 00:00:00 2001 From: maslow Date: Fri, 6 Aug 2021 17:45:52 +0800 Subject: [PATCH 2/6] =?UTF-8?q?chore:=20=E6=89=80=E6=9C=89=E9=A2=84?= =?UTF-8?q?=E7=BD=AE=E5=87=BD=E6=95=B0=E5=A2=9E=E5=8A=A0=E5=90=AF=E7=94=A8?= =?UTF-8?q?=E7=8A=B6=E6=80=81=EF=BC=9B=E6=96=B0=E5=A2=9E=E5=8F=91=E9=82=AE?= =?UTF-8?q?=E4=BB=B6=E3=80=81=E8=84=9A=E6=9C=AC=E6=89=A7=E8=A1=8C=20?= =?UTF-8?q?=E9=A2=84=E7=BD=AE=E5=87=BD=E6=95=B0=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/devops-server/init/func-loader.js | 3 ++ .../init/functions/admin-create/meta.json | 1 + .../init/functions/admin-edit/meta.json | 1 + .../init/functions/admin-getinfo/meta.json | 1 + .../init/functions/admin-login/meta.json | 1 + .../functions/aliyun-sms-service/meta.json | 1 + .../functions/email-sender-service/index.ts | 34 +++++++++++++++++++ .../functions/email-sender-service/meta.json | 8 +++++ .../init/functions/exec_shell/index.ts | 17 ++++++++++ .../init/functions/exec_shell/meta.json | 8 +++++ .../init/functions/file-token/meta.json | 1 + .../init/functions/file-upload/meta.json | 1 + .../init/functions/init-app-rbac/meta.json | 1 + .../init/functions/initializer/meta.json | 1 + .../init/functions/injector-admin/meta.json | 1 + .../functions/send-login-smscode/meta.json | 1 + .../init/functions/test/meta.json | 1 + .../functions/user-passwd-login/meta.json | 1 + .../user-password-register/meta.json | 1 + .../init/functions/wx-mp-login/meta.json | 1 + packages/devops-server/init/index.js | 1 - 21 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 packages/devops-server/init/functions/email-sender-service/index.ts create mode 100644 packages/devops-server/init/functions/email-sender-service/meta.json create mode 100644 packages/devops-server/init/functions/exec_shell/index.ts create mode 100644 packages/devops-server/init/functions/exec_shell/meta.json diff --git a/packages/devops-server/init/func-loader.js b/packages/devops-server/init/func-loader.js index 9885e2452b..7df4d2813c 100644 --- a/packages/devops-server/init/func-loader.js +++ b/packages/devops-server/init/func-loader.js @@ -40,6 +40,9 @@ class FunctionLoader { const metaPath = path.join(func_path, 'meta.json') const meta = await this.loadFunctionMeta(metaPath) + if (!meta['status']) { + meta['status'] = 0 + } return { ...meta, code } } diff --git a/packages/devops-server/init/functions/admin-create/meta.json b/packages/devops-server/init/functions/admin-create/meta.json index feb55cecf8..be442b1bad 100644 --- a/packages/devops-server/init/functions/admin-create/meta.json +++ b/packages/devops-server/init/functions/admin-create/meta.json @@ -3,5 +3,6 @@ "name": "admin-create", "description": "", "enableHTTP": true, + "status": 1, "tags": ["后台管理", "预置"] } \ No newline at end of file diff --git a/packages/devops-server/init/functions/admin-edit/meta.json b/packages/devops-server/init/functions/admin-edit/meta.json index 27291bd24d..133439e3b1 100644 --- a/packages/devops-server/init/functions/admin-edit/meta.json +++ b/packages/devops-server/init/functions/admin-edit/meta.json @@ -3,5 +3,6 @@ "name": "admin-edit", "description": "", "enableHTTP": true, + "status": 1, "tags": ["后台管理", "预置"] } \ No newline at end of file diff --git a/packages/devops-server/init/functions/admin-getinfo/meta.json b/packages/devops-server/init/functions/admin-getinfo/meta.json index d3c303ecb4..32932bc7eb 100644 --- a/packages/devops-server/init/functions/admin-getinfo/meta.json +++ b/packages/devops-server/init/functions/admin-getinfo/meta.json @@ -3,5 +3,6 @@ "name": "admin-getinfo", "description": "", "enableHTTP": true, + "status": 1, "tags": ["后台管理", "预置"] } \ No newline at end of file diff --git a/packages/devops-server/init/functions/admin-login/meta.json b/packages/devops-server/init/functions/admin-login/meta.json index 22b1a18f6c..c99fb51fb4 100644 --- a/packages/devops-server/init/functions/admin-login/meta.json +++ b/packages/devops-server/init/functions/admin-login/meta.json @@ -3,5 +3,6 @@ "name": "admin-login", "description": "", "enableHTTP": true, + "status": 1, "tags": ["后台管理", "预置", "登陆"] } \ No newline at end of file diff --git a/packages/devops-server/init/functions/aliyun-sms-service/meta.json b/packages/devops-server/init/functions/aliyun-sms-service/meta.json index af1a2de851..41a7170dba 100644 --- a/packages/devops-server/init/functions/aliyun-sms-service/meta.json +++ b/packages/devops-server/init/functions/aliyun-sms-service/meta.json @@ -3,6 +3,7 @@ "name": "aliyun-sms-service", "description": "阿里云通信-发短信内部调用服务,不开启外网访问", "enableHTTP": false, + "status": 0, "debugParams": "{\n \"phone\": \"13184211245\",\n \"code\": \"1234\"\n}", "tags": ["预置", "阿里云"] } \ No newline at end of file diff --git a/packages/devops-server/init/functions/email-sender-service/index.ts b/packages/devops-server/init/functions/email-sender-service/index.ts new file mode 100644 index 0000000000..2461307dd7 --- /dev/null +++ b/packages/devops-server/init/functions/email-sender-service/index.ts @@ -0,0 +1,34 @@ + +import cloud from '@/cloud-sdk' +import * as nodemailer from 'nodemailer' +import * as assert from 'assert' + +exports.main = async function (ctx) { + const body = ctx.body + const db = cloud.database() + const CONFIG = cloud.shared.get('sys.config.mail') + assert.ok(CONFIG, 'no mail config found') + + const transporter = nodemailer.createTransport({ + host: CONFIG.host, + port: CONFIG.port, + secure: true, // true for 465, false for other ports + auth: { + user: CONFIG.user, + pass: CONFIG.pass, + }, + }) + + // send mail with defined transport object + const info = await transporter.sendMail({ + from: CONFIG.sender, // sender address + to: body.email, // list of receivers + subject: body.subject, // Subject line + text: body.text, // plain text body + // html: "Hello world?", // html body + }) + + console.log(info) + + return info +} diff --git a/packages/devops-server/init/functions/email-sender-service/meta.json b/packages/devops-server/init/functions/email-sender-service/meta.json new file mode 100644 index 0000000000..c4583e8cb3 --- /dev/null +++ b/packages/devops-server/init/functions/email-sender-service/meta.json @@ -0,0 +1,8 @@ +{ + "label": "email-sender-service", + "name": "email-sender-service", + "description": "", + "enableHTTP": false, + "status": 0, + "tags": ["预置"] +} \ No newline at end of file diff --git a/packages/devops-server/init/functions/exec_shell/index.ts b/packages/devops-server/init/functions/exec_shell/index.ts new file mode 100644 index 0000000000..f677e288cb --- /dev/null +++ b/packages/devops-server/init/functions/exec_shell/index.ts @@ -0,0 +1,17 @@ + +import * as child_process from 'child_process' + +/** + * 可修改本函数,安装指定的依赖包。 + * 注意: + * 0. 因客户端请求超时时间限制,函数可能在返回前请求超时,但该命令会继续运行,请知晓 + * 1. 不要开启本函数的 HTTP 访问(安全风险) + * 2. 通常请保持本函数是停用状态(安全风险) + * 3. 其中 `npm run create-internal-pkg` 是为了创建云函数 sdk 内部包,请在更新过依赖后执行此命令,否则在线 IDE 的类型提示将失效 + */ + +exports.main = async function (ctx) { + const r = child_process.execSync("npm i @types/nodemailer nodemailer && npm run create-internal-pkg") + console.log(r.toString()) + return 'ok' +} diff --git a/packages/devops-server/init/functions/exec_shell/meta.json b/packages/devops-server/init/functions/exec_shell/meta.json new file mode 100644 index 0000000000..4c7f76cab4 --- /dev/null +++ b/packages/devops-server/init/functions/exec_shell/meta.json @@ -0,0 +1,8 @@ +{ + "label": "在服务端执行 shell 脚本", + "name": "exec_shell", + "description": "", + "enableHTTP": false, + "status": 0, + "tags": ["预置", "scripts"] +} \ No newline at end of file diff --git a/packages/devops-server/init/functions/file-token/meta.json b/packages/devops-server/init/functions/file-token/meta.json index a4b368b3ff..a97b48ba74 100644 --- a/packages/devops-server/init/functions/file-token/meta.json +++ b/packages/devops-server/init/functions/file-token/meta.json @@ -3,5 +3,6 @@ "name": "file-token", "description": "文件访问令牌", "enableHTTP": true, + "status": 0, "tags": ["预置"] } \ No newline at end of file diff --git a/packages/devops-server/init/functions/file-upload/meta.json b/packages/devops-server/init/functions/file-upload/meta.json index 84c839c85c..7c18ee6f27 100644 --- a/packages/devops-server/init/functions/file-upload/meta.json +++ b/packages/devops-server/init/functions/file-upload/meta.json @@ -3,5 +3,6 @@ "name": "file-upload", "description": "文件上传,请使用 postman/curl 等HTTP工具测试此函数;默认上传至 public 空间下,可自行定义上传逻辑", "enableHTTP": true, + "status": 0, "tags": ["预置"] } \ No newline at end of file diff --git a/packages/devops-server/init/functions/init-app-rbac/meta.json b/packages/devops-server/init/functions/init-app-rbac/meta.json index a48a18471e..63b34ae962 100644 --- a/packages/devops-server/init/functions/init-app-rbac/meta.json +++ b/packages/devops-server/init/functions/init-app-rbac/meta.json @@ -3,5 +3,6 @@ "name": "init-app-rbac", "description": "初始化一个经典的 RBAC,包括基础的权限、角色、初始管理员", "enableHTTP": false, + "status": 1, "tags": ["初始化", "预置"] } \ No newline at end of file diff --git a/packages/devops-server/init/functions/initializer/meta.json b/packages/devops-server/init/functions/initializer/meta.json index bc13538085..dc9aef656a 100644 --- a/packages/devops-server/init/functions/initializer/meta.json +++ b/packages/devops-server/init/functions/initializer/meta.json @@ -4,6 +4,7 @@ "description": "", "enableHTTP": false, "reserved": true, + "status": 1, "tags": ["初始化", "预置"], "triggers": [ { diff --git a/packages/devops-server/init/functions/injector-admin/meta.json b/packages/devops-server/init/functions/injector-admin/meta.json index 2e1ef3b39c..14fd426f93 100644 --- a/packages/devops-server/init/functions/injector-admin/meta.json +++ b/packages/devops-server/init/functions/injector-admin/meta.json @@ -3,5 +3,6 @@ "name": "injector-admin", "description": "", "enableHTTP": false, + "status": 1, "tags": ["预置", "injector"] } \ No newline at end of file diff --git a/packages/devops-server/init/functions/send-login-smscode/meta.json b/packages/devops-server/init/functions/send-login-smscode/meta.json index ce2046079c..1922cfc0b0 100644 --- a/packages/devops-server/init/functions/send-login-smscode/meta.json +++ b/packages/devops-server/init/functions/send-login-smscode/meta.json @@ -3,6 +3,7 @@ "name": "send-login-smscode", "description": "发送登陆短信验证码", "enableHTTP": true, + "status": 0, "debugParams": "{\n \"phone\": \"13184211245\"\n}", "tags": ["预置"] } \ No newline at end of file diff --git a/packages/devops-server/init/functions/test/meta.json b/packages/devops-server/init/functions/test/meta.json index 1c44a3000b..ab3811bb85 100644 --- a/packages/devops-server/init/functions/test/meta.json +++ b/packages/devops-server/init/functions/test/meta.json @@ -3,5 +3,6 @@ "name": "test", "description": "", "enableHTTP": true, + "status": 1, "tags": ["预置"] } \ No newline at end of file diff --git a/packages/devops-server/init/functions/user-passwd-login/meta.json b/packages/devops-server/init/functions/user-passwd-login/meta.json index 1ab9554007..d1579be94b 100644 --- a/packages/devops-server/init/functions/user-passwd-login/meta.json +++ b/packages/devops-server/init/functions/user-passwd-login/meta.json @@ -3,6 +3,7 @@ "name": "user-passwd-login", "description": "用户密码登陆", "enableHTTP": true, + "status": 1, "debugParams": "{\n \"username\": \"less\",\n \"password\": \"less123\"\n}", "tags": ["预置"] } \ No newline at end of file diff --git a/packages/devops-server/init/functions/user-password-register/meta.json b/packages/devops-server/init/functions/user-password-register/meta.json index 6795e6e831..3f120abbad 100644 --- a/packages/devops-server/init/functions/user-password-register/meta.json +++ b/packages/devops-server/init/functions/user-password-register/meta.json @@ -3,6 +3,7 @@ "name": "user-password-register", "description": "用户密码注册", "enableHTTP": true, + "status": 1, "debugParams": "{\"username\":\"less\",\"password\":\"less123\"}", "tags": ["预置"] } \ No newline at end of file diff --git a/packages/devops-server/init/functions/wx-mp-login/meta.json b/packages/devops-server/init/functions/wx-mp-login/meta.json index b639b44aa0..05fd748f34 100644 --- a/packages/devops-server/init/functions/wx-mp-login/meta.json +++ b/packages/devops-server/init/functions/wx-mp-login/meta.json @@ -3,5 +3,6 @@ "name": "wx-mp-login", "description": "微信小程序登陆", "enableHTTP": true, + "status": 0, "tags": ["预置"] } \ No newline at end of file diff --git a/packages/devops-server/init/index.js b/packages/devops-server/init/index.js index 23e712a9b9..776c490e37 100644 --- a/packages/devops-server/init/index.js +++ b/packages/devops-server/init/index.js @@ -215,7 +215,6 @@ async function createBuiltinFunctions() { const triggers = func.triggers || [] const data = { ...func, - status: 1, created_at: Date.now(), updated_at: Date.now() } From b3ea99f8a452a8a0849a849823e724772ec897f7 Mon Sep 17 00:00:00 2001 From: maslow Date: Fri, 6 Aug 2021 17:46:58 +0800 Subject: [PATCH 3/6] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=20devops=20?= =?UTF-8?q?=E6=8E=A7=E5=88=B6=E5=8F=B0=E4=BA=A4=E4=BA=92=E4=BD=93=E9=AA=8C?= =?UTF-8?q?=E3=80=81=E6=A0=B7=E5=BC=8F=E3=80=81=E5=BB=B6=E9=95=BF=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E8=B6=85=E6=97=B6=E6=97=B6=E9=97=B4=E5=88=B0=2060?= =?UTF-8?q?=E7=A7=92=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/devops-admin/src/utils/request.js | 2 +- .../src/views/development/function_logs.vue | 12 +++- .../src/views/development/functions.vue | 55 +++++++++++-------- 3 files changed, 44 insertions(+), 25 deletions(-) diff --git a/packages/devops-admin/src/utils/request.js b/packages/devops-admin/src/utils/request.js index 1cdb69da02..120e9b3fee 100644 --- a/packages/devops-admin/src/utils/request.js +++ b/packages/devops-admin/src/utils/request.js @@ -7,7 +7,7 @@ import { getToken } from '@/utils/auth' const service = axios.create({ baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url // withCredentials: true, // send cookies when cross-domain requests - timeout: 5000 // request timeout + timeout: 60000 // request timeout }) // request interceptor diff --git a/packages/devops-admin/src/views/development/function_logs.vue b/packages/devops-admin/src/views/development/function_logs.vue index 58349a1686..9abbf5a79b 100644 --- a/packages/devops-admin/src/views/development/function_logs.vue +++ b/packages/devops-admin/src/views/development/function_logs.vue @@ -3,13 +3,14 @@
- + 搜索
@@ -20,7 +21,7 @@ v-loading="listLoading" :data="list" border - fit + size="mini" highlight-current-row style="width: 100%;" > @@ -230,3 +231,10 @@ export default { } } + + \ No newline at end of file diff --git a/packages/devops-admin/src/views/development/functions.vue b/packages/devops-admin/src/views/development/functions.vue index eb0fc9eb3b..fdaf4d1103 100644 --- a/packages/devops-admin/src/views/development/functions.vue +++ b/packages/devops-admin/src/views/development/functions.vue @@ -5,16 +5,18 @@ - + 搜索 - + 新建函数 + 只看已启用 @@ -33,23 +35,13 @@ v-loading="listLoading" :data="list" border - fit + size="small" highlight-current-row style="width: 100%;" > - - - @@ -59,7 +51,7 @@ {{ row.label }} - + @@ -88,16 +80,16 @@ - +