mirror of
https://github.com/certd/certd.git
synced 2026-04-24 04:17:25 +08:00
feat: 升级midway,支持esm
This commit is contained in:
@@ -6,9 +6,9 @@ import {
|
||||
Post,
|
||||
Provide,
|
||||
Query,
|
||||
} from '@midwayjs/decorator';
|
||||
import { CrudController } from '../../../basic/crud-controller';
|
||||
import { PermissionService } from '../service/permission-service';
|
||||
} from '@midwayjs/core';
|
||||
import { CrudController } from '../../../basic/crud-controller.js';
|
||||
import { PermissionService } from '../service/permission-service.js';
|
||||
|
||||
/**
|
||||
* 权限资源
|
||||
|
||||
@@ -6,9 +6,9 @@ import {
|
||||
Post,
|
||||
Provide,
|
||||
Query,
|
||||
} from '@midwayjs/decorator';
|
||||
import { CrudController } from '../../../basic/crud-controller';
|
||||
import { RoleService } from '../service/role-service';
|
||||
} from '@midwayjs/core';
|
||||
import { CrudController } from '../../../basic/crud-controller.js';
|
||||
import { RoleService } from '../service/role-service.js';
|
||||
|
||||
/**
|
||||
* 系统用户
|
||||
|
||||
@@ -6,12 +6,12 @@ import {
|
||||
Body,
|
||||
Query,
|
||||
ALL,
|
||||
} from '@midwayjs/decorator';
|
||||
import { UserService } from '../service/user-service';
|
||||
import { CrudController } from '../../../basic/crud-controller';
|
||||
import { RoleService } from '../service/role-service';
|
||||
import { PermissionService } from '../service/permission-service';
|
||||
import { Constants } from '../../../basic/constants';
|
||||
} from '@midwayjs/core';
|
||||
import { UserService } from '../service/user-service.js';
|
||||
import { CrudController } from '../../../basic/crud-controller.js';
|
||||
import { RoleService } from '../service/role-service.js';
|
||||
import { PermissionService } from '../service/permission-service.js';
|
||||
import { Constants } from '../../../basic/constants.js';
|
||||
|
||||
/**
|
||||
* 系统用户
|
||||
|
||||
@@ -14,6 +14,9 @@ export class UserEntity {
|
||||
@Column({ comment: '密码', length: 100 })
|
||||
password: string;
|
||||
|
||||
@Column({ name: 'password_version', comment: '密码版本' })
|
||||
passwordVersion: number;
|
||||
|
||||
@Column({ name: 'nick_name', comment: '昵称', length: 100, nullable: true })
|
||||
nickName: string;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { EnumItem } from '../../../basic/enum-item';
|
||||
import * as _ from 'lodash';
|
||||
import { EnumItem } from '../../../basic/enum-item.js';
|
||||
import * as _ from 'lodash-es';
|
||||
class ResourceTypes {
|
||||
MENU = new EnumItem('menu', '菜单', 'blue');
|
||||
BTN = new EnumItem('btn', '按钮', 'green');
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Provide, Scope, ScopeEnum } from '@midwayjs/decorator';
|
||||
import { Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
||||
import { InjectEntityModel } from '@midwayjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { BaseService } from '../../../basic/base-service';
|
||||
import { PermissionEntity } from '../entity/permission';
|
||||
import { BaseService } from '../../../basic/base-service.js';
|
||||
import { PermissionEntity } from '../entity/permission.js';
|
||||
|
||||
/**
|
||||
* 权限资源
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Provide, Scope, ScopeEnum } from '@midwayjs/decorator';
|
||||
import { Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
||||
import { InjectEntityModel } from '@midwayjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { BaseService } from '../../../basic/base-service';
|
||||
import { RolePermissionEntity } from '../entity/role-permission';
|
||||
import { BaseService } from '../../../basic/base-service.js';
|
||||
import { RolePermissionEntity } from '../entity/role-permission.js';
|
||||
|
||||
/**
|
||||
* 角色->权限
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { Inject, Provide, Scope, ScopeEnum } from '@midwayjs/decorator';
|
||||
import { Inject, Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
||||
import { InjectEntityModel } from '@midwayjs/typeorm';
|
||||
import { In, Repository } from 'typeorm';
|
||||
import { BaseService } from '../../../basic/base-service';
|
||||
import { RoleEntity } from '../entity/role';
|
||||
import { UserRoleService } from './user-role-service';
|
||||
import { RolePermissionEntity } from '../entity/role-permission';
|
||||
import { PermissionService } from './permission-service';
|
||||
import * as _ from 'lodash';
|
||||
import { RolePermissionService } from './role-permission-service';
|
||||
import { BaseService } from '../../../basic/base-service.js';
|
||||
import { RoleEntity } from '../entity/role.js';
|
||||
import { UserRoleService } from './user-role-service.js';
|
||||
import { RolePermissionEntity } from '../entity/role-permission.js';
|
||||
import { PermissionService } from './permission-service.js';
|
||||
import * as _ from 'lodash-es';
|
||||
import { RolePermissionService } from './role-permission-service.js';
|
||||
import { LRUCache } from 'lru-cache';
|
||||
/**
|
||||
* 角色
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Provide, Scope, ScopeEnum } from '@midwayjs/decorator';
|
||||
import { Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
||||
import { InjectEntityModel } from '@midwayjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { BaseService } from '../../../basic/base-service';
|
||||
import { UserRoleEntity } from '../entity/user-role';
|
||||
import { BaseService } from '../../../basic/base-service.js';
|
||||
import { UserRoleEntity } from '../entity/user-role.js';
|
||||
|
||||
/**
|
||||
* 用户->角色
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
import { Inject, Provide, Scope, ScopeEnum } from '@midwayjs/decorator';
|
||||
import { Inject, Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
||||
import { InjectEntityModel } from '@midwayjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { UserEntity } from '../entity/user';
|
||||
import * as _ from 'lodash';
|
||||
import { UserEntity } from '../entity/user.js';
|
||||
import * as _ from 'lodash-es';
|
||||
import md5 from 'md5';
|
||||
import { CommonException } from '../../../basic/exception/common-exception';
|
||||
import { BaseService } from '../../../basic/base-service';
|
||||
import { RoleService } from './role-service';
|
||||
import { PermissionService } from './permission-service';
|
||||
import { UserRoleService } from './user-role-service';
|
||||
import { Constants } from '../../../basic/constants';
|
||||
import { UserRoleEntity } from '../entity/user-role';
|
||||
import { CommonException } from '../../../basic/exception/common-exception.js';
|
||||
import { BaseService } from '../../../basic/base-service.js';
|
||||
import { RoleService } from './role-service.js';
|
||||
import { PermissionService } from './permission-service.js';
|
||||
import { UserRoleService } from './user-role-service.js';
|
||||
import { Constants } from '../../../basic/constants.js';
|
||||
import { UserRoleEntity } from '../entity/user-role.js';
|
||||
import { randomText } from 'svg-captcha';
|
||||
import bcrypt from 'bcryptjs';
|
||||
|
||||
/**
|
||||
* 系统用户
|
||||
@@ -58,8 +59,9 @@ export class UserService extends BaseService<UserEntity> {
|
||||
if (!_.isEmpty(exists)) {
|
||||
throw new CommonException('用户名已经存在');
|
||||
}
|
||||
const password = param.password ?? randomText(6);
|
||||
param.password = md5(password); // 默认密码 建议未改密码不能登陆
|
||||
const plainPassword = param.password ?? randomText(6);
|
||||
param.passwordVersion = 2;
|
||||
param.password = this.genPassword(plainPassword, param.passwordVersion); // 默认密码 建议未改密码不能登陆
|
||||
await super.add(param);
|
||||
//添加角色
|
||||
if (param.roles && param.roles.length > 0) {
|
||||
@@ -85,7 +87,8 @@ export class UserService extends BaseService<UserEntity> {
|
||||
|
||||
delete param.username;
|
||||
if (!_.isEmpty(param.password)) {
|
||||
param.password = md5(param.password);
|
||||
param.passwordVersion = 2;
|
||||
param.password = this.genPassword(param.password, param.passwordVersion);
|
||||
} else {
|
||||
delete param.password;
|
||||
}
|
||||
@@ -93,15 +96,30 @@ export class UserService extends BaseService<UserEntity> {
|
||||
await this.roleService.updateRoles(param.id, param.roles);
|
||||
}
|
||||
|
||||
private genPassword(plainPassword: any, passwordVersion: number) {
|
||||
if (passwordVersion == null || passwordVersion <= 1) {
|
||||
return md5(plainPassword);
|
||||
}
|
||||
const salt = bcrypt.genSaltSync(10);
|
||||
return bcrypt.hashSync(plainPassword, salt);
|
||||
}
|
||||
|
||||
async findOne(param) {
|
||||
return this.repository.findOne({
|
||||
where: param,
|
||||
});
|
||||
}
|
||||
|
||||
checkPassword(rawPassword: any, md5Password: any) {
|
||||
// logger.info('md5', md5('123456'));
|
||||
return md5(rawPassword) === md5Password;
|
||||
async checkPassword(
|
||||
rawPassword: any,
|
||||
hashPassword: any,
|
||||
passwordVersion: number
|
||||
) {
|
||||
if (passwordVersion == null || passwordVersion <= 1) {
|
||||
return this.genPassword(rawPassword, passwordVersion) === hashPassword;
|
||||
}
|
||||
|
||||
return bcrypt.compareSync(rawPassword, hashPassword); // true
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,8 +145,12 @@ export class UserService extends BaseService<UserEntity> {
|
||||
mobile: user.mobile || '',
|
||||
phoneCode: user.phoneCode || '',
|
||||
status: 1,
|
||||
passwordVersion: 2,
|
||||
});
|
||||
newUser.password = md5(newUser.password);
|
||||
newUser.password = this.genPassword(
|
||||
newUser.password,
|
||||
newUser.passwordVersion
|
||||
);
|
||||
|
||||
await this.transaction(async txManager => {
|
||||
newUser = await txManager.save(newUser);
|
||||
@@ -145,7 +167,12 @@ export class UserService extends BaseService<UserEntity> {
|
||||
|
||||
async changePassword(userId: any, form: any) {
|
||||
const user = await this.info(userId);
|
||||
if (!this.checkPassword(form.password, user.password)) {
|
||||
const passwordChecked = await this.checkPassword(
|
||||
form.password,
|
||||
user.password,
|
||||
user.passwordVersion
|
||||
);
|
||||
if (!passwordChecked) {
|
||||
throw new CommonException('原密码错误');
|
||||
}
|
||||
const param = {
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import { Autoload, Init, Inject, Scope, ScopeEnum } from '@midwayjs/core';
|
||||
import { logger } from '../../utils/logger.js';
|
||||
import { UserService } from '../authority/service/user-service.js';
|
||||
import { SysSettingsService } from '../system/service/sys-settings-service.js';
|
||||
import { nanoid } from 'nanoid';
|
||||
import { SysInstallInfo } from '../system/service/models.js';
|
||||
|
||||
export type InstallInfo = {
|
||||
installTime: number;
|
||||
instanceId?: string;
|
||||
};
|
||||
|
||||
@Autoload()
|
||||
@Scope(ScopeEnum.Singleton)
|
||||
export class AutoInitSite {
|
||||
@Inject()
|
||||
userService: UserService;
|
||||
|
||||
@Inject()
|
||||
sysSettingsService: SysSettingsService;
|
||||
|
||||
@Init()
|
||||
async init() {
|
||||
logger.info('初始化站点开始');
|
||||
const installInfo: SysInstallInfo = await this.sysSettingsService.getSetting(SysInstallInfo);
|
||||
if (!installInfo.siteId) {
|
||||
installInfo.siteId = nanoid();
|
||||
await this.sysSettingsService.saveSetting(installInfo);
|
||||
}
|
||||
if (!installInfo.siteId) {
|
||||
installInfo.siteId = nanoid();
|
||||
await this.sysSettingsService.saveSetting(installInfo);
|
||||
}
|
||||
|
||||
logger.info('初始化站点完成');
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
import { Rule, RuleType } from '@midwayjs/validate';
|
||||
import { ALL, Inject } from '@midwayjs/decorator';
|
||||
import { Body } from '@midwayjs/decorator';
|
||||
import { Controller, Post, Provide } from '@midwayjs/decorator';
|
||||
import { BaseController } from '../../../basic/base-controller';
|
||||
import { CodeService } from '../service/code-service';
|
||||
import { EmailService } from '../service/email-service';
|
||||
import { Constants } from '../../../basic/constants';
|
||||
import { ALL, Inject } from '@midwayjs/core';
|
||||
import { Body } from '@midwayjs/core';
|
||||
import { Controller, Post, Provide } from '@midwayjs/core';
|
||||
import { BaseController } from '../../../basic/base-controller.js';
|
||||
import { CodeService } from '../service/code-service.js';
|
||||
import { EmailService } from '../service/email-service.js';
|
||||
import { Constants } from '../../../basic/constants.js';
|
||||
export class SmsCodeReq {
|
||||
@Rule(RuleType.number().required())
|
||||
phoneCode: number;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Body, Controller, Inject, Post, Provide } from '@midwayjs/decorator';
|
||||
import { BaseController } from '../../../basic/base-controller';
|
||||
import { EmailService } from '../service/email-service';
|
||||
import { Constants } from '../../../basic/constants';
|
||||
import { Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
|
||||
import { BaseController } from '../../../basic/base-controller.js';
|
||||
import { EmailService } from '../service/email-service.js';
|
||||
import { Constants } from '../../../basic/constants.js';
|
||||
|
||||
/**
|
||||
*/
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { Rule, RuleType } from '@midwayjs/validate';
|
||||
import { Controller, Get, Inject, Provide } from '@midwayjs/decorator';
|
||||
import { BaseController } from '../../../basic/base-controller';
|
||||
import { Constants } from '../../../basic/constants';
|
||||
import { SysSettingsService } from '../../system/service/sys-settings-service';
|
||||
import { Controller, Get, Inject, Provide } from '@midwayjs/core';
|
||||
import { BaseController } from '../../../basic/base-controller.js';
|
||||
import { Constants } from '../../../basic/constants.js';
|
||||
import { SysSettingsService } from '../../system/service/sys-settings-service.js';
|
||||
import { SysPublicSettings } from '../../system/service/models.js';
|
||||
|
||||
export class SmsCodeReq {
|
||||
@Rule(RuleType.number().required())
|
||||
@@ -28,7 +29,9 @@ export class BasicSettingsController extends BaseController {
|
||||
|
||||
@Get('/public', { summary: Constants.per.guest })
|
||||
public async getSysPublic() {
|
||||
const settings = await this.sysSettingsService.readPublicSettings();
|
||||
const settings = await this.sysSettingsService.getSetting(
|
||||
SysPublicSettings
|
||||
);
|
||||
return this.ok(settings);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Inject, Provide } from '@midwayjs/decorator';
|
||||
import { Inject, Provide } from '@midwayjs/core';
|
||||
import { CacheManager } from '@midwayjs/cache';
|
||||
const svgCaptcha = require('svg-captcha');
|
||||
import svgCaptcha from 'svg-captcha';
|
||||
|
||||
// {data: '<svg.../svg>', text: 'abcd'}
|
||||
/**
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { Inject, Provide, Scope, ScopeEnum } from '@midwayjs/decorator';
|
||||
import { Inject, Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
||||
import type { EmailSend } from '@certd/pipeline';
|
||||
import { IEmailService } from '@certd/pipeline';
|
||||
import nodemailer from 'nodemailer';
|
||||
import type SMTPConnection from 'nodemailer/lib/smtp-connection';
|
||||
import { logger } from '../../../utils/logger';
|
||||
import { UserSettingsService } from '../../mine/service/user-settings-service';
|
||||
import { logger } from '../../../utils/logger.js';
|
||||
import { UserSettingsService } from '../../mine/service/user-settings-service.js';
|
||||
|
||||
export type EmailConfig = {
|
||||
host: string;
|
||||
|
||||
@@ -5,10 +5,10 @@ import {
|
||||
Post,
|
||||
Provide,
|
||||
ALL,
|
||||
} from '@midwayjs/decorator';
|
||||
import { LoginService } from '../service/login-service';
|
||||
import { BaseController } from '../../../basic/base-controller';
|
||||
import { Constants } from '../../../basic/constants';
|
||||
} from '@midwayjs/core';
|
||||
import { LoginService } from '../service/login-service.js';
|
||||
import { BaseController } from '../../../basic/base-controller.js';
|
||||
import { Constants } from '../../../basic/constants.js';
|
||||
|
||||
/**
|
||||
*/
|
||||
|
||||
@@ -5,12 +5,12 @@ import {
|
||||
Inject,
|
||||
Post,
|
||||
Provide,
|
||||
} from '@midwayjs/decorator';
|
||||
import { BaseController } from '../../../basic/base-controller';
|
||||
import { Constants } from '../../../basic/constants';
|
||||
import { UserService } from '../../authority/service/user-service';
|
||||
import { UserEntity } from '../../authority/entity/user';
|
||||
import { SysSettingsService } from '../../system/service/sys-settings-service';
|
||||
} from '@midwayjs/core';
|
||||
import { BaseController } from '../../../basic/base-controller.js';
|
||||
import { Constants } from '../../../basic/constants.js';
|
||||
import { UserService } from '../../authority/service/user-service.js';
|
||||
import { UserEntity } from '../../authority/entity/user.js';
|
||||
import { SysSettingsService } from '../../system/service/sys-settings-service.js';
|
||||
|
||||
/**
|
||||
*/
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { Config, Inject, Provide } from '@midwayjs/decorator';
|
||||
import { UserService } from '../../authority/service/user-service';
|
||||
import * as jwt from 'jsonwebtoken';
|
||||
import { CommonException } from '../../../basic/exception/common-exception';
|
||||
import { RoleService } from '../../authority/service/role-service';
|
||||
import { UserEntity } from '../../authority/entity/user';
|
||||
import { Config, Inject, Provide } from '@midwayjs/core';
|
||||
import { UserService } from '../../authority/service/user-service.js';
|
||||
import jwt from 'jsonwebtoken';
|
||||
import { CommonException } from '../../../basic/exception/common-exception.js';
|
||||
import { RoleService } from '../../authority/service/role-service.js';
|
||||
import { UserEntity } from '../../authority/entity/user.js';
|
||||
|
||||
/**
|
||||
* 系统用户
|
||||
@@ -26,7 +26,7 @@ export class LoginService {
|
||||
if (info == null) {
|
||||
throw new CommonException('用户名或密码错误');
|
||||
}
|
||||
const right = this.userService.checkPassword(user.password, info.password);
|
||||
const right = await this.userService.checkPassword(user.password, info.password, info.passwordVersion);
|
||||
if (!right) {
|
||||
throw new CommonException('用户名或密码错误');
|
||||
}
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
import {
|
||||
ALL,
|
||||
Body,
|
||||
Controller,
|
||||
Inject,
|
||||
Post,
|
||||
Provide,
|
||||
} from '@midwayjs/decorator';
|
||||
import { BaseController } from '../../../basic/base-controller';
|
||||
import { Constants } from '../../../basic/constants';
|
||||
import { UserService } from '../../authority/service/user-service';
|
||||
import { ALL, Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
|
||||
import { BaseController } from '../../../basic/base-controller.js';
|
||||
import { Constants } from '../../../basic/constants.js';
|
||||
import { UserService } from '../../authority/service/user-service.js';
|
||||
|
||||
/**
|
||||
*/
|
||||
|
||||
@@ -1,8 +1,16 @@
|
||||
import { ALL, Body, Controller, Inject, Post, Provide, Query } from "@midwayjs/decorator";
|
||||
import { CrudController } from "../../../basic/crud-controller";
|
||||
import { Constants } from "../../../basic/constants";
|
||||
import { UserSettingsService } from "../service/user-settings-service";
|
||||
import { UserSettingsEntity } from "../entity/user-settings";
|
||||
import {
|
||||
ALL,
|
||||
Body,
|
||||
Controller,
|
||||
Inject,
|
||||
Post,
|
||||
Provide,
|
||||
Query,
|
||||
} from '@midwayjs/core';
|
||||
import { CrudController } from '../../../basic/crud-controller.js';
|
||||
import { Constants } from '../../../basic/constants.js';
|
||||
import { UserSettingsService } from '../service/user-settings-service.js';
|
||||
import { UserSettingsEntity } from '../entity/user-settings.js';
|
||||
|
||||
/**
|
||||
*/
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Provide, Scope, ScopeEnum } from '@midwayjs/decorator';
|
||||
import { Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
||||
import { InjectEntityModel } from '@midwayjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { BaseService } from '../../../basic/base-service';
|
||||
import { UserSettingsEntity } from '../entity/user-settings';
|
||||
import { BaseService } from '../../../basic/base-service.js';
|
||||
import { UserSettingsEntity } from '../entity/user-settings.js';
|
||||
|
||||
/**
|
||||
* 授权
|
||||
@@ -30,7 +30,10 @@ export class UserSettingsService extends BaseService<UserSettingsEntity> {
|
||||
};
|
||||
}
|
||||
|
||||
async getByKey(key: string, userId: number): Promise<UserSettingsEntity | null> {
|
||||
async getByKey(
|
||||
key: string,
|
||||
userId: number
|
||||
): Promise<UserSettingsEntity | null> {
|
||||
if (!key || !userId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Autoload, Init, Inject, Scope, ScopeEnum } from '@midwayjs/decorator';
|
||||
import { PipelineService } from '../service/pipeline-service';
|
||||
import { logger } from '../../../utils/logger';
|
||||
import { Autoload, Init, Inject, Scope, ScopeEnum } from '@midwayjs/core';
|
||||
import { PipelineService } from '../service/pipeline-service.js';
|
||||
import { logger } from '../../../utils/logger.js';
|
||||
|
||||
@Autoload()
|
||||
@Scope(ScopeEnum.Singleton)
|
||||
|
||||
@@ -6,10 +6,10 @@ import {
|
||||
Post,
|
||||
Provide,
|
||||
Query,
|
||||
} from '@midwayjs/decorator';
|
||||
import { CrudController } from '../../../basic/crud-controller';
|
||||
import { AccessService } from '../service/access-service';
|
||||
import { Constants } from '../../../basic/constants';
|
||||
} from '@midwayjs/core';
|
||||
import { CrudController } from '../../../basic/crud-controller.js';
|
||||
import { AccessService } from '../service/access-service.js';
|
||||
import { Constants } from '../../../basic/constants.js';
|
||||
|
||||
/**
|
||||
* 授权
|
||||
|
||||
+4
-11
@@ -1,14 +1,7 @@
|
||||
import {
|
||||
ALL,
|
||||
Controller,
|
||||
Inject,
|
||||
Post,
|
||||
Provide,
|
||||
Query,
|
||||
} from '@midwayjs/decorator';
|
||||
import { DnsProviderService } from '../service/dns-provider-service';
|
||||
import { BaseController } from '../../../basic/base-controller';
|
||||
import {Constants} from "../../../basic/constants";
|
||||
import { ALL, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
|
||||
import { DnsProviderService } from '../service/dns-provider-service.js';
|
||||
import { BaseController } from '../../../basic/base-controller.js';
|
||||
import { Constants } from '../../../basic/constants.js';
|
||||
|
||||
/**
|
||||
* 插件
|
||||
|
||||
@@ -1,25 +1,16 @@
|
||||
import {
|
||||
ALL,
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
Inject,
|
||||
Post,
|
||||
Provide,
|
||||
Query,
|
||||
} from '@midwayjs/decorator';
|
||||
import { CrudController } from '../../../basic/crud-controller';
|
||||
import { PipelineEntity } from '../entity/pipeline';
|
||||
import { HistoryService } from '../service/history-service';
|
||||
import { HistoryLogService } from '../service/history-log-service';
|
||||
import { HistoryEntity } from '../entity/history';
|
||||
import { HistoryLogEntity } from '../entity/history-log';
|
||||
import { Constants } from '../../../basic/constants';
|
||||
import { PipelineService } from '../service/pipeline-service';
|
||||
import { CommonException } from '../../../basic/exception/common-exception';
|
||||
import { PermissionException } from '../../../basic/exception/permission-exception';
|
||||
import { ALL, Body, Controller, Get, Inject, Post, Provide, Query } from '@midwayjs/core';
|
||||
import { CrudController } from '../../../basic/crud-controller.js';
|
||||
import { PipelineEntity } from '../entity/pipeline.js';
|
||||
import { HistoryService } from '../service/history-service.js';
|
||||
import { HistoryLogService } from '../service/history-log-service.js';
|
||||
import { HistoryEntity } from '../entity/history.js';
|
||||
import { HistoryLogEntity } from '../entity/history-log.js';
|
||||
import { Constants } from '../../../basic/constants.js';
|
||||
import { PipelineService } from '../service/pipeline-service.js';
|
||||
import { CommonException } from '../../../basic/exception/common-exception.js';
|
||||
import { PermissionException } from '../../../basic/exception/permission-exception.js';
|
||||
import * as fs from 'fs';
|
||||
import { logger } from '../../../utils/logger';
|
||||
import { logger } from '../../../utils/logger.js';
|
||||
|
||||
/**
|
||||
* 证书
|
||||
@@ -53,11 +44,7 @@ export class HistoryController extends CrudController<HistoryService> {
|
||||
const buildQuery = qb => {
|
||||
qb.limit(10);
|
||||
};
|
||||
const listRet = await this.getService().list(
|
||||
body,
|
||||
{ prop: 'id', asc: false },
|
||||
buildQuery
|
||||
);
|
||||
const listRet = await this.getService().list(body, { prop: 'id', asc: false }, buildQuery);
|
||||
return this.ok(listRet);
|
||||
}
|
||||
|
||||
@@ -137,11 +124,7 @@ export class HistoryController extends CrudController<HistoryService> {
|
||||
}
|
||||
|
||||
@Get('/download', { summary: Constants.per.authOnly })
|
||||
async download(
|
||||
@Query('pipelineId') pipelineId,
|
||||
@Query('historyId') historyId,
|
||||
@Query('fileId') fileId
|
||||
) {
|
||||
async download(@Query('pipelineId') pipelineId, @Query('historyId') historyId, @Query('fileId') fileId) {
|
||||
const files = await this.getFiles(historyId, pipelineId);
|
||||
const file = files.find(f => f.id === fileId);
|
||||
if (file == null) {
|
||||
|
||||
@@ -1,17 +1,9 @@
|
||||
import {
|
||||
ALL,
|
||||
Body,
|
||||
Controller,
|
||||
Inject,
|
||||
Post,
|
||||
Provide,
|
||||
Query,
|
||||
} from '@midwayjs/decorator';
|
||||
import { CrudController } from '../../../basic/crud-controller';
|
||||
import { PipelineService } from '../service/pipeline-service';
|
||||
import { PipelineEntity } from '../entity/pipeline';
|
||||
import { Constants } from '../../../basic/constants';
|
||||
import { HistoryService } from '../service/history-service';
|
||||
import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
|
||||
import { CrudController } from '../../../basic/crud-controller.js';
|
||||
import { PipelineService } from '../service/pipeline-service.js';
|
||||
import { PipelineEntity } from '../entity/pipeline.js';
|
||||
import { Constants } from '../../../basic/constants.js';
|
||||
import { HistoryService } from '../service/history-service.js';
|
||||
|
||||
/**
|
||||
* 证书
|
||||
|
||||
@@ -5,10 +5,10 @@ import {
|
||||
Post,
|
||||
Provide,
|
||||
Query,
|
||||
} from '@midwayjs/decorator';
|
||||
import { BaseController } from '../../../basic/base-controller';
|
||||
import { PluginService } from '../service/plugin-service';
|
||||
import { Constants } from '../../../basic/constants';
|
||||
} from '@midwayjs/core';
|
||||
import { BaseController } from '../../../basic/base-controller.js';
|
||||
import { PluginService } from '../service/plugin-service.js';
|
||||
import { Constants } from '../../../basic/constants.js';
|
||||
|
||||
/**
|
||||
* 插件
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { HistoryEntity } from '../history';
|
||||
import { HistoryLogEntity } from '../history-log';
|
||||
import { HistoryEntity } from '../history.js';
|
||||
import { HistoryLogEntity } from '../history-log.js';
|
||||
|
||||
export class HistoryDetail {
|
||||
history: HistoryEntity;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { PipelineEntity } from '../pipeline';
|
||||
import { HistoryEntity } from '../history';
|
||||
import { HistoryLogEntity } from '../history-log';
|
||||
import { PipelineEntity } from '../pipeline.js';
|
||||
import { HistoryEntity } from '../history.js';
|
||||
import { HistoryLogEntity } from '../history-log.js';
|
||||
|
||||
export class PipelineDetail {
|
||||
pipeline: PipelineEntity;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Provide, Scope, ScopeEnum } from '@midwayjs/decorator';
|
||||
import { Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
||||
import { InjectEntityModel } from '@midwayjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { BaseService } from '../../../basic/base-service';
|
||||
import { AccessEntity } from '../entity/access';
|
||||
import { BaseService } from '../../../basic/base-service.js';
|
||||
import { AccessEntity } from '../entity/access.js';
|
||||
import { accessRegistry, IAccessService } from '@certd/pipeline';
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { IStorage } from '@certd/pipeline';
|
||||
import { StorageService } from './storage-service';
|
||||
import { StorageService } from './storage-service.js';
|
||||
|
||||
export class DbStorage implements IStorage {
|
||||
/**
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Provide, Scope, ScopeEnum } from '@midwayjs/decorator';
|
||||
import { Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
||||
import { dnsProviderRegistry } from '@certd/plugin-cert';
|
||||
@Provide()
|
||||
@Scope(ScopeEnum.Singleton)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Provide, Scope, ScopeEnum } from "@midwayjs/decorator";
|
||||
import { Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
||||
import { InjectEntityModel } from '@midwayjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { BaseService } from '../../../basic/base-service';
|
||||
import { HistoryLogEntity } from '../entity/history-log';
|
||||
import { BaseService } from '../../../basic/base-service.js';
|
||||
import { HistoryLogEntity } from '../entity/history-log.js';
|
||||
|
||||
/**
|
||||
* 证书申请
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { Config, Inject, Provide, Scope, ScopeEnum } from '@midwayjs/decorator';
|
||||
import { Config, Inject, Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
||||
import { InjectEntityModel } from '@midwayjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { BaseService } from '../../../basic/base-service';
|
||||
import { HistoryEntity } from '../entity/history';
|
||||
import { PipelineEntity } from '../entity/pipeline';
|
||||
import { HistoryDetail } from '../entity/vo/history-detail';
|
||||
import { HistoryLogService } from './history-log-service';
|
||||
import { BaseService } from '../../../basic/base-service.js';
|
||||
import { HistoryEntity } from '../entity/history.js';
|
||||
import { PipelineEntity } from '../entity/pipeline.js';
|
||||
import { HistoryDetail } from '../entity/vo/history-detail.js';
|
||||
import { HistoryLogService } from './history-log-service.js';
|
||||
import { FileItem, Pipeline, RunnableCollection } from '@certd/pipeline';
|
||||
import { FileStore } from '@certd/pipeline';
|
||||
import { logger } from '../../../utils/logger';
|
||||
import { logger } from '../../../utils/logger.js';
|
||||
|
||||
/**
|
||||
* 证书申请
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
import { Config, Inject, Provide, Scope, ScopeEnum } from '@midwayjs/decorator';
|
||||
import { Config, Inject, Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
||||
import { InjectEntityModel } from '@midwayjs/typeorm';
|
||||
import { In, Repository } from 'typeorm';
|
||||
import { BaseService } from '../../../basic/base-service';
|
||||
import { PipelineEntity } from '../entity/pipeline';
|
||||
import { PipelineDetail } from '../entity/vo/pipeline-detail';
|
||||
import { BaseService } from '../../../basic/base-service.js';
|
||||
import { PipelineEntity } from '../entity/pipeline.js';
|
||||
import { PipelineDetail } from '../entity/vo/pipeline-detail.js';
|
||||
import { Executor, Pipeline, ResultType, RunHistory } from '@certd/pipeline';
|
||||
import { AccessService } from './access-service';
|
||||
import { DbStorage } from './db-storage';
|
||||
import { StorageService } from './storage-service';
|
||||
import { Cron } from '../../plugin/cron/cron';
|
||||
import { HistoryService } from './history-service';
|
||||
import { HistoryEntity } from '../entity/history';
|
||||
import { HistoryLogEntity } from '../entity/history-log';
|
||||
import { HistoryLogService } from './history-log-service';
|
||||
import { logger } from '../../../utils/logger';
|
||||
import { EmailService } from '../../basic/service/email-service';
|
||||
import { AccessService } from './access-service.js';
|
||||
import { DbStorage } from './db-storage.js';
|
||||
import { StorageService } from './storage-service.js';
|
||||
import { Cron } from '../../plugin/cron/cron.js';
|
||||
import { HistoryService } from './history-service.js';
|
||||
import { HistoryEntity } from '../entity/history.js';
|
||||
import { HistoryLogEntity } from '../entity/history-log.js';
|
||||
import { HistoryLogService } from './history-log-service.js';
|
||||
import { logger } from '../../../utils/logger.js';
|
||||
import { EmailService } from '../../basic/service/email-service.js';
|
||||
|
||||
const runningTasks: Map<string | number, Executor> = new Map();
|
||||
|
||||
@@ -138,7 +138,11 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||
cron: null,
|
||||
job: async () => {
|
||||
logger.info('job准备启动,当前定时器数量:', this.cron.getListSize());
|
||||
await this.run(id, null);
|
||||
try {
|
||||
await this.run(id, null);
|
||||
} catch (e) {
|
||||
logger.error('定时job执行失败:', e);
|
||||
}
|
||||
},
|
||||
});
|
||||
logger.info('定时器数量:', this.cron.getListSize());
|
||||
@@ -230,7 +234,7 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||
await executor.run(historyId, triggerType);
|
||||
} catch (e) {
|
||||
logger.error('执行失败:', e);
|
||||
throw e;
|
||||
// throw e;
|
||||
} finally {
|
||||
runningTasks.delete(historyId);
|
||||
}
|
||||
@@ -242,8 +246,8 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||
await executor.cancel();
|
||||
} else {
|
||||
const entity = await this.historyService.info(historyId);
|
||||
if(entity == null){
|
||||
return
|
||||
if (entity == null) {
|
||||
return;
|
||||
}
|
||||
const pipeline: Pipeline = JSON.parse(entity.pipeline);
|
||||
pipeline.status.status = ResultType.canceled;
|
||||
@@ -295,7 +299,7 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||
const entity: HistoryEntity = new HistoryEntity();
|
||||
entity.id = parseInt(history.id);
|
||||
entity.userId = history.pipeline.userId;
|
||||
entity.status = pipelineEntity.status
|
||||
entity.status = pipelineEntity.status;
|
||||
entity.pipeline = JSON.stringify(history.pipeline);
|
||||
entity.pipelineId = parseInt(history.pipeline.id);
|
||||
await this.historyService.save(entity);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Provide, Scope, ScopeEnum } from "@midwayjs/decorator";
|
||||
import { Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
||||
import { pluginRegistry } from '@certd/pipeline';
|
||||
@Provide()
|
||||
@Scope(ScopeEnum.Singleton)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Provide, Scope, ScopeEnum } from '@midwayjs/decorator';
|
||||
import { Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
||||
import { InjectEntityModel } from '@midwayjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { BaseService } from '../../../basic/base-service';
|
||||
import { StorageEntity } from '../entity/storage';
|
||||
import { BaseService } from '../../../basic/base-service.js';
|
||||
import { StorageEntity } from '../entity/storage.js';
|
||||
|
||||
/**
|
||||
*/
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Config, Configuration, Logger } from '@midwayjs/decorator';
|
||||
import { Config, Configuration, Logger } from '@midwayjs/core';
|
||||
import { ILogger } from '@midwayjs/logger';
|
||||
import { IMidwayContainer } from '@midwayjs/core';
|
||||
import { Cron } from './cron';
|
||||
import { Cron } from './cron.js';
|
||||
|
||||
// ... (see below) ...
|
||||
@Configuration({
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// src/index.ts
|
||||
export { CronConfiguration as Configuration } from './configuration';
|
||||
export { CronConfiguration as Configuration } from './configuration.js';
|
||||
// export * from './controller/user';
|
||||
// export * from './controller/api';
|
||||
// export * from './service/user';
|
||||
|
||||
@@ -6,10 +6,10 @@ import {
|
||||
Post,
|
||||
Provide,
|
||||
Query,
|
||||
} from '@midwayjs/decorator';
|
||||
import { CrudController } from '../../../basic/crud-controller';
|
||||
import { SysSettingsService } from '../service/sys-settings-service';
|
||||
import { SysSettingsEntity } from '../entity/sys-settings';
|
||||
} from '@midwayjs/core';
|
||||
import { CrudController } from '../../../basic/crud-controller.js';
|
||||
import { SysSettingsService } from '../service/sys-settings-service.js';
|
||||
import { SysSettingsEntity } from '../entity/sys-settings.js';
|
||||
|
||||
/**
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
export class BaseSettings {
|
||||
static __key__: string;
|
||||
static __title__: string;
|
||||
static __access__ = 'private';
|
||||
|
||||
static getCacheKey() {
|
||||
return 'settings.' + this.__key__;
|
||||
}
|
||||
}
|
||||
export class SysPublicSettings extends BaseSettings {
|
||||
static __key__ = 'sys.public';
|
||||
static __title__ = '系统公共设置';
|
||||
static __access__ = 'public';
|
||||
registerEnabled = false;
|
||||
}
|
||||
|
||||
export class SysPrivateSettings extends BaseSettings {
|
||||
static __title__ = '系统私有设置';
|
||||
static __access__ = 'private';
|
||||
static __key__ = 'sys.private';
|
||||
}
|
||||
|
||||
export class SysInstallInfo extends BaseSettings {
|
||||
static __title__ = '系统安装信息';
|
||||
static __key__ = 'sys.install';
|
||||
static __access__ = 'private';
|
||||
installTime: number;
|
||||
siteId?: string;
|
||||
}
|
||||
@@ -1,17 +1,11 @@
|
||||
import { Inject, Provide, Scope, ScopeEnum } from '@midwayjs/decorator';
|
||||
import { Inject, Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
||||
import { InjectEntityModel } from '@midwayjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { BaseService } from '../../../basic/base-service';
|
||||
import { SysSettingsEntity } from '../entity/sys-settings';
|
||||
import { BaseService } from '../../../basic/base-service.js';
|
||||
import { SysSettingsEntity } from '../entity/sys-settings.js';
|
||||
import { CacheManager } from '@midwayjs/cache';
|
||||
|
||||
const SYS_PUBLIC_KEY = 'sys.public';
|
||||
const SYS_PRIVATE_KEY = 'sys.private';
|
||||
const CACHE_SYS_PUBLIC_KEY = `settings.${SYS_PUBLIC_KEY}`;
|
||||
const CACHE_SYS_PRIVATE_KEY = `settings.${SYS_PRIVATE_KEY}`;
|
||||
export type SysPublicSettings = {
|
||||
registerEnabled: boolean;
|
||||
};
|
||||
import { BaseSettings, SysPublicSettings } from './models.js';
|
||||
import * as _ from 'lodash-es';
|
||||
|
||||
export type SysPrivateSettings = NonNullable<unknown>;
|
||||
|
||||
@@ -77,67 +71,60 @@ export class SysSettingsService extends BaseService<SysSettingsEntity> {
|
||||
}
|
||||
}
|
||||
|
||||
async getPublicSettings(): Promise<SysPublicSettings> {
|
||||
const key = CACHE_SYS_PUBLIC_KEY;
|
||||
let settings: SysPublicSettings = await this.cache.get(key);
|
||||
async getSetting<T>(type: any): Promise<T> {
|
||||
const key = type.__key__;
|
||||
const cacheKey = type.getCacheKey();
|
||||
let settings: T = await this.cache.get(cacheKey);
|
||||
let settingInstance: T = new type();
|
||||
if (settings == null) {
|
||||
settings = await this.readPublicSettings();
|
||||
await this.cache.set(key, settings);
|
||||
settings = await this.getSettingByKey(key);
|
||||
settingInstance = _.merge(settingInstance, settings);
|
||||
await this.cache.set(key, settingInstance);
|
||||
}
|
||||
return settings;
|
||||
return settingInstance;
|
||||
}
|
||||
|
||||
async readPublicSettings(): Promise<SysPublicSettings> {
|
||||
const key = SYS_PUBLIC_KEY;
|
||||
async saveSetting<T extends BaseSettings>(bean: T) {
|
||||
const type: any = bean.constructor;
|
||||
const key = type.__key__;
|
||||
const cacheKey = type.getCacheKey();
|
||||
|
||||
const entity = await this.getByKey(key);
|
||||
if (!entity) {
|
||||
return {
|
||||
registerEnabled: false,
|
||||
};
|
||||
if (entity) {
|
||||
entity.setting = JSON.stringify(bean);
|
||||
await this.repository.save(entity);
|
||||
} else {
|
||||
const newEntity = new SysSettingsEntity();
|
||||
newEntity.key = key;
|
||||
newEntity.title = type.__title__;
|
||||
newEntity.setting = JSON.stringify(bean);
|
||||
newEntity.access = type.__access__;
|
||||
await this.repository.save(newEntity);
|
||||
}
|
||||
return JSON.parse(entity.setting);
|
||||
|
||||
await this.cache.set(cacheKey, bean);
|
||||
}
|
||||
|
||||
async getPublicSettings(): Promise<SysPublicSettings> {
|
||||
return await this.getSetting(SysPublicSettings);
|
||||
}
|
||||
|
||||
async savePublicSettings(bean: SysPublicSettings) {
|
||||
const key = SYS_PUBLIC_KEY;
|
||||
const entity = await this.getByKey(key);
|
||||
if (entity) {
|
||||
entity.setting = JSON.stringify(bean);
|
||||
await this.repository.save(entity);
|
||||
} else {
|
||||
const newEntity = new SysSettingsEntity();
|
||||
newEntity.key = key;
|
||||
newEntity.title = '系统公共设置';
|
||||
newEntity.setting = JSON.stringify(bean);
|
||||
newEntity.access = 'public';
|
||||
await this.repository.save(newEntity);
|
||||
}
|
||||
await this.cache.del(CACHE_SYS_PRIVATE_KEY);
|
||||
}
|
||||
|
||||
async readPrivateSettings(): Promise<SysPrivateSettings> {
|
||||
const key = SYS_PRIVATE_KEY;
|
||||
const entity = await this.getByKey(key);
|
||||
if (!entity) {
|
||||
return {};
|
||||
}
|
||||
return JSON.parse(entity.setting);
|
||||
await this.saveSetting(bean);
|
||||
}
|
||||
|
||||
async savePrivateSettings(bean: SysPrivateSettings) {
|
||||
const key = SYS_PRIVATE_KEY;
|
||||
this.saveSetting(bean);
|
||||
}
|
||||
|
||||
async updateByKey(key: string, setting: any) {
|
||||
const entity = await this.getByKey(key);
|
||||
if (entity) {
|
||||
entity.setting = JSON.stringify(bean);
|
||||
entity.setting = JSON.stringify(setting);
|
||||
await this.repository.save(entity);
|
||||
} else {
|
||||
const newEntity = new SysSettingsEntity();
|
||||
newEntity.key = key;
|
||||
newEntity.title = '系统私有设置';
|
||||
newEntity.setting = JSON.stringify(bean);
|
||||
newEntity.access = 'private';
|
||||
await this.repository.save(newEntity);
|
||||
throw new Error('该设置不存在');
|
||||
}
|
||||
await this.cache.del(CACHE_SYS_PRIVATE_KEY);
|
||||
await this.cache.del(`settings.${key}`);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user