perf: 群晖支持OTP双重验证登录

This commit is contained in:
xiaojunnuo
2024-09-20 19:29:16 +08:00
parent df55299e6f
commit 8b8039f42b
7 changed files with 160 additions and 8 deletions

View 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`);
}
}

View File

@@ -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";

View File

@@ -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;
},