2024-09-11 18:01:46 +08:00
|
|
|
|
import { AbstractTaskPlugin, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput, TaskInstanceContext } from '@certd/pipeline';
|
|
|
|
|
|
import { CertInfo, CertReader } from '@certd/plugin-cert';
|
2025-03-18 00:52:50 +08:00
|
|
|
|
import { CertApplyPluginNames} from '@certd/plugin-cert';
|
2024-09-11 18:01:46 +08:00
|
|
|
|
export type CustomScriptContext = {
|
|
|
|
|
|
CertReader: typeof CertReader;
|
|
|
|
|
|
self: CustomScriptPlugin;
|
|
|
|
|
|
} & TaskInstanceContext;
|
|
|
|
|
|
|
|
|
|
|
|
@IsTaskPlugin({
|
|
|
|
|
|
name: 'CustomScript',
|
|
|
|
|
|
title: '自定义js脚本',
|
2024-09-29 01:14:21 +08:00
|
|
|
|
icon: 'ri:javascript-line',
|
|
|
|
|
|
desc: '【仅管理员】运行自定义js脚本执行',
|
2025-07-22 12:22:54 +08:00
|
|
|
|
group: pluginGroups.admin.key,
|
2025-04-10 23:44:11 +08:00
|
|
|
|
showRunStrategy: true,
|
2025-07-22 11:51:27 +08:00
|
|
|
|
onlyAdmin: true,
|
2024-09-11 18:01:46 +08:00
|
|
|
|
default: {
|
|
|
|
|
|
strategy: {
|
|
|
|
|
|
runStrategy: RunStrategy.SkipWhenSucceed,
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
})
|
|
|
|
|
|
export class CustomScriptPlugin extends AbstractTaskPlugin {
|
|
|
|
|
|
@TaskInput({
|
|
|
|
|
|
title: '脚本',
|
2024-11-04 21:34:41 +08:00
|
|
|
|
helper: '自定义js脚本,[脚本编写帮助文档](https://certd.docmirror.cn/guide/use/custom-script/)',
|
2024-09-11 18:01:46 +08:00
|
|
|
|
component: {
|
|
|
|
|
|
name: 'a-textarea',
|
|
|
|
|
|
vModel: 'value',
|
|
|
|
|
|
rows: 10,
|
|
|
|
|
|
style: 'background-color: #000c17;color: #fafafa;',
|
|
|
|
|
|
},
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
})
|
|
|
|
|
|
script!: string;
|
|
|
|
|
|
|
|
|
|
|
|
@TaskInput({
|
|
|
|
|
|
title: '域名证书',
|
|
|
|
|
|
helper: '请选择前置任务输出的域名证书',
|
|
|
|
|
|
component: {
|
2024-10-07 03:21:16 +08:00
|
|
|
|
name: 'output-selector',
|
2025-03-18 00:52:50 +08:00
|
|
|
|
from: [...CertApplyPluginNames],
|
2024-09-11 18:01:46 +08:00
|
|
|
|
},
|
2024-10-03 22:03:49 +08:00
|
|
|
|
required: false,
|
2024-09-11 18:01:46 +08:00
|
|
|
|
})
|
|
|
|
|
|
cert!: CertInfo;
|
|
|
|
|
|
|
|
|
|
|
|
async onInstance() {}
|
|
|
|
|
|
async execute(): Promise<void> {
|
2024-09-29 01:14:21 +08:00
|
|
|
|
if (!this.isAdmin()) {
|
|
|
|
|
|
throw new Error('只有管理员才能运行此任务');
|
|
|
|
|
|
}
|
2024-09-11 18:01:46 +08:00
|
|
|
|
this.logger.info('执行自定义脚本:\n', this.script);
|
|
|
|
|
|
const ctx: CustomScriptContext = {
|
|
|
|
|
|
CertReader,
|
|
|
|
|
|
self: this,
|
|
|
|
|
|
...this.ctx,
|
|
|
|
|
|
};
|
|
|
|
|
|
const AsyncFunction = Object.getPrototypeOf(async () => {}).constructor;
|
|
|
|
|
|
const func = new AsyncFunction('ctx', this.script);
|
|
|
|
|
|
return await func(ctx);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
new CustomScriptPlugin();
|