mirror of
https://github.com/certd/certd.git
synced 2026-04-15 13:32:37 +08:00
perf: 群晖支持OTP双重验证登录
This commit is contained in:
33
packages/core/pipeline/src/core/handler.ts
Normal file
33
packages/core/pipeline/src/core/handler.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import _ from "lodash-es";
|
||||
import { HttpClient, ILogger } from "../utils";
|
||||
|
||||
export type PluginRequest = {
|
||||
type: "plugin" | "access";
|
||||
typeName: string;
|
||||
action: string;
|
||||
input: any;
|
||||
data: any;
|
||||
};
|
||||
|
||||
export type RequestHandleContext = {
|
||||
http: HttpClient;
|
||||
logger: ILogger;
|
||||
};
|
||||
|
||||
export class RequestHandler {
|
||||
async onRequest(req: PluginRequest, ctx: RequestHandleContext) {
|
||||
if (!req.action) {
|
||||
throw new Error("action is required");
|
||||
}
|
||||
|
||||
const methodName = `on${_.upperFirst(req.action)}`;
|
||||
|
||||
// @ts-ignore
|
||||
const method = this[methodName];
|
||||
if (method) {
|
||||
// @ts-ignore
|
||||
return await this[methodName](req.data, ctx);
|
||||
}
|
||||
throw new Error(`action ${req.action} not found`);
|
||||
}
|
||||
}
|
||||
@@ -4,3 +4,4 @@ export * from "./context.js";
|
||||
export * from "./storage.js";
|
||||
export * from "./file-store.js";
|
||||
export * from "./license.js";
|
||||
export * from "./handler.js";
|
||||
|
||||
@@ -45,7 +45,7 @@ export function createAxiosService({ logger }: { logger: Logger }) {
|
||||
// 创建一个 axios 实例
|
||||
const service = axios.create();
|
||||
|
||||
const defaultAgents = createAgent();
|
||||
// const defaultAgents = createAgent();
|
||||
// 请求拦截
|
||||
service.interceptors.request.use(
|
||||
(config: any) => {
|
||||
@@ -53,13 +53,14 @@ export function createAxiosService({ logger }: { logger: Logger }) {
|
||||
if (config.timeout == null) {
|
||||
config.timeout = 15000;
|
||||
}
|
||||
let agents = defaultAgents;
|
||||
if (config.skipSslVerify) {
|
||||
agents = createAgent({ rejectUnauthorized: config.rejectUnauthorized });
|
||||
}
|
||||
|
||||
config.httpsAgent = agents.httpsAgent;
|
||||
config.httpAgent = agents.httpAgent;
|
||||
// let agents = defaultAgents;
|
||||
// if (config.skipSslVerify) {
|
||||
// logger.info("跳过SSL验证");
|
||||
// agents = createAgent({ rejectUnauthorized: config.rejectUnauthorized });
|
||||
// }
|
||||
// delete config.skipSslVerify;
|
||||
// config.httpsAgent = agents.httpsAgent;
|
||||
// config.httpAgent = agents.httpAgent;
|
||||
|
||||
return config;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user