chore: format

This commit is contained in:
xiaojunnuo
2026-05-31 01:41:33 +08:00
parent acd440106b
commit 4b57a0d729
557 changed files with 12530 additions and 14039 deletions
@@ -1,29 +1,27 @@
import { AccessInput, BaseAccess, IsAccess } from "@certd/pipeline";
import { HttpRequestConfig } from "@certd/basic";
/**
*/
@IsAccess({
name: "github",
title: "Github授权",
desc: "",
icon: "ion:logo-github"
icon: "ion:logo-github",
})
export class GithubAccess extends BaseAccess {
@AccessInput({
title: "接口地址",
component: {
placeholder: "可以使用反向代理地址",
component: {
name: "a-input",
vModel: "value"
}
vModel: "value",
},
},
helper:"默认值:https://api.github.com",
helper: "默认值:https://api.github.com",
encrypt: false,
required: false
required: false,
})
endpoint!: string;
@@ -33,12 +31,12 @@ export class GithubAccess extends BaseAccess {
placeholder: "GithubToken",
component: {
name: "a-input",
vModel: "value"
}
vModel: "value",
},
},
helper:"支持匿名访问的接口可以不填",
helper: "支持匿名访问的接口可以不填",
encrypt: true,
required: false
required: false,
})
githubToken!: string;
@@ -48,41 +46,39 @@ export class GithubAccess extends BaseAccess {
placeholder: "http://192.168.x.x:10811",
component: {
name: "a-input",
vModel: "value"
}
vModel: "value",
},
},
encrypt: false,
required: false
required: false,
})
httpProxy!: string;
@AccessInput({
title: "测试",
component: {
name: "api-test",
action: "TestRequest"
action: "TestRequest",
},
helper: "点击测试接口是否正常"
helper: "点击测试接口是否正常",
})
testRequest = true;
async onTestRequest() {
await this.getRelease({repoName:"certd/certd"})
return "ok"
await this.getRelease({ repoName: "certd/certd" });
return "ok";
}
async getRelease(req:{repoName:string}){
const url = `/repos/${req.repoName}/releases/latest`;
return await this.doRequest({
url,
method: "GET",
data:{}
});
async getRelease(req: { repoName: string }) {
const url = `/repos/${req.repoName}/releases/latest`;
return await this.doRequest({
url,
method: "GET",
data: {},
});
}
async doRequest(req:HttpRequestConfig){
async doRequest(req: HttpRequestConfig) {
/**
* async function getLatestRelease() {
* const { REPO_OWNER, REPO_NAME, API_URL, TOKEN } = CONFIG.GITHUB;
@@ -113,18 +109,18 @@ export class GithubAccess extends BaseAccess {
* }
*/
const headers:any = {}
if(this.githubToken){
headers.Authorization = `token ${this.githubToken}`
const headers: any = {};
if (this.githubToken) {
headers.Authorization = `token ${this.githubToken}`;
}
const baseURL= this.endpoint || "https://api.github.com";
const res = await this.ctx.http.request({
const baseURL = this.endpoint || "https://api.github.com";
const res = await this.ctx.http.request({
url: req.url,
baseURL,
method: req.method || "POST",
data: req.data,
headers,
httpProxy: this.httpProxy||undefined,
httpProxy: this.httpProxy || undefined,
});
if (res) {
@@ -134,6 +130,4 @@ export class GithubAccess extends BaseAccess {
}
}
new GithubAccess();
@@ -6,7 +6,7 @@ import { SshClient } from "../../plugin-lib/ssh/ssh.js";
//命名规范,插件类型+功能(就是目录plugin-demo中的demo),大写字母开头,驼峰命名
name: "GithubCheckRelease",
title: "Github-检查Release版本",
desc:"检查最新Release版本并推送消息",
desc: "检查最新Release版本并推送消息",
icon: "ion:logo-github",
//插件分组
group: pluginGroups.other.key,
@@ -14,9 +14,9 @@ import { SshClient } from "../../plugin-lib/ssh/ssh.js";
default: {
//默认值配置照抄即可
strategy: {
runStrategy: RunStrategy.AlwaysRun
}
}
runStrategy: RunStrategy.AlwaysRun,
},
},
})
//类名规范,跟上面插件名称(name)一致
export class GithubCheckRelease extends AbstractTaskPlugin {
@@ -25,29 +25,28 @@ export class GithubCheckRelease extends AbstractTaskPlugin {
title: "Github授权",
component: {
name: "access-selector",
type: "github" //固定授权类型
type: "github", //固定授权类型
},
required: true //必填
required: true, //必填
})
accessId!: string;
@TaskInput({
title: "仓库名称",
helper:"owner/name,比如 certd/certd",
required:true,
helper: "owner/name,比如 certd/certd",
required: true,
})
repoName!: string;
@TaskInput({
title: "通知渠道",
component:{
name:"notification-selector",
select:{
mode:"tags"
}
component: {
name: "notification-selector",
select: {
mode: "tags",
},
},
required:false,
required: false,
})
notificationIds!: number[];
@@ -56,23 +55,22 @@ export class GithubCheckRelease extends AbstractTaskPlugin {
})
lastVersion?: string;
@TaskInput({
title: '主机登录配置',
helper: '登录',
title: "主机登录配置",
helper: "登录",
component: {
name: 'access-selector',
type: 'ssh',
name: "access-selector",
type: "ssh",
},
required: false,
})
sshAccessId!: string;
@TaskInput({
title: 'shell脚本命令',
title: "shell脚本命令",
component: {
name: 'a-textarea',
vModel: 'value',
name: "a-textarea",
vModel: "value",
rows: 6,
placeholder: `
# 拉取最新镜像
@@ -93,68 +91,63 @@ nohup sh -c '$RESTART_CERT' >/dev/null 2>&1 & echo '10秒后重启' && exit
})
script!: string;
//插件实例化时执行的方法
async onInstance() {
}
async onInstance() {}
//插件执行方法
async execute(): Promise<string> {
const access = await this.getAccess<GithubAccess>(this.accessId);
const res = await access.getRelease({repoName:this.repoName})
if(res == null){
throw new Error(`获取${this.repoName}最新版本失败`)
const res = await access.getRelease({ repoName: this.repoName });
if (res == null) {
throw new Error(`获取${this.repoName}最新版本失败`);
}
const lastVersion = this.ctx.lastStatus?.status?.output?.lastVersion;
if(res.tag_name == null || res.tag_name ==lastVersion){
if (res.tag_name == null || res.tag_name == lastVersion) {
this.logger.info(`暂无更新,${res.tag_name}`);
this.lastVersion = res.tag_name || lastVersion;
return "skip"
return "skip";
}
//有更新
this.logger.info(`有更新,${lastVersion??"0"}->${res.tag_name}`)
this.logger.info(`有更新,${lastVersion ?? "0"}->${res.tag_name}`);
this.lastVersion = res.tag_name;
// const body = res.body.replaceAll("* ","- ")
//仅每行开头的* 替换成 -, *号前面可以有空格
const body = res.body.replace(/^(\s*)\* /gm, "$1- ")
const body = res.body.replace(/^(\s*)\* /gm, "$1- ");
if (this.notificationIds && this.notificationIds.length > 0){
if (this.notificationIds && this.notificationIds.length > 0) {
//发送通知
for (const notificationId of this.notificationIds) {
await this.ctx.notificationService.send({
id: notificationId,
useDefault: false,
useEmail:false,
useEmail: false,
logger: this.logger,
body: {
title: `${this.repoName} 新版本 ${this.lastVersion} 发布`,
content: `${body}\n\n > [Certd](https://certd.docmirror.cn),不止证书自动化,插件解锁无限可能!\n\n`,
url: `https://github.com/${this.repoName}/releases/tag/${this.lastVersion}`,
notificationType: "githubReleaseCheck",
}
})
},
});
}
}
if (this.script != null && this.script.trim() != "") {
const connectConf = await this.getAccess(this.sshAccessId);
const sshClient = new SshClient(this.logger);
const scripts = this.script.split('\n');
const scripts = this.script.split("\n");
await sshClient.exec({
connectConf,
script: scripts,
env: {
REPO: this.repoName,
LAST_VERSION: this.lastVersion,
}
},
});
}
}
}
new GithubCheckRelease();