perf: 群晖支持刷新登录有效期

This commit is contained in:
xiaojunnuo
2026-02-15 18:43:53 +08:00
parent 32c3ce5c98
commit 42c7ec2f75
4 changed files with 100 additions and 1 deletions

View File

@@ -124,6 +124,23 @@ export class SynologyAccess extends BaseAccess {
})
timeout = 120;
@AccessInput({
title: "测试",
component: {
name: "api-test",
action: "onTestRequest",
},
helper: "点击测试接口看是否正常",
})
testRequest = true;
async onTestRequest() {
const client = new SynologyClient(this as any, this.ctx.http, this.ctx.logger, this.skipSslVerify);
await client.doLogin();
await client.getCertList();
return "ok";
}
onLoginWithOPTCode(data: { otpCode: string }) {
const ctx = this.ctx;
const client = new SynologyClient(this as any, ctx.http, ctx.logger, this.skipSslVerify);

View File

@@ -1 +1,2 @@
export * from "./plugin-deploy-to-panel.js";
export * from "./plugin-keep-alive.js";

View File

@@ -46,7 +46,7 @@ export class SynologyDeployToPanel extends AbstractPlusTaskPlugin {
//授权选择框
@TaskInput({
title: "群晖授权",
helper: "群晖登录授权,请确保账户是管理员用户组",
helper: "群晖登录授权,请确保账户是管理员用户组\n群晖OTP授权有效期只有30天您还需要添加“群晖-刷新OTP登录有效期”任务做登录有效期保活",
component: {
name: "access-selector",
type: "synology",

View File

@@ -0,0 +1,81 @@
import { IsTaskPlugin, pluginGroups, RunStrategy, TaskInput, TaskOutput } from "@certd/pipeline";
import { AbstractPlusTaskPlugin } from "@certd/plugin-plus";
import dayjs from "dayjs";
@IsTaskPlugin({
name: "SynologyKeepAlive",
title: "群晖-刷新OTP登录有效期",
icon: "simple-icons:synology",
group: pluginGroups.panel.key,
desc: "群晖登录状态可能30天失效需要在失效之前登录一次刷新有效期您可以将其放在“部署到群晖面板”任务之后",
showRunStrategy: false,
default: {
strategy: {
runStrategy: RunStrategy.AlwaysRun,
},
},
needPlus: true,
})
export class SynologyKeepAlivePlugin extends AbstractPlusTaskPlugin {
@TaskInput({
title: "群晖授权",
helper: "群晖登录授权,请确保账户是管理员用户组",
component: {
name: "access-selector",
type: "synology",
},
required: true,
})
accessId!: string;
//授权选择框
@TaskInput({
title: "间隔天数",
helper: "多少天刷新一次建议15天以内",
component: {
name: "number-input",
type: "number",
min: 1,
max: 30,
},
required: true,
})
intervalDays!: number;
@TaskOutput({
title: "上次刷新时间",
type :"SynologyLastRefreshTime"
})
lastRefreshTime!: number;
async onInstance() {}
async execute(): Promise<void> {
this.logger.info("开始刷新群晖登录有效期");
const now = dayjs()
const status = this.getLastStatus();
if (status) {
let lastRefreshTime = this.getLastOutput("lastRefreshTime");
lastRefreshTime = lastRefreshTime || 0;
this.lastRefreshTime = lastRefreshTime;
const lastTime = dayjs(lastRefreshTime);
const diffDays = now.diff(lastTime, "day");
if (diffDays < this.intervalDays) {
this.logger.info(`距离上次刷新有效期${diffDays.toFixed(0)}天(${this.intervalDays}天),无需刷新`);
this.logger.info(`下一次刷新时间${lastTime.add(this.intervalDays, "day").format("YYYY-MM-DD")}`);
return;
}
}
// const access: SynologyAccess = await this.getAccess<SynologyAccess>(this.accessId);
// const client = new SynologyClient(access as any, this.ctx.http, this.ctx.logger, access.skipSslVerify);
// await client.doLogin();
// await client.getCertList();
this.lastRefreshTime = now.unix();
this.logger.info("刷新群晖登录有效期成功");
}
}
new SynologyKeepAlivePlugin();