mirror of https://github.com/certd/certd
chore:
parent
469a088a4d
commit
faac4dfc30
|
@ -2,4 +2,3 @@ export * from './api/index.js'
|
||||||
export * from './entity/addon.js'
|
export * from './entity/addon.js'
|
||||||
export * from './service/addon-service.js'
|
export * from './service/addon-service.js'
|
||||||
export * from './service/addon-getter.js'
|
export * from './service/addon-getter.js'
|
||||||
export * from './service/addon-sys-getter.js'
|
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
import { IAddonGetter } from "../api/index.js";
|
|
||||||
|
|
||||||
export class AddonGetter implements IAddonGetter {
|
|
||||||
userId: number;
|
|
||||||
getter: <T>(id: any, userId?: number) => Promise<T>;
|
|
||||||
constructor(userId: number, getter: (id: any, userId: number) => Promise<any>) {
|
|
||||||
this.userId = userId;
|
|
||||||
this.getter = getter;
|
|
||||||
}
|
|
||||||
|
|
||||||
async getById<T = any>(id: any) {
|
|
||||||
return await this.getter<T>(id, this.userId);
|
|
||||||
}
|
|
||||||
|
|
||||||
async getCommonById<T = any>(id: any) {
|
|
||||||
return await this.getter<T>(id, 0);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,17 +0,0 @@
|
||||||
import { IAccessService } from '@certd/pipeline';
|
|
||||||
import { AddonService } from './addon-service.js';
|
|
||||||
|
|
||||||
export class AddonSysGetter implements IAccessService {
|
|
||||||
addonService: AddonService;
|
|
||||||
constructor(addonService: AddonService) {
|
|
||||||
this.addonService = addonService;
|
|
||||||
}
|
|
||||||
|
|
||||||
async getById<T = any>(id: any) {
|
|
||||||
return await this.addonService.getById(id, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
async getCommonById<T = any>(id: any) {
|
|
||||||
return await this.addonService.getById(id, 0);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -13,42 +13,45 @@ export class CaptchaService {
|
||||||
addonGetterService: AddonGetterService;
|
addonGetterService: AddonGetterService;
|
||||||
|
|
||||||
|
|
||||||
async getCaptcha(captchaAddonId?:number){
|
async getCaptcha(captchaAddonId?: number) {
|
||||||
if (!captchaAddonId) {
|
if (!captchaAddonId) {
|
||||||
const settings = await this.sysSettingsService.getPublicSettings()
|
const settings = await this.sysSettingsService.getPublicSettings();
|
||||||
captchaAddonId = settings.captchaAddonId ?? 0
|
captchaAddonId = settings.captchaAddonId ?? 0;
|
||||||
}
|
}
|
||||||
const addon:ICaptchaAddon = await this.addonGetterService.getAddonById(captchaAddonId,true,0)
|
const addon: ICaptchaAddon = await this.addonGetterService.getAddonById(captchaAddonId, true, 0, {
|
||||||
|
type: "captcha",
|
||||||
|
name: "image"
|
||||||
|
});
|
||||||
if (!addon) {
|
if (!addon) {
|
||||||
throw new Error('验证码插件还未配置')
|
throw new Error("验证码插件还未配置");
|
||||||
}
|
}
|
||||||
return await addon.getCaptcha()
|
return await addon.getCaptcha();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async doValidate(opts:{form:any,must?:boolean,captchaAddonId?:number}){
|
async doValidate(opts: { form: any, must?: boolean, captchaAddonId?: number }) {
|
||||||
if (!opts.captchaAddonId) {
|
if (!opts.captchaAddonId) {
|
||||||
const settings = await this.sysSettingsService.getPublicSettings()
|
const settings = await this.sysSettingsService.getPublicSettings();
|
||||||
opts.captchaAddonId = settings.captchaAddonId ?? 0
|
opts.captchaAddonId = settings.captchaAddonId ?? 0;
|
||||||
}
|
}
|
||||||
const addon = await this.addonGetterService.getById(opts.captchaAddonId,0)
|
const addon = await this.addonGetterService.getById(opts.captchaAddonId, 0);
|
||||||
if (!addon) {
|
if (!addon) {
|
||||||
if (opts.must) {
|
if (opts.must) {
|
||||||
throw new Error('请先配置验证码插件');
|
throw new Error("请先配置验证码插件");
|
||||||
}
|
}
|
||||||
logger.warn('验证码插件还未配置,忽略验证码校验')
|
logger.warn("验证码插件还未配置,忽略验证码校验");
|
||||||
return true
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!opts.form) {
|
if (!opts.form) {
|
||||||
throw new Error('请输入验证码');
|
throw new Error("请输入验证码");
|
||||||
}
|
}
|
||||||
const res = await addon.onValidate(opts.form)
|
const res = await addon.onValidate(opts.form);
|
||||||
if (!res) {
|
if (!res) {
|
||||||
throw new Error('验证码错误');
|
throw new Error("验证码错误");
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ export class AddonGetterService {
|
||||||
addonService: AddonService;
|
addonService: AddonService;
|
||||||
|
|
||||||
|
|
||||||
async getAddonById(id: any, checkUserId: boolean, userId?: number): Promise<any> {
|
async getAddonById(id: any, checkUserId: boolean, userId?: number, defaultAddon?:{type:string,name:string} ): Promise<any> {
|
||||||
const serviceGetter = this.taskServiceBuilder.create({
|
const serviceGetter = this.taskServiceBuilder.create({
|
||||||
userId
|
userId
|
||||||
});
|
});
|
||||||
|
@ -28,13 +28,17 @@ export class AddonGetterService {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!id) {
|
if (!id) {
|
||||||
//使用图片验证码
|
if (!defaultAddon) {
|
||||||
return await newAddon("captcha", "image", {}, ctx);
|
return null;
|
||||||
|
}
|
||||||
|
return await newAddon(defaultAddon.type, defaultAddon.name, {}, ctx);
|
||||||
}
|
}
|
||||||
const entity = await this.addonService.info(id);
|
const entity = await this.addonService.info(id);
|
||||||
if (entity == null) {
|
if (entity == null) {
|
||||||
//使用图片验证码
|
if (!defaultAddon) {
|
||||||
return await newAddon("captcha", "image", {}, ctx);
|
return null;
|
||||||
|
}
|
||||||
|
return await newAddon(defaultAddon.type, defaultAddon.name, {}, ctx);
|
||||||
}
|
}
|
||||||
if (checkUserId) {
|
if (checkUserId) {
|
||||||
if (userId == null) {
|
if (userId == null) {
|
||||||
|
|
|
@ -32,7 +32,7 @@ export class TaskServiceGetter implements IServiceGetter{
|
||||||
return await this.getNotificationService() as T
|
return await this.getNotificationService() as T
|
||||||
} else if (serviceName === 'domainVerifierGetter') {
|
} else if (serviceName === 'domainVerifierGetter') {
|
||||||
return await this.getDomainVerifierGetter() as T
|
return await this.getDomainVerifierGetter() as T
|
||||||
} else{
|
}else{
|
||||||
if(!serviceNames.includes(serviceName)){
|
if(!serviceNames.includes(serviceName)){
|
||||||
throw new Error(`${serviceName} not in whitelist`)
|
throw new Error(`${serviceName} not in whitelist`)
|
||||||
}
|
}
|
||||||
|
@ -53,6 +53,7 @@ export class TaskServiceGetter implements IServiceGetter{
|
||||||
return new AccessGetter(this.userId, accessService.getById.bind(accessService));
|
return new AccessGetter(this.userId, accessService.getById.bind(accessService));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async getCnameProxyService(): Promise<CnameProxyService> {
|
async getCnameProxyService(): Promise<CnameProxyService> {
|
||||||
const cnameRecordService:CnameRecordService = await this.appCtx.getAsync("cnameRecordService")
|
const cnameRecordService:CnameRecordService = await this.appCtx.getAsync("cnameRecordService")
|
||||||
return new CnameProxyService(this.userId, cnameRecordService.getWithAccessByDomain.bind(cnameRecordService));
|
return new CnameProxyService(this.userId, cnameRecordService.getWithAccessByDomain.bind(cnameRecordService));
|
||||||
|
|
Loading…
Reference in New Issue