chore: format

This commit is contained in:
xiaojunnuo
2026-05-31 01:41:33 +08:00
parent acd440106b
commit 4b57a0d729
557 changed files with 12530 additions and 14039 deletions
@@ -43,14 +43,13 @@ export class AliesaAccess extends BaseAccess {
})
region = "";
@AccessInput({
@AccessInput({
title: "测试",
component: {
name: "api-test",
action: "TestRequest"
action: "TestRequest",
},
helper: "点击测试接口是否正常"
helper: "点击测试接口是否正常",
})
testRequest = true;
@@ -59,51 +58,50 @@ export class AliesaAccess extends BaseAccess {
pageNo: 1,
pageSize: 1,
});
return "ok"
return "ok";
}
async getEsaClient(){
const access: AliesaAccess = this
const aliAccess = await this.ctx.accessService.getById(access.accessId) as AliyunAccess
const endpoint = `esa.${access.region}.aliyuncs.com`
return aliAccess.getClient(endpoint)
async getEsaClient() {
const access: AliesaAccess = this;
const aliAccess = (await this.ctx.accessService.getById(access.accessId)) as AliyunAccess;
const endpoint = `esa.${access.region}.aliyuncs.com`;
return aliAccess.getClient(endpoint);
}
async getDomainListPage(req: PageSearch): Promise<PageRes<DomainRecord>> {
const pager = new Pager(req)
const client = await this.getEsaClient()
const ret = await client.doRequest({
// 接口名称
action: "ListSites",
// 接口版本
version: "2024-09-10",
// 接口协议
protocol: "HTTPS",
// 接口 HTTP 方法
method: "GET",
authType: "AK",
style: "RPC",
data: {
query: {
SiteName: req.searchKey,
// ["SiteSearchType"] = "exact";
SiteSearchType: "fuzzy",
AccessType: "NS",
PageSize: pager.pageSize,
PageNumber: pager.pageNo,
}
}
})
const list = ret.Sites?.map(item => ({
domain: item.SiteName,
id: item.SiteId,
}))
return {
list: list || [],
total: ret.TotalCount,
}
}
async getDomainListPage(req: PageSearch): Promise<PageRes<DomainRecord>> {
const pager = new Pager(req);
const client = await this.getEsaClient();
const ret = await client.doRequest({
// 接口名称
action: "ListSites",
// 接口版本
version: "2024-09-10",
// 接口协议
protocol: "HTTPS",
// 接口 HTTP 方法
method: "GET",
authType: "AK",
style: "RPC",
data: {
query: {
SiteName: req.searchKey,
// ["SiteSearchType"] = "exact";
SiteSearchType: "fuzzy",
AccessType: "NS",
PageSize: pager.pageSize,
PageNumber: pager.pageNo,
},
},
});
const list = ret.Sites?.map(item => ({
domain: item.SiteName,
id: item.SiteId,
}));
return {
list: list || [],
total: ret.TotalCount,
};
}
}
new AliesaAccess();
@@ -27,7 +27,7 @@ export class AliossAccess extends BaseAccess {
vModel: "value",
type: "access",
typeName: "alioss",
action: AliossAccess.prototype.onGetRegionList.name
action: AliossAccess.prototype.onGetRegionList.name,
},
required: true,
})
@@ -49,8 +49,7 @@ export class AliossAccess extends BaseAccess {
})
bucket!: string;
onGetRegionList(){
onGetRegionList() {
return {
list: [
{ value: "oss-cn-hangzhou", label: "华东1(杭州)" },
@@ -82,8 +81,8 @@ export class AliossAccess extends BaseAccess {
{ value: "oss-eu-west-1", label: "英国(伦敦)" },
{ value: "oss-me-east-1", label: "阿联酋(迪拜)①" },
{ value: "oss-rg-china-mainland", label: "无地域属性(中国内地)" },
]
}
],
};
}
async onGetBucketList() {
@@ -14,7 +14,7 @@ function createAccess(result: Record<string, unknown>) {
access.getStsClient = async () =>
({
getCallerIdentity: async () => result,
}) as any;
} as any);
return access;
}
@@ -33,9 +33,9 @@ export class AliyunAccess extends BaseAccess {
title: "测试",
component: {
name: "api-test",
action: "TestRequest"
action: "TestRequest",
},
helper: "点击测试接口是否正常"
helper: "点击测试接口是否正常",
})
testRequest = true;
@@ -44,23 +44,20 @@ export class AliyunAccess extends BaseAccess {
return "ok";
}
async getStsClient() {
const StsClient = await import('@alicloud/sts-sdk');
const StsClient = await import("@alicloud/sts-sdk");
// 配置凭证
const sts = new StsClient.default({
endpoint: 'sts.aliyuncs.com',
endpoint: "sts.aliyuncs.com",
accessKeyId: this.accessKeyId,
accessKeySecret: this.accessKeySecret,
});
return sts
return sts;
}
async getCallerIdentity() {
const sts = await this.getStsClient();
// 调用 GetCallerIdentity 接口
const result = await sts.getCallerIdentity();
@@ -79,22 +76,19 @@ export class AliyunAccess extends BaseAccess {
valid: true,
accountId: result.AccountId,
arn: result.Arn,
userId: result.UserId
userId: result.UserId,
};
}
getSslClient({ endpoint }: { endpoint: string }) {
const client = new AliyunSslClient({
access: this,
logger: this.ctx.logger,
endpoint,
});
return client
return client;
}
getClient(endpoint: string) {
return new AliyunClientV2({
access: this,
@@ -1,3 +1,3 @@
export * from "./access/index.js";
export * from "./lib/index.js";
export * from "./utils/index.js";
export * from "./utils/index.js";
@@ -38,7 +38,7 @@ export type CasCertId = {
certIdentifier: string;
certName: string;
detail?: SimpleCertDetail;
}
};
export class AliyunSslClient {
opts: AliyunSslClientOpts;
logger: ILogger;
@@ -100,10 +100,10 @@ export class AliyunSslClient {
}
async uploadCert(req: AliyunSslUploadCertReq) {
const {certId} = await this.uploadCertificate(req);
return certId;
const { certId } = await this.uploadCertificate(req);
return certId;
}
async uploadCertificate(req: AliyunSslUploadCertReq) : Promise<CasCertId> {
async uploadCertificate(req: AliyunSslUploadCertReq): Promise<CasCertId> {
const client = await this.getClient();
const params = {
Name: req.name,
@@ -125,13 +125,12 @@ export class AliyunSslClient {
certId: ret.CertId,
certName: req.name,
certIdentifier: this.getCertIdentifier(ret.CertId),
detail:certReader.getSimpleDetail(),
}
detail: certReader.getSimpleDetail(),
};
}
async uploadCertOrGet(cert: CertInfo | number | CasCertId ) :Promise<CasCertId>{
async uploadCertOrGet(cert: CertInfo | number | CasCertId): Promise<CasCertId> {
if (typeof cert === "object") {
const casCert = cert as CasCertId;
if (casCert.certId) {
return casCert;
@@ -143,20 +142,20 @@ export class AliyunSslClient {
const certName = certReader.buildCertName();
const res = await this.uploadCertificate({
name: certName,
cert: certInfo
cert: certInfo,
});
this.logger.info("上传证书成功", JSON.stringify(res));
return res
return res;
}
//number类型
const certId = cert as any;
let certName: any = utils.string.appendTimeSuffix(certId);
const certName: any = utils.string.appendTimeSuffix(certId);
const certIdentifier = this.getCertIdentifier(certId);
return {
certId,
certIdentifier,
certName,
}
};
}
async getResourceList(req: AliyunSslGetResourceListReq) {
@@ -237,18 +236,18 @@ export class AliyunSslClient {
return region;
}
getCertDomains(cert: CertInfo | number | CasCertId): string[]{
const casCert = cert as CasCertId;
const certInfo = cert as CertInfo;
if (casCert.certId) {
if (!casCert.detail){
throw new Error('未获取到证书域名列表,请尝试强制重新运行一下流水线');
}
return casCert.detail?.domains || [];
}else if (certInfo.crt){
return new CertReader(certInfo).getSimpleDetail().domains || [];
}else{
throw new Error('未获取到证书域名列表,请尝试强制重新运行一下流水线');
getCertDomains(cert: CertInfo | number | CasCertId): string[] {
const casCert = cert as CasCertId;
const certInfo = cert as CertInfo;
if (casCert.certId) {
if (!casCert.detail) {
throw new Error("未获取到证书域名列表,请尝试强制重新运行一下流水线");
}
return casCert.detail?.domains || [];
} else if (certInfo.crt) {
return new CertReader(certInfo).getSimpleDetail().domains || [];
} else {
throw new Error("未获取到证书域名列表,请尝试强制重新运行一下流水线");
}
}
}
@@ -2,31 +2,27 @@ import dayjs from "dayjs";
import { CertInfo, CertReader } from "@certd/plugin-cert";
import { AliyunSslClient } from "../lib/index.js";
export const ZoneOptions = [{ value: 'cn-hangzhou' }];
export const ZoneOptions = [{ value: "cn-hangzhou" }];
export function appendTimeSuffix(name: string) {
if (name == null) {
name = 'certd';
name = "certd";
}
return name + '-' + dayjs().format('YYYYMMDD-HHmmss');
return name + "-" + dayjs().format("YYYYMMDD-HHmmss");
}
export function checkRet(ret: any) {
if (ret.Code != null) {
throw new Error('执行失败:' + ret.Message);
throw new Error("执行失败:" + ret.Message);
}
}
export async function getAliyunCertId(opts:{
cert: string | CertInfo,
sslClient: AliyunSslClient,
}) {
export async function getAliyunCertId(opts: { cert: string | CertInfo; sslClient: AliyunSslClient }) {
const { cert, sslClient } = opts;
let certId: any = cert;
let certName: any = CertReader.appendTimeSuffix("certd");
if (typeof cert === "object") {
const certReader = new CertReader(cert)
certName = certReader.buildCertName()
const certReader = new CertReader(cert);
certName = certReader.buildCertName();
certId = await sslClient.uploadCert({
name: certName,
@@ -34,7 +34,7 @@ export type OssClientContext = {
};
export abstract class BaseOssClient<A> implements IOssClient {
rootDir: string = "";
rootDir = "";
access: A = null;
logger: ILogger;
utils: typeof utils;
@@ -2,6 +2,6 @@ import SftpOssClientImpl from "./sftp.js";
export default class ScpOssClientImpl extends SftpOssClientImpl {
getUploaderType() {
return 'scp';
return "scp";
}
}
@@ -6,7 +6,7 @@ import { SftpAccess, SshAccess, SshClient } from "../../ssh/index.js";
export default class SftpOssClientImpl extends BaseOssClient<SftpAccess> {
getUploaderType() {
return 'sftp';
return "sftp";
}
async download(fileName: string, savePath: string): Promise<void> {
const path = this.join(this.rootDir, fileName);
@@ -23,7 +23,7 @@ export class QiniuAccess extends BaseAccess {
})
secretKey!: string;
@AccessInput({
@AccessInput({
title: "测试",
component: {
name: "api-test",
@@ -38,18 +38,16 @@ export class QiniuAccess extends BaseAccess {
return "ok";
}
async getDomainList(req: PageSearch = {}) {
const qiniuClient = new QiniuClient({
http: this.ctx.http,
access:this,
logger: this.ctx.logger,
});
const url = `https://api.qiniu.com/domain?limit=${req.pageSize || 1000}`;
const res = await qiniuClient.doRequest(url, 'get');
return res.domains||[]
}
const qiniuClient = new QiniuClient({
http: this.ctx.http,
access: this,
logger: this.ctx.logger,
});
const url = `https://api.qiniu.com/domain?limit=${req.pageSize || 1000}`;
const res = await qiniuClient.doRequest(url, "get");
return res.domains || [];
}
}
new QiniuAccess();
@@ -55,10 +55,8 @@ export class TencentAccess extends BaseAccess {
vModel: "checked",
},
})
closeExpiresNotify: boolean = true;
closeExpiresNotify = true;
@AccessInput({
title: "测试",
component: {
@@ -74,7 +72,6 @@ export class TencentAccess extends BaseAccess {
return "ok";
}
isIntl() {
return this.accountType === "intl";
}
@@ -87,28 +84,27 @@ export class TencentAccess extends BaseAccess {
return `${this.intlDomain()}${endpoint}`;
}
async getCallerIdentity(){
async getCallerIdentity() {
const client = await this.getStsClient();
// 调用 GetCallerIdentity 接口
// 调用 GetCallerIdentity 接口
const result = await client.GetCallerIdentity();
this.ctx.logger.info("✅ 密钥有效!");
this.ctx.logger.info(` 账户ID: ${result.AccountId}`);
this.ctx.logger.info(` ARN: ${result.Arn}`);
this.ctx.logger.info(` 用户ID: ${result.UserId}`);
return {
valid: true,
accountId: result.AccountId,
arn: result.Arn,
userId: result.UserId
userId: result.UserId,
};
}
async getStsClient(){
const sdk = await import('tencentcloud-sdk-nodejs/tencentcloud/services/sts/v20180813/index.js');
async getStsClient() {
const sdk = await import("tencentcloud-sdk-nodejs/tencentcloud/services/sts/v20180813/index.js");
const StsClient = sdk.v20180813.Client;
const clientConfig = {
@@ -116,7 +112,7 @@ export class TencentAccess extends BaseAccess {
secretId: this.secretId,
secretKey: this.secretKey,
},
region: 'ap-shanghai',
region: "ap-shanghai",
profile: {
httpProfile: {
endpoint: `sts.${this.intlDomain()}tencentcloudapi.com`,