From 8b7572a9e58d6b0ab632c7b97addba85b7008a73 Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Sat, 2 Nov 2024 22:04:05 +0800 Subject: [PATCH] chore: 1 --- docs/.vitepress/config.ts | 1 + docs/guide/use/custom-script/index.md | 80 +++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 docs/guide/use/custom-script/index.md diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index 91185bb2f..5dec81bcd 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -98,6 +98,7 @@ export default defineConfig({ { text: "忘记密码", link: "/guide/use/forgotpasswd/" }, { text: "数据备份", link: "/guide/use/backup/" }, { text: "Certd本身的证书更新", link: "/guide/use/https/index.md" }, + { text: "js脚本插件使用", link: "/guide/use/custom-script/index.md" }, { text: "如何贡献代码", link: "/guide/development/index.md" }, ] }, diff --git a/docs/guide/use/custom-script/index.md b/docs/guide/use/custom-script/index.md new file mode 100644 index 000000000..6d8e84200 --- /dev/null +++ b/docs/guide/use/custom-script/index.md @@ -0,0 +1,80 @@ +# 自定义脚本插件 + +## 介绍 + +自定义脚本插件是一个通用的插件,可以通过编写脚本来实现各种功能,例如:调用第三方API、执行系统命令、发送邮件等。 + +## 使用示例 +```js +const certPem = this.ctx.self.cert.crt +const certKey = this.ctx.self.cert.key + +//axios发起http请求上传证书 +const res = await this.ctx.http.request({ + url:"your_cert_deploy_url", + method:"post", + data:{ + crt : certPem, + key : certKey + } +}) +this.ctx.logger.info("上传成功",res.data) + + +``` +## API + + +```ts + +type ctx = { + CertReader: typeof CertReader; + self: CustomScriptPlugin; + //流水线定义 + pipeline: Pipeline; + //步骤定义 + step: Step; + //日志 + logger: Logger; + //当前步骤输入参数跟上一次执行比较是否有变化 + inputChanged: boolean; + //授权获取服务 + accessService: IAccessService; + //邮件服务 + emailService: IEmailService; + //cname记录服务 + cnameProxyService: ICnameProxyService; + //插件配置服务 + pluginConfigService: IPluginConfigService; + //流水线上下文 + pipelineContext: IContext; + //用户上下文 + userContext: IContext; + //http请求客户端 + http: HttpClient; // http.request(AxiosConfig) + //文件存储 + fileStore: FileStore; + //上一次执行结果状态 + lastStatus?: Runnable; + //用户取消信号 + signal: AbortSignal; + //工具类 + utils: typeof utils; + //用户信息 + user: UserInfo; +} + +type CertInfo = { + crt:string; //fullchain证书,即 cert.pem, cert.crt + key:string; // 私钥 + ic: string; //中间证书 + pfx: string;//PFX证书,base64编码 + der: string;//DER证书,base64编码 +} + +type CustomScriptPlugin = { + //可以获取证书 + cert: CertInfo +} + +```