mirror of
https://github.com/certd/certd.git
synced 2026-05-15 12:37:30 +08:00
perf: 支持一键安装脚本
This commit is contained in:
@@ -126,12 +126,12 @@ export class NextTerminalAccess extends BaseAccess {
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
|
||||
|
||||
this.ctx.logger.debug(`Next Terminal API 请求: ${req.method} ${this.baseUrl}${req.url}`);
|
||||
const baseUrl = this.normalizeEndpoint(this.baseUrl);
|
||||
this.ctx.logger.debug(`Next Terminal API 请求: ${req.method} ${baseUrl}${req.url}`);
|
||||
|
||||
const resp = await this.ctx.http.request({
|
||||
url: req.url,
|
||||
baseURL: this.baseUrl,
|
||||
baseURL: baseUrl,
|
||||
method: req.method,
|
||||
headers,
|
||||
params: req.params,
|
||||
|
||||
@@ -29,25 +29,6 @@ interface TokenResponse {
|
||||
challenge_token?: string;
|
||||
}
|
||||
|
||||
function normalizeEndpoint(endpoint: string): string {
|
||||
const trimmed = String(endpoint ?? "").trim();
|
||||
if (!trimmed) {
|
||||
throw new Error("Nginx Proxy Manager 地址不能为空");
|
||||
}
|
||||
|
||||
const withoutTrailingSlash = trimmed.replace(/\/+$/, "");
|
||||
return withoutTrailingSlash.endsWith("/api")
|
||||
? withoutTrailingSlash.slice(0, -4)
|
||||
: withoutTrailingSlash;
|
||||
}
|
||||
|
||||
function describeError(error: unknown, action: string): Error {
|
||||
if (error instanceof Error) {
|
||||
return new Error(`${action} failed: ${error.message}`);
|
||||
}
|
||||
return new Error(`${action} failed`);
|
||||
}
|
||||
|
||||
@IsAccess({
|
||||
name: "nginxProxyManager",
|
||||
title: "Nginx Proxy Manager 授权",
|
||||
@@ -127,8 +108,27 @@ export class NginxProxyManagerAccess extends BaseAccess {
|
||||
private token: string | undefined;
|
||||
private tokenPromise: Promise<string> | undefined;
|
||||
|
||||
normalizeEndpoint(endpoint: string): string {
|
||||
const trimmed = String(endpoint ?? "").trim();
|
||||
if (!trimmed) {
|
||||
throw new Error("Nginx Proxy Manager 地址不能为空");
|
||||
}
|
||||
|
||||
const withoutTrailingSlash = trimmed.replace(/\/+$/, "");
|
||||
return withoutTrailingSlash.endsWith("/api")
|
||||
? withoutTrailingSlash.slice(0, -4)
|
||||
: withoutTrailingSlash;
|
||||
}
|
||||
|
||||
private describeError(error: unknown, action: string): Error {
|
||||
if (error instanceof Error) {
|
||||
return new Error(`${action} failed: ${error.message}`);
|
||||
}
|
||||
return new Error(`${action} failed`);
|
||||
}
|
||||
|
||||
private get apiBaseUrl(): string {
|
||||
const endpoint = normalizeEndpoint(this.endpoint);
|
||||
const endpoint = this.normalizeEndpoint(this.endpoint);
|
||||
return `${endpoint}/api`;
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ export class NginxProxyManagerAccess extends BaseAccess {
|
||||
url: "/nginx/certificates",
|
||||
params: {
|
||||
...(searchQuery ? { query: searchQuery } : {}),
|
||||
...(expand.length > 0 ? { expand: expand.join(",") } : {}),
|
||||
...(expand.length > 0 ? { expand: expand.join(", ") } : {}),
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -286,7 +286,7 @@ export class NginxProxyManagerAccess extends BaseAccess {
|
||||
try {
|
||||
code = authenticator.generate(this.totpSecret);
|
||||
} catch (error) {
|
||||
throw describeError(error, "Generating TOTP code");
|
||||
throw this.describeError(error, "Generating TOTP code");
|
||||
}
|
||||
|
||||
const completedLogin = await this.request<TokenResponse>({
|
||||
@@ -344,9 +344,9 @@ export class NginxProxyManagerAccess extends BaseAccess {
|
||||
rejectUnauthorized: false
|
||||
} : undefined,
|
||||
});
|
||||
return response.data;
|
||||
return response;
|
||||
} catch (error) {
|
||||
throw describeError(error, action);
|
||||
throw this.describeError(error, action);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-9
@@ -5,7 +5,7 @@ import {
|
||||
RunStrategy,
|
||||
TaskInput,
|
||||
} from "@certd/pipeline";
|
||||
import { CertInfo, CertReader } from "@certd/plugin-cert";
|
||||
import { CertInfo, CertReader, createCertDomainGetterInputDefine } from "@certd/plugin-cert";
|
||||
import { NginxProxyManagerAccess, ProxyHost } from "../access.js";
|
||||
|
||||
interface ProxyHostOption {
|
||||
@@ -38,13 +38,7 @@ export class NginxProxyManagerDeploy extends AbstractTaskPlugin {
|
||||
})
|
||||
cert!: CertInfo;
|
||||
|
||||
@TaskInput({
|
||||
title: "证书域名",
|
||||
component: {
|
||||
name: "cert-domains-getter",
|
||||
},
|
||||
required: false,
|
||||
})
|
||||
@TaskInput(createCertDomainGetterInputDefine())
|
||||
certDomains!: string[];
|
||||
|
||||
@TaskInput({
|
||||
@@ -297,7 +291,6 @@ export class NginxProxyManagerDeploy extends AbstractTaskPlugin {
|
||||
"dead_hosts",
|
||||
"streams",
|
||||
]);
|
||||
|
||||
const candidates = certificates.filter((certificate) => {
|
||||
return certificate.id !== currentCertificateId;
|
||||
});
|
||||
|
||||
@@ -124,6 +124,9 @@ export class TechnitiumAccess extends BaseAccess {
|
||||
this.ctx.logger.info(`获取域名列表,req:${JSON.stringify(req)}`);
|
||||
const pager = new Pager(req);
|
||||
|
||||
// 规范API地址
|
||||
this.apiUrl = this.normalizeEndpoint(this.apiUrl);
|
||||
|
||||
// 构建API URL
|
||||
const apiUrl = `${this.apiUrl}/api/zones/list`;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user