chore: 整理依赖

This commit is contained in:
xiaojunnuo
2024-11-06 01:17:36 +08:00
parent 77c9a7e2fa
commit 80f8fd49f1
70 changed files with 119 additions and 5990 deletions
+27
View File
@@ -0,0 +1,27 @@
# key: ./data/ssl/cert.key
# cert: ./data/ssl/cert.crt
#plus:
# server:
# baseUrl: 'http://127.0.0.1:11007'
typeorm:
dataSource:
default:
database: './data/db-new.sqlite'
plus:
server:
baseUrls: ['https://api.ai.handsfree.work', 'https://api.ai.docmirror.cn']
account:
server:
baseUrl: 'https://ai.handsfree.work/subject'
#plus:
# server:
# baseUrls: ['http://127.0.0.1:11007']
#
#account:
# server:
# baseUrl: 'http://127.0.0.1:1017/subject'
+23
View File
@@ -0,0 +1,23 @@
{
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint"
],
"extends": [
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended",
"prettier"
],
"env": {
"mocha": true
},
"rules": {
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/ban-ts-ignore": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-empty-function": "off",
// "no-unused-expressions": "off",
"max-len": [0, 160, 2, { "ignoreUrls": true }]
}
}
+5 -6
View File
@@ -11,7 +11,7 @@
"commpro": "cross-env NODE_ENV=commpro mwtsc --watch --run @midwayjs/mock/app",
"pgdev": "cross-env NODE_ENV=pgdev mwtsc --watch --run @midwayjs/mock/app",
"pgpl": "cross-env NODE_ENV=pgpl mwtsc --watch --run @midwayjs/mock/app",
"dev-new": "npm run rm-db-new && cross-env NODE_ENV=local mwtsc --watch --run @midwayjs/mock/app",
"dev-new": "cross-env NODE_ENV=devnew mwtsc --watch --run @midwayjs/mock/app",
"rm-db-new": "rimraf ./data/db-new.sqlite",
"test": "cross-env NODE_ENV=unittest mocha",
"cov": "cross-env c8 --all --reporter=text --reporter=lcovonly npm run test",
@@ -31,7 +31,6 @@
"@certd/basic": "^1.27.1",
"@certd/commercial-core": "^1.27.1",
"@certd/lib-huawei": "^1.27.1",
"@certd/lib-jdcloud": "^1.27.1",
"@certd/lib-k8s": "^1.27.1",
"@certd/lib-server": "^1.27.1",
"@certd/midway-flyway-js": "^1.27.1",
@@ -85,7 +84,7 @@
"qiniu": "^7.12.0",
"querystring": "^0.2.1",
"reflect-metadata": "^0.2.2",
"rimraf": "^6.0.1",
"rimraf": "^5.0.5",
"socks": "^2.8.3",
"socks-proxy-agent": "^8.0.4",
"ssh2": "^1.15.0",
@@ -108,10 +107,10 @@
"@types/ssh2": "^1.15.0",
"c8": "^10.1.2",
"mocha": "^10.2.0",
"prettier": "^3.3.3",
"prettier": "^2.8.8",
"rimraf": "^5.0.5",
"ts-node": "^10.9.2",
"typescript": "^5.4.2"
"typescript": "^5.4.2",
"tslib": "^2.8.1"
},
"engines": {
"node": ">=18.0.0"
@@ -7,11 +7,11 @@ export type CnameProvider = {
title: string;
};
export const CommonProviders = [
// {
// id: -1,
// domain: 'cname.certd.com.cn',
// title: '公共CNAME服务',
// },
{
id: -1,
domain: 'cname.certd.com.cn',
title: '公共CNAME服务',
},
];
export class CommonDnsProvider implements IDnsProvider {
@@ -29,6 +29,9 @@ export class CommonDnsProvider implements IDnsProvider {
if (!this.config.domain.endsWith(options.domain)) {
throw new Error('cname服务域名不匹配');
}
await this.plusService.register();
const res = await this.plusService.requestWithoutSign({
url: '/activation/certd/cname/recordCreate',
data: {
@@ -9,5 +9,4 @@ export * from './plugin-other/index.js';
export * from './plugin-west/index.js';
export * from './plugin-doge/index.js';
export * from './plugin-qiniu/index.js';
export * from './plugin-jdcloud/index.js';
export * from './plugin-woai/index.js';
@@ -1,28 +0,0 @@
import { AccessInput, BaseAccess, IsAccess } from '@certd/pipeline';
/**
* 这个注解将注册一个授权配置
* 在certd的后台管理系统中,用户可以选择添加此类型的授权
*/
@IsAccess({
name: 'dynadot',
title: 'dynadot授权',
desc: '************\n注意:申请证书时会覆盖已有的域名解析配置,慎用\n************\n待优化,主要是dynadot的接口一言难尽',
})
export class DynadotAccess extends BaseAccess {
/**
* 授权属性配置
*/
@AccessInput({
title: 'API Production Key',
component: {
placeholder: '授权key',
},
helper: '前往 [Dynadot API](https://www.dynadot.com/account/domain/setting/api.html) 获取 API Production Key',
required: true,
encrypt: true,
})
apiProductionKey = '';
}
new DynadotAccess();
@@ -1,96 +0,0 @@
import { AbstractDnsProvider, CreateRecordOptions, IsDnsProvider, RemoveRecordOptions } from '@certd/plugin-cert';
import { Autowire } from '@certd/pipeline';
import { ILogger } from '@certd/basic';
import { DynadotAccess } from './access.js';
import querystring from 'querystring';
// 这里通过IsDnsProvider注册一个dnsProvider
@IsDnsProvider({
name: 'dynadot',
title: 'dynadot',
desc: 'dynadot dns provider',
// 这里是对应的 cloudflare的access类型名称
accessType: 'dynadot',
deprecated: '暂不支持',
})
export class DynadotDnsProvider extends AbstractDnsProvider {
// 通过Autowire传递context
@Autowire()
logger!: ILogger;
access!: DynadotAccess;
async onInstance() {
this.access = this.ctx.access as DynadotAccess;
}
private async doRequest(command: string, query: any) {
const baseUrl = 'https://api.dynadot.com/api3.json?key=' + this.access.apiProductionKey;
const qs = querystring.stringify(query);
const url = `${baseUrl}&command=${command}&${qs}`;
const res = await this.ctx.http.request<any, any>({
url,
method: 'get',
headers: {
'Content-Type': 'application/json',
},
});
/*
"SetDnsResponse": {
"ResponseCode": 0,
"Status": "success"
}
*/
for (const resKey in res) {
if (res[resKey].ResponseCode != null && res[resKey].ResponseCode !== 0) {
throw new Error(`请求失败:${res[resKey].Status}`);
}
}
return res;
}
/**
* 创建dns解析记录,用于验证域名所有权
*/
async createRecord(options: CreateRecordOptions) {
/**
* fullRecord: '_acme-challenge.test.example.com',
* value: 一串uuid
* type: 'TXT',
* domain: 'example.com'
*/
const { fullRecord, value, type, domain } = options;
this.logger.info('添加域名解析:', fullRecord, value, type, domain);
//先获取域名原始解析记录
//https://api.dynadot.com/api3.xml?key=[API Key]&command=domain_info&domain=domain1.com
const res1 = await this.doRequest('domain_info', {
domain: domain,
});
// this.logger.info(`域名信息:${JSON.stringify(res1)}`);
// "DomainInfoResponse.NameServerSettings":{"Type":"Dynadot DNS","SubDomains":[{"Subhost":"_acme-challenge","RecordType":"TXT","Value":"43XrhFA6pJpE7a-20y7BmC6CsN20TMt5l-Zl-CL_-4I"}],"TTL":"300"}
this.logger.info('原始域名解析记录:', JSON.stringify(res1.DomainInfoResponse?.DomainInfo?.NameServerSettings));
const prefix = fullRecord.replace(`.${domain}`, '');
// 给domain下创建txt类型的dns解析记录,fullRecord
const res = await this.doRequest('set_dns2', {
domain: domain,
subdomain0: prefix,
sub_record_type0: 'TXT',
sub_record0: value,
});
this.logger.info(`添加域名解析成功:fullRecord=${fullRecord},value=${value}`);
this.logger.info(`请求结果:${JSON.stringify(res)}`);
//本接口需要返回本次创建的dns解析记录,这个记录会在删除的时候用到
return {};
}
/**
* 删除dns解析记录,清理申请痕迹
* @param options
*/
async removeRecord(options: RemoveRecordOptions<any>): Promise<void> {}
}
//实例化这个provider,将其自动注册到系统中
new DynadotDnsProvider();
@@ -1,3 +0,0 @@
export * from './dns-provider.js';
export * from './plugins/index.js';
export * from './access.js';
@@ -1,39 +0,0 @@
import { AccessInput, BaseAccess, IsAccess } from '@certd/pipeline';
/**
* 这个注解将注册一个授权配置
* 在certd的后台管理系统中,用户可以选择添加此类型的授权
*/
@IsAccess({
name: 'jdcloud',
title: '京东云授权',
desc: '暂时无法成功申请,还没测试通过',
})
export class JDCloudAccess extends BaseAccess {
/**
* 授权属性配置
*/
@AccessInput({
title: 'AccessKeyId',
component: {
placeholder: 'AK',
},
helper: '前往 [AccessKey管理](https://uc.jdcloud.com/account/accesskey) 获取 API Production Key',
required: true,
encrypt: true,
})
accessKeyId = '';
@AccessInput({
title: 'AccessKeySecret',
component: {
placeholder: 'SK',
},
helper: 'SK',
required: true,
encrypt: true,
})
accessKeySecret = '';
}
new JDCloudAccess();
@@ -1,125 +0,0 @@
import { AbstractDnsProvider, CreateRecordOptions, IsDnsProvider, RemoveRecordOptions } from '@certd/plugin-cert';
import { Autowire } from '@certd/pipeline';
import { ILogger } from '@certd/basic';
import { JDCloudAccess } from './access.js';
function promisfy(func: any) {
return (params: any, regionId: string) => {
return new Promise((resolve, reject) => {
try {
func(params, regionId, (err, result) => {
if (err) {
reject(err.error || err);
return;
}
resolve(result);
});
} catch (e) {
reject(e);
}
});
};
}
// 这里通过IsDnsProvider注册一个dnsProvider
@IsDnsProvider({
name: 'jdcloud',
title: '京东云',
desc: '京东云 dns provider',
// 这里是对应的 cloudflare的access类型名称
accessType: 'jdcloud',
deprecated: '暂不支持',
})
export class JDCloudDnsProvider extends AbstractDnsProvider {
// 通过Autowire传递context
@Autowire()
logger!: ILogger;
access!: JDCloudAccess;
service!: any;
regionId: string;
async onInstance() {
this.access = this.ctx.access as JDCloudAccess;
const { DomainService } = await import('@certd/lib-jdcloud');
// @ts-ignore
this.regionId = 'cn-north-1';
this.service = new DomainService({
credentials: {
accessKeyId: this.access.accessKeyId,
secretAccessKey: this.access.accessKeySecret,
},
regionId: this.regionId,
});
}
/**
* 创建dns解析记录,用于验证域名所有权
*/
async createRecord(options: CreateRecordOptions) {
/**
* fullRecord: '_acme-challenge.test.example.com',
* value: 一串uuid
* type: 'TXT',
* domain: 'example.com'
*/
const { fullRecord, value, type, domain } = options;
this.logger.info('添加域名解析:', fullRecord, value, type, domain);
const describeDomains = promisfy((a, b, c) => {
this.service.describeDomains(a, b, c);
});
const res: any = await describeDomains({ domainName: domain, pageNumber: 1, pageSize: 10 }, this.regionId);
this.logger.info('请求成功:', JSON.stringify(res.result));
const dataList = res.result.dataList;
if (dataList.length === 0) {
throw new Error('账号下找不到域名:' + domain);
}
const domainId = dataList[0].id;
this.logger.info('domainId:', domainId);
//开始创建解析记录
const createResourceRecord = promisfy((a, b, c) => {
this.service.createResourceRecord(a, b, c);
});
const res2: any = await createResourceRecord(
{
domainId,
req: {
hostRecord: fullRecord,
hostValue: value,
type: 'TXT',
},
},
this.regionId
);
this.logger.info('请求成功:', JSON.stringify(res.result));
const recordList = res2.result.dataList;
const recordId = recordList[0].id;
this.logger.info(`添加域名解析成功:fullRecord=${fullRecord},value=${value}`);
this.logger.info(`请求结果:recordId:${recordId}`);
//本接口需要返回本次创建的dns解析记录,这个记录会在删除的时候用到
return { id: recordId, domainId };
}
/**
* 删除dns解析记录,清理申请痕迹
* @param options
*/
async removeRecord(options: RemoveRecordOptions<any>): Promise<void> {
// const { fullRecord, value, domain } = options.recordReq;
const record = options.recordRes;
const deleteResourceRecord = promisfy(this.service.deleteResourceRecord);
const res: any = await deleteResourceRecord(
{
domainId: record.domainId,
resourceRecordId: record.id,
},
this.regionId
);
this.logger.info(`删除dns解析记录成功:${JSON.stringify(res)}`);
}
}
//实例化这个provider,将其自动注册到系统中
new JDCloudDnsProvider();
@@ -1,3 +0,0 @@
export * from './dns-provider.js';
export * from './plugins/index.js';
export * from './access.js';
+5 -1
View File
@@ -26,5 +26,9 @@
"dist",
"node_modules",
"test"
]
],
"include": [
"src/**/*.ts",
"node_modules/@certd/**/src/**/*.ts"
],
}