chore: lib-server

This commit is contained in:
xiaojunnuo
2024-10-03 22:03:49 +08:00
parent a13203fb3f
commit a4e2cc54e6
101 changed files with 936 additions and 223 deletions
+1 -1
View File
@@ -55,7 +55,7 @@ export function errorLog(error: any) {
if (error.response?.data?.message) {
message = error.response.data.message;
}
if (message.indexOf("ssl3_get_record:wrong version number" > -1)) {
if (message.indexOf("ssl3_get_record:wrong version number") >= 0) {
message = "http协议错误,服务端要求http协议,请检查是否使用了https请求";
}
// 显示提示
@@ -150,35 +150,69 @@ function openUpgrade() {
content: () => {
const vipLabel = userStore.vipLabel;
return (
<div class="mt-10 mb-10">
<div>
<div class="mt-10 mb-10 vip-active-modal">
<div class="vip-type-vs">
<a-row gutter={20}>
<a-col span={8}>
<h3 class="block-header">免费版</h3>
<ul>
<li>证书申请功能无限制</li>
<li>证书流水线数量限制10条</li>
<li>部分部署插件不可用</li>
<li>
<fs-icon class="color-green" icon="ion:checkmark-sharp"></fs-icon>证书申请功能无限制
</li>
<li>
<fs-icon class="color-green" icon="ion:checkmark-sharp"></fs-icon>
证书流水线数量10条
</li>
<li>
<fs-icon class="color-green" icon="ion:checkmark-sharp"></fs-icon>
常用的部署插件
</li>
</ul>
</a-col>
<a-col span={8}>
<h3 class="block-header">专业版</h3>
<ul>
<li>可加VIP群需求优先实现</li>
<li>证书流水线数量无限制</li>
<li>免配置发邮件功能</li>
<li>宝塔易盾群晖cdnfly1Panel等部署插件</li>
<li>多用户有限制</li>
<li>
<fs-icon class="color-green" icon="ion:checkmark-sharp"></fs-icon>
可加VIP群需求优先实现
</li>
<li>
<fs-icon class="color-green" icon="ion:checkmark-sharp"></fs-icon>
证书流水线数量无限制
</li>
<li>
<fs-icon class="color-green" icon="ion:checkmark-sharp"></fs-icon>
免配置发邮件功能
</li>
<li>
<fs-icon class="color-green" icon="ion:checkmark-sharp"></fs-icon>
支持宝塔易盾群晖cdnfly1Panel等部署插件
</li>
</ul>
</a-col>
<a-col span={8}>
<h3 class="block-header">商业版</h3>
<ul>
<li>拥有专业版所有特权</li>
<li>修改logo标题</li>
<li>多用户无限制</li>
<li>支持用户支付</li>
<li>允许商用</li>
<li>
<fs-icon class="color-green" icon="ion:checkmark-sharp"></fs-icon>
拥有专业版所有特权
</li>
<li>
<fs-icon class="color-green" icon="ion:checkmark-sharp"></fs-icon>
修改logo标题
</li>
<li>
<fs-icon class="color-green" icon="ion:checkmark-sharp"></fs-icon>
多用户无限制
</li>
<li>
<fs-icon class="color-green" icon="ion:checkmark-sharp"></fs-icon>
支持用户支付
</li>
<li>
<fs-icon class="color-green" icon="ion:checkmark-sharp"></fs-icon>
允许商用
</li>
</ul>
</a-col>
</a-row>
@@ -224,4 +258,18 @@ function openUpgrade() {
margin-left: 5px;
}
}
.vip-active-modal {
ul {
list-style-type: unset;
margin-left: 0px;
padding: 0;
}
.vip-type-vs {
.fs-icon {
margin-right: 5px;
color: green;
}
}
}
</style>
@@ -86,6 +86,7 @@ import { env } from "../utils/util.env";
import FsThemeModeSet from "./components/theme/mode-set.vue";
import VipButton from "/@/components/vip-button/index.vue";
import TutorialButton from "/@/components/tutorial/index.vue";
import { useUserStore } from "/@/store/modules/user";
export default {
name: "LayoutFramework",
// eslint-disable-next-line vue/no-unused-components
@@ -130,7 +131,10 @@ export default {
const version = ref(import.meta.env.VITE_APP_VERSION);
const envRef = ref(env);
const userStore = useUserStore();
return {
userStore,
version,
frameworkMenus,
headerMenus,
@@ -75,6 +75,33 @@ export const sysResources = [
},
path: "/sys/account",
component: "/sys/account/index.vue"
},
{
title: "站点个性化",
name: "site",
meta: {
icon: "ion:document-text-outline",
permission: "sys:settings:view"
},
component: "/sys/site/index.vue"
},
{
title: "商业版设置",
name: "/sys/commercial",
meta: {
icon: "ion:document-text-outline",
permission: "sys:settings:view"
},
children: [
{
title: "套餐设置",
name: "suite",
meta: {
icon: "ion:document-text-outline",
permission: "sys:settings:view"
}
}
]
}
]
}
@@ -0,0 +1,43 @@
// @ts-ignore
import { request } from "/src/api/service";
const apiPrefix = "/sys/settings";
export const SettingKeys = {
SysPublic: "sys.public",
SysPrivate: "sys.private"
};
export async function SettingsGet(key: string) {
return await request({
url: apiPrefix + "/get",
method: "post",
params: {
key
}
});
}
export async function SettingsSave(key: string, setting: any) {
await request({
url: apiPrefix + "/save",
method: "post",
data: {
key,
setting: JSON.stringify(setting)
}
});
}
export async function PublicSettingsSave(setting: any) {
await request({
url: apiPrefix + "/savePublicSettings",
method: "post",
data: setting
});
}
export async function stopOtherUserTimer() {
await request({
url: apiPrefix + "/stopOtherUserTimer",
method: "post"
});
}
@@ -0,0 +1,92 @@
<template>
<fs-page class="page-sys-settings">
<template #header>
<div class="title">站点个性化设置</div>
</template>
<div class="sys-settings-form">
<a-form
:model="formState"
name="basic"
:label-col="{ span: 8 }"
:wrapper-col="{ span: 16 }"
autocomplete="off"
@finish="onFinish"
@finish-failed="onFinishFailed"
>
<a-form-item label="开启自助注册" name="registerEnabled">
<a-switch v-model:checked="formState.registerEnabled" />
</a-form-item>
<a-form-item label="管理其他用户流水线" name="managerOtherUserPipeline">
<a-switch v-model:checked="formState.managerOtherUserPipeline" />
</a-form-item>
<!-- <a-form-item label="启动后触发流水线" name="triggerOnStartup">-->
<!-- <a-switch v-model:checked="formState.triggerOnStartup" />-->
<!-- <div class="helper">启动后自动触发一次所有已启用的流水线</div>-->
<!-- </a-form-item>-->
<a-form-item :wrapper-col="{ offset: 8, span: 16 }">
<a-button type="primary" html-type="submit">保存</a-button>
</a-form-item>
</a-form>
<!-- <a-descriptions label="系统维护操作">-->
<!-- <a-descriptions-item label="自动化任务">-->
<!-- <a-button @click="stopOtherUserTimer">停止所有其他用户的定时任务</a-button>-->
<!-- </a-descriptions-item>-->
<!-- </a-descriptions>-->
</div>
</fs-page>
</template>
<script setup lang="ts">
import { reactive } from "vue";
import * as api from "./api";
import { PublicSettingsSave, SettingKeys } from "./api";
import { notification } from "ant-design-vue";
import { useSettingStore } from "/src/store/modules/settings";
interface FormState {
title: string;
logo: string;
}
const formState = reactive<Partial<FormState>>({
registerEnabled: false,
managerOtherUserPipeline: false
});
async function loadSysPublicSettings() {
const data: any = await api.SettingsGet(SettingKeys.SysPublic);
const setting = JSON.parse(data.setting);
Object.assign(formState, setting);
}
loadSysPublicSettings();
const settingsStore = useSettingStore();
const onFinish = async (form: any) => {
await api.PublicSettingsSave(form);
await settingsStore.loadSysSettings();
notification.success({
message: "保存成功"
});
};
const onFinishFailed = (errorInfo: any) => {
// console.log("Failed:", errorInfo);
};
async function stopOtherUserTimer() {
await api.stopOtherUserTimer();
notification.success({
message: "停止成功"
});
}
</script>
<style lang="less">
.page-sys-settings {
.sys-settings-form {
width: 500px;
margin: 20px;
}
}
</style>
+12 -10
View File
@@ -17,21 +17,23 @@
# password: root
# database: postgres
typeorm:
dataSource:
default:
database: './data/db-comm.sqlite'
#plus:
# server:
# baseUrls: ['https://api.ai.handsfree.work', 'https://api.ai.docmirror.cn']
#typeorm:
# dataSource:
# default:
# database: './data/db-comm.sqlite'
plus:
server:
baseUrls: ['http://127.0.0.1:11007']
baseUrls: ['https://api.ai.handsfree.work', 'https://api.ai.docmirror.cn']
account:
server:
baseUrl: 'http://127.0.0.1:1017/subject'
baseUrl: 'https://ai.handsfree.work/subject'
#plus:
# server:
# baseUrls: ['http://127.0.0.1:11007']
#
#account:
# server:
# baseUrl: 'https://ai.handsfree.work/subject'
# baseUrl: 'http://127.0.0.1:1017/subject'
+1 -1
View File
@@ -5,7 +5,7 @@ const { Bootstrap } = require('@midwayjs/bootstrap');
const DirectoryFileDetector = require('@midwayjs/core').DirectoryFileDetector;
const baseDir = process.cwd();
const pipelineDir = baseDir + './node_modules/@certd/pipeline';
const pipelineDir = baseDir + './node_modules/@certd/pipeline/dist';
const customFileDetector = new DirectoryFileDetector({
loadDir: [baseDir, pipelineDir],
});
+2 -1
View File
@@ -24,6 +24,7 @@
"@alicloud/pop-core": "^1.7.10",
"@certd/acme-client": "^1.25.9",
"@certd/lib-huawei": "^1.25.9",
"@certd/lib-server": "^1.25.9",
"@certd/commercial-core": "^1.25.9",
"@certd/lib-jdcloud": "^1.25.9",
"@certd/lib-k8s": "^1.25.9",
@@ -64,7 +65,7 @@
"lru-cache": "^10.2.0",
"md5": "^2.3.0",
"mwtsc": "^1.4.0",
"nanoid": "^4.0.0",
"nanoid": "^5.0.7",
"nodemailer": "^6.9.3",
"pg": "^8.12.0",
"qiniu": "^7.12.0",
@@ -1,42 +0,0 @@
import { Inject } from '@midwayjs/core';
import { Context } from '@midwayjs/koa';
import { Constants } from './constants.js';
export abstract class BaseController {
@Inject()
ctx: Context;
/**
* 成功返回
* @param data 返回数据
*/
ok(data?: any) {
const res = {
...Constants.res.success,
data: undefined,
};
if (data) {
res.data = data;
}
return res;
}
/**
* 失败返回
* @param msg
* @param code
*/
fail(msg: string, code: any) {
return {
code: code ? code : Constants.res.error.code,
msg: msg ? msg : Constants.res.error.code,
};
}
getUserId() {
const userId = this.ctx.user?.id;
if (userId == null) {
throw new Error('Token已过期');
}
return userId;
}
}
@@ -1,212 +0,0 @@
import { ValidateException } from './exception/validation-exception.js';
import * as _ from 'lodash-es';
import { PermissionException } from './exception/permission-exception.js';
import { Repository } from 'typeorm';
import { Inject } from '@midwayjs/core';
import { TypeORMDataSourceManager } from '@midwayjs/typeorm';
import { EntityManager } from 'typeorm/entity-manager/EntityManager.js';
/**
* 服务基类
*/
export abstract class BaseService<T> {
@Inject()
dataSourceManager: TypeORMDataSourceManager;
abstract getRepository(): Repository<T>;
async transaction(callback: (entityManager: EntityManager) => Promise<any>) {
const dataSource = this.dataSourceManager.getDataSource('default');
await dataSource.transaction(callback as any);
}
/**
* 获得单个ID
* @param id ID
* @param infoIgnoreProperty 忽略返回属性
*/
async info(id, infoIgnoreProperty?): Promise<T | null> {
if (!id) {
throw new ValidateException('id不能为空');
}
const info = await this.getRepository().findOneBy({ id } as any);
if (info && infoIgnoreProperty) {
for (const property of infoIgnoreProperty) {
delete info[property];
}
}
return info;
}
/**
* 非分页查询
* @param options
*/
async find(options) {
return await this.getRepository().find(options);
}
/**
* 删除
* @param ids 删除的ID集合 如:[1,2,3] 或者 1,2,3
*/
async delete(ids) {
if (ids instanceof Array) {
await this.getRepository().delete(ids);
} else if (typeof ids === 'string') {
await this.getRepository().delete(ids.split(','));
} else {
//ids是一个condition
await this.getRepository().delete(ids);
}
await this.modifyAfter(ids);
}
/**
* 新增|修改
* @param param 数据
*/
async addOrUpdate(param) {
await this.getRepository().save(param);
}
/**
* 新增
* @param param 数据
*/
async add(param) {
const now = new Date();
param.createTime = now;
param.updateTime = now;
await this.addOrUpdate(param);
await this.modifyAfter(param);
return {
id: param.id,
};
}
/**
* 修改
* @param param 数据
*/
async update(param) {
if (!param.id) throw new ValidateException('no id');
param.updateTime = new Date();
await this.addOrUpdate(param);
await this.modifyAfter(param);
}
/**
* 新增|修改|删除 之后的操作
* @param data 对应数据
*/
async modifyAfter(data) {}
/**
* 分页查询
* @param query 查询条件 bean
* @param page
* @param order
* @param buildQuery
*/
async page(query, page = { offset: 0, limit: 20 }, order, buildQuery) {
if (page.offset == null) {
page.offset = 0;
}
if (page.limit == null) {
page.limit = 20;
}
const qb = this.getRepository().createQueryBuilder('main');
if (order && order.prop) {
qb.addOrderBy('main.' + order.prop, order.asc ? 'ASC' : 'DESC');
}
qb.addOrderBy('id', 'DESC');
qb.offset(page.offset).limit(page.limit);
//根据bean query
if (query) {
let whereSql = '';
let index = 0;
_.forEach(query, (value, key) => {
if (!value) {
return;
}
if (index !== 0) {
whereSql += ' and ';
}
whereSql += ` main.${key} = :${key} `;
index++;
});
if (index > 0) {
qb.where(whereSql, query);
}
}
//自定义query
if (buildQuery) {
buildQuery(qb);
}
const list = await qb.getMany();
const total = await qb.getCount();
return {
records: list,
total,
offset: page.offset,
limit: page.limit,
};
}
/**
* 分页查询
* @param query 查询条件 bean
* @param order
* @param buildQuery
*/
async list(query, order, buildQuery) {
const qb = this.getRepository().createQueryBuilder('main');
if (order && order.prop) {
qb.orderBy('main.' + order.prop, order.asc ? 'ASC' : 'DESC');
} else {
qb.orderBy('id', 'DESC');
}
//根据bean query
if (query) {
let whereSql = '';
let index = 0;
_.forEach(query, (value, key) => {
if (!value) {
return;
}
if (index !== 0) {
whereSql += ' and ';
}
whereSql += ` main.${key} = :${key} `;
index++;
});
if (index > 0) {
qb.where(whereSql, query);
}
}
//自定义query
if (buildQuery) {
buildQuery(qb);
}
return await qb.getMany();
}
async checkUserId(id: any = 0, userId, userKey = 'userId') {
// @ts-ignore
const res = await this.getRepository().findOne({
// @ts-ignore
select: { [userKey]: true },
// @ts-ignore
where: {
// @ts-ignore
id,
},
});
// @ts-ignore
if (!res || res[userKey] === userId) {
return;
}
throw new PermissionException('权限不足');
}
}
@@ -1,52 +0,0 @@
export const Constants = {
dataDir: './data',
role: {
defaultUser: 3,
},
per: {
//无需登录
guest: '_guest_',
//无需登录
anonymous: '_guest_',
//仅需要登录
authOnly: '_authOnly_',
//仅需要登录
loginOnly: '_authOnly_',
},
res: {
serverError(message: string) {
return {
code: 1,
message,
};
},
error: {
code: 1,
message: 'Internal server error',
},
success: {
code: 0,
message: 'success',
},
validation: {
code: 10,
message: '参数错误',
},
needvip: {
code: 88,
message: '需要VIP',
},
auth: {
code: 401,
message: '您还未登录或token已过期',
},
permission: {
code: 402,
message: '您没有权限',
},
preview: {
code: 10001,
message: '对不起,预览环境不允许修改此数据',
},
},
};
@@ -1,61 +0,0 @@
import { ALL, Body, Post, Query } from '@midwayjs/core';
import { BaseController } from './base-controller.js';
export abstract class CrudController<T> extends BaseController {
abstract getService<T>();
@Post('/page')
async page(
@Body(ALL)
body
) {
const pageRet = await this.getService().page(body?.query, body?.page, body?.sort, null);
return this.ok(pageRet);
}
@Post('/list')
async list(
@Body(ALL)
body
) {
const listRet = await this.getService().list(body, null, null);
return this.ok(listRet);
}
@Post('/add')
async add(
@Body(ALL)
bean
) {
delete bean.id;
const id = await this.getService().add(bean);
return this.ok(id);
}
@Post('/info')
async info(
@Query('id')
id
) {
const bean = await this.getService().info(id);
return this.ok(bean);
}
@Post('/update')
async update(
@Body(ALL)
bean
) {
await this.getService().update(bean);
return this.ok(null);
}
@Post('/delete')
async delete(
@Query('id')
id
) {
await this.getService().delete([id]);
return this.ok(null);
}
}
@@ -1,11 +0,0 @@
export class EnumItem {
value: string;
label: string;
color: string;
constructor(value, label, color) {
this.value = value;
this.label = label;
this.color = color;
}
}
@@ -1,14 +0,0 @@
import { Constants } from '../constants.js';
import { BaseException } from './base-exception.js';
/**
* 授权异常
*/
export class AuthException extends BaseException {
constructor(message) {
super(
'AuthException',
Constants.res.auth.code,
message ? message : Constants.res.auth.message
);
}
}
@@ -1,11 +0,0 @@
/**
* 异常基类
*/
export class BaseException extends Error {
status: number;
constructor(name, code, message) {
super(message);
this.name = name;
this.status = code;
}
}
@@ -1,14 +0,0 @@
import { Constants } from '../constants.js';
import { BaseException } from './base-exception.js';
/**
* 通用异常
*/
export class CommonException extends BaseException {
constructor(message) {
super(
'CommonException',
Constants.res.error.code,
message ? message : Constants.res.error.message
);
}
}
@@ -1,14 +0,0 @@
import { Constants } from '../constants.js';
import { BaseException } from './base-exception.js';
/**
* 授权异常
*/
export class PermissionException extends BaseException {
constructor(message?: string) {
super(
'PermissionException',
Constants.res.permission.code,
message ? message : Constants.res.permission.message
);
}
}
@@ -1,14 +0,0 @@
import { Constants } from '../constants.js';
import { BaseException } from './base-exception.js';
/**
* 预览模式
*/
export class PreviewException extends BaseException {
constructor(message) {
super(
'PreviewException',
Constants.res.preview.code,
message ? message : Constants.res.preview.message
);
}
}
@@ -1,14 +0,0 @@
import { Constants } from '../constants.js';
import { BaseException } from './base-exception.js';
/**
* 校验异常
*/
export class ValidateException extends BaseException {
constructor(message) {
super(
'ValidateException',
Constants.res.validation.code,
message ? message : Constants.res.validation.message
);
}
}
@@ -1,10 +0,0 @@
import { Constants } from '../constants.js';
import { BaseException } from './base-exception.js';
/**
* 需要vip异常
*/
export class NeedVIPException extends BaseException {
constructor(message) {
super('NeedVIPException', Constants.res.needvip.code, message ? message : Constants.res.needvip.message);
}
}
@@ -1,18 +0,0 @@
export class Result<T> {
code: number;
msg: string;
data: T;
constructor(code, msg, data?) {
this.code = code;
this.msg = msg;
this.data = data;
}
static error(code = 1, msg) {
return new Result(code, msg, null);
}
static success(msg, data?) {
return new Result(0, msg, data);
}
}
@@ -12,6 +12,8 @@ import { PipelineEntity } from '../modules/pipeline/entity/pipeline.js';
//import { logger } from '../utils/logger';
// load .env file in process.cwd
import { mergeConfig } from './loader.js';
import { libServerEntities } from '@certd/lib-server';
import { commercialEntities } from '@certd/commercial-core';
const env = process.env.NODE_ENV || 'development';
@@ -63,7 +65,7 @@ const development = {
logging: false,
// 配置实体模型 或者 entities: '/entity',
entities: ['**/modules/*/entity/*.ts', '**/entity/*.js', '**/entity/*.d.ts', PipelineEntity, FlywayHistory, UserEntity],
entities: ['**/modules/*/entity/*.js', ...libServerEntities, ...commercialEntities, PipelineEntity, FlywayHistory, UserEntity],
},
},
},
@@ -2,7 +2,7 @@ import path from 'path';
import * as _ from 'lodash-es';
import yaml from 'js-yaml';
import fs from 'fs';
import { logger } from '../utils/logger.js';
import { logger } from '@certd/pipeline';
function parseEnv(defaultConfig: any) {
const config = {};
@@ -11,10 +11,11 @@ import cors from '@koa/cors';
import { GlobalExceptionMiddleware } from './middleware/global-exception.js';
import { PreviewMiddleware } from './middleware/preview.js';
import { AuthorityMiddleware } from './middleware/authority.js';
import { logger } from './utils/logger.js';
import { logger } from '@certd/pipeline';
import { ResetPasswdMiddleware } from './middleware/reset-passwd/middleware.js';
import DefaultConfig from './config/config.default.js';
import * as libServer from '@certd/lib-server';
import * as commercial from '@certd/commercial-core';
process.on('uncaughtException', error => {
console.error('未捕获的异常:', error);
// 在这里可以添加日志记录、发送错误通知等操作
@@ -33,6 +34,8 @@ process.on('uncaughtException', error => {
component: info,
enabledEnvironment: ['local'],
},
libServer,
commercial,
],
importConfigs: [
{
@@ -1,11 +1,11 @@
import { Init, Inject, MidwayWebRouterService, Provide, Scope, ScopeEnum } from '@midwayjs/core';
import { IMidwayKoaContext, IWebMiddleware, NextFunction } from '@midwayjs/koa';
import jwt from 'jsonwebtoken';
import { Constants } from '../basic/constants.js';
import { logger } from '../utils/logger.js';
import { Constants } from '@certd/lib-server';
import { logger } from '@certd/pipeline';
import { AuthService } from '../modules/authority/service/auth-service.js';
import { SysSettingsService } from '../modules/system/service/sys-settings-service.js';
import { SysPrivateSettings } from '../modules/system/service/models.js';
import { SysSettingsService } from '@certd/lib-server';
import { SysPrivateSettings } from '@certd/lib-server';
/**
* 权限校验
@@ -1,7 +1,7 @@
import { Provide } from '@midwayjs/core';
import { IWebMiddleware, IMidwayKoaContext, NextFunction } from '@midwayjs/koa';
import { logger } from '../utils/logger.js';
import { Result } from '../basic/result.js';
import { logger } from '@certd/pipeline';
import { Result } from '@certd/lib-server';
@Provide()
export class GlobalExceptionMiddleware implements IWebMiddleware {
@@ -1,6 +1,6 @@
import { Config, Provide } from '@midwayjs/core';
import { IMidwayKoaContext, NextFunction, IWebMiddleware } from '@midwayjs/koa';
import { PreviewException } from '../basic/exception/preview-exception.js';
import { PreviewException } from '@certd/lib-server';
/**
* 预览模式
@@ -30,15 +30,10 @@ export class PreviewMiddleware implements IWebMiddleware {
if (url.indexOf('?') !== -1) {
url = url.substring(0, url.indexOf('?'));
}
const isModify =
url.endsWith('update') ||
url.endsWith('delete') ||
url.endsWith('authz');
const isModify = url.endsWith('update') || url.endsWith('delete') || url.endsWith('authz');
const isPreviewId = id < 1000;
if (this.preview && isModify && isPreviewId) {
throw new PreviewException(
'对不起,预览环境不允许修改此数据,如需体验请添加新数据'
);
throw new PreviewException('对不起,预览环境不允许修改此数据,如需体验请添加新数据');
}
await next();
return;
@@ -1,16 +1,8 @@
import {
Autoload,
Config,
Init,
Inject,
Provide,
Scope,
ScopeEnum,
} from '@midwayjs/core';
import { Autoload, Config, Init, Inject, Provide, Scope, ScopeEnum } from '@midwayjs/core';
import { IMidwayKoaContext, IWebMiddleware, NextFunction } from '@midwayjs/koa';
import { CommonException } from '../../basic/exception/common-exception.js';
import { CommonException } from '@certd/lib-server';
import { UserService } from '../../modules/authority/service/user-service.js';
import { logger } from '../../utils/logger.js';
import { logger } from '@certd/pipeline';
/**
* 重置密码模式
@@ -26,9 +18,7 @@ export class ResetPasswdMiddleware implements IWebMiddleware {
resolve() {
return async (ctx: IMidwayKoaContext, next: NextFunction) => {
if (this.resetAdminPasswd === true) {
throw new CommonException(
'1号管理员密码已修改为123456,当前为重置密码模式,无法响应请求,请关闭重置密码模式恢复正常服务'
);
throw new CommonException('1号管理员密码已修改为123456,当前为重置密码模式,无法响应请求,请关闭重置密码模式恢复正常服务');
}
await next();
};
@@ -1,9 +1,9 @@
import { ALL, Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
import { BaseController } from '../../basic/base-controller.js';
import { BaseController } from '@certd/lib-server';
import { PlusService } from '../basic/service/plus-service.js';
import { AppKey } from '@certd/pipeline';
import { SysSettingsService } from '../system/service/sys-settings-service.js';
import { SysInstallInfo } from '../system/service/models.js';
import { SysSettingsService } from '@certd/lib-server';
import { SysInstallInfo } from '@certd/lib-server';
export type PreBindUserReq = {
userId: number;
@@ -1,5 +1,5 @@
import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
import { CrudController } from '../../../basic/crud-controller.js';
import { CrudController } from '@certd/lib-server';
import { PermissionService } from '../service/permission-service.js';
/**
@@ -1,5 +1,5 @@
import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
import { CrudController } from '../../../basic/crud-controller.js';
import { CrudController } from '@certd/lib-server';
import { RoleService } from '../service/role-service.js';
/**
@@ -1,9 +1,9 @@
import { Provide, Controller, Post, Inject, Body, Query, ALL } from '@midwayjs/core';
import { UserService } from '../service/user-service.js';
import { CrudController } from '../../../basic/crud-controller.js';
import { CrudController } from '@certd/lib-server';
import { RoleService } from '../service/role-service.js';
import { PermissionService } from '../service/permission-service.js';
import { Constants } from '../../../basic/constants.js';
import { Constants } from '@certd/lib-server';
/**
* 系统用户
@@ -1,4 +1,4 @@
import { EnumItem } from '../../../basic/enum-item.js';
import { EnumItem } from '@certd/lib-server';
import * as _ from 'lodash-es';
class ResourceTypes {
MENU = new EnumItem('menu', '菜单', 'blue');
@@ -1,6 +1,6 @@
import { Inject, Provide, Scope, ScopeEnum } from '@midwayjs/core';
import { RoleService } from './role-service.js';
import { BaseService } from '../../../basic/base-service.js';
import { BaseService } from '@certd/lib-server';
/**
* 权限校验
@@ -1,7 +1,7 @@
import { Provide, Scope, ScopeEnum } from '@midwayjs/core';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { Repository } from 'typeorm';
import { BaseService } from '../../../basic/base-service.js';
import { BaseService } from '@certd/lib-server';
import { PermissionEntity } from '../entity/permission.js';
/**
@@ -1,7 +1,7 @@
import { Provide, Scope, ScopeEnum } from '@midwayjs/core';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { Repository } from 'typeorm';
import { BaseService } from '../../../basic/base-service.js';
import { BaseService } from '@certd/lib-server';
import { RolePermissionEntity } from '../entity/role-permission.js';
/**
@@ -1,7 +1,7 @@
import { Inject, Provide, Scope, ScopeEnum } from '@midwayjs/core';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { In, Repository } from 'typeorm';
import { BaseService } from '../../../basic/base-service.js';
import { BaseService } from '@certd/lib-server';
import { RoleEntity } from '../entity/role.js';
import { UserRoleService } from './user-role-service.js';
import { RolePermissionEntity } from '../entity/role-permission.js';
@@ -50,12 +50,7 @@ export class RoleService extends BaseService<RoleEntity> {
async getPermissionByRoleIds(roleIds: any) {
return await this.permissionService.repository
.createQueryBuilder('permission')
.innerJoinAndSelect(
RolePermissionEntity,
'rp',
'rp.permissionId = permission.id and rp.roleId in (:...roleIds)',
{ roleIds }
)
.innerJoinAndSelect(RolePermissionEntity, 'rp', 'rp.permissionId = permission.id and rp.roleId in (:...roleIds)', { roleIds })
.getMany();
}
@@ -119,9 +114,7 @@ export class RoleService extends BaseService<RoleEntity> {
return permissionSet;
}
async getCachedPermissionSetByRoleIds(
roleIds: number[]
): Promise<Set<string>> {
async getCachedPermissionSetByRoleIds(roleIds: number[]): Promise<Set<string>> {
const roleIdsKey = roleIds.join(',');
let permissionSet = this.permissionCache.get(roleIdsKey);
if (permissionSet) {
@@ -1,7 +1,7 @@
import { Provide, Scope, ScopeEnum } from '@midwayjs/core';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { Repository } from 'typeorm';
import { BaseService } from '../../../basic/base-service.js';
import { BaseService } from '@certd/lib-server';
import { UserRoleEntity } from '../entity/user-role.js';
/**
@@ -16,6 +16,4 @@ export class UserRoleService extends BaseService<UserRoleEntity> {
getRepository() {
return this.repository;
}
}
@@ -4,16 +4,16 @@ import { Repository } from 'typeorm';
import { UserEntity } from '../entity/user.js';
import * as _ from 'lodash-es';
import md5 from 'md5';
import { CommonException } from '../../../basic/exception/common-exception.js';
import { BaseService } from '../../../basic/base-service.js';
import { CommonException } from '@certd/lib-server';
import { BaseService } from '@certd/lib-server';
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 { Constants } from '@certd/lib-server';
import { UserRoleEntity } from '../entity/user-role.js';
import bcrypt from 'bcryptjs';
import { SysSettingsService } from '../../system/service/sys-settings-service.js';
import { SysInstallInfo } from '../../system/service/models.js';
import { SysSettingsService } from '@certd/lib-server';
import { SysInstallInfo } from '@certd/lib-server';
import { RandomUtil } from '../../../utils/random.js';
/**
@@ -1,12 +1,11 @@
import { Autoload, Config, Init, Inject, Scope, ScopeEnum } from '@midwayjs/core';
import { logger } from '../../utils/logger.js';
import { logger } from '@certd/pipeline';
import { UserService } from '../authority/service/user-service.js';
import { SysSettingsService } from '../system/service/sys-settings-service.js';
import { SysSettingsService } from '@certd/lib-server';
import { nanoid } from 'nanoid';
import { SysInstallInfo, SysPrivateSettings } from '../system/service/models.js';
import { SysInstallInfo, SysPrivateSettings } from '@certd/lib-server';
import crypto from 'crypto';
import { PlusService } from '../basic/service/plus-service.js';
import { isComm } from '@certd/plus-core';
export type InstallInfo = {
installTime: number;
@@ -58,15 +57,6 @@ export class AutoInitSite {
// 授权许可
await this.plusService.verify();
if (isComm()) {
//加载商业版代码
try {
await import('@certd/commercial-core');
} catch (e) {
logger.error('加载商业版代码失败,请尝试升级版本', e);
}
}
logger.info('初始化站点完成');
}
@@ -1,7 +1,7 @@
import { Autoload, Config, Init, Inject, Scope, ScopeEnum } from '@midwayjs/core';
import { PipelineService } from '../pipeline/service/pipeline-service.js';
import { logger } from '../../utils/logger.js';
import { SysSettingsService } from '../system/service/sys-settings-service.js';
import { logger } from '@certd/pipeline';
import { SysSettingsService } from '@certd/lib-server';
@Autoload()
@Scope(ScopeEnum.Singleton)
@@ -2,10 +2,10 @@ import { Rule, RuleType } from '@midwayjs/validate';
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 { BaseController } from '@certd/lib-server';
import { CodeService } from '../service/code-service.js';
import { EmailService } from '../service/email-service.js';
import { Constants } from '../../../basic/constants.js';
import { Constants } from '@certd/lib-server';
export class SmsCodeReq {
@Rule(RuleType.number().required())
phoneCode: number;
@@ -1,7 +1,7 @@
import { Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
import { BaseController } from '../../../basic/base-controller.js';
import { BaseController } from '@certd/lib-server';
import { EmailService } from '../service/email-service.js';
import { Constants } from '../../../basic/constants.js';
import { Constants } from '@certd/lib-server';
/**
*/
@@ -1,7 +1,7 @@
import { MidwayEnvironmentService } from '@midwayjs/core';
import { Controller, Get, Inject, Provide } from '@midwayjs/core';
import { logger } from '../../../utils/logger.js';
import { Constants } from '../../../basic/constants.js';
import { logger } from '@certd/pipeline';
import { Constants } from '@certd/lib-server';
@Provide()
@Controller('/home')
@@ -1,8 +1,8 @@
import { Config, 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 { SysInstallInfo, SysPublicSettings, SysSiteInfo } from '../../system/service/models.js';
import { BaseController } from '@certd/lib-server';
import { Constants } from '@certd/lib-server';
import { SysSettingsService } from '@certd/lib-server';
import { SysInstallInfo, SysPublicSettings, SysSiteInfo } from '@certd/lib-server';
import { AppKey } from '@certd/pipeline';
/**
@@ -3,7 +3,7 @@ import type { EmailSend } from '@certd/pipeline';
import { IEmailService, isPlus } from '@certd/pipeline';
import nodemailer from 'nodemailer';
import type SMTPConnection from 'nodemailer/lib/smtp-connection';
import { logger } from '../../../utils/logger.js';
import { logger } from '@certd/pipeline';
import { UserSettingsService } from '../../mine/service/user-settings-service.js';
import { PlusService } from './plus-service.js';
@@ -1,8 +1,8 @@
import { Config, Init, Inject, Provide, Scope, ScopeEnum } from '@midwayjs/core';
import { SysSettingsService } from '../../system/service/sys-settings-service.js';
import { SysInstallInfo, SysLicenseInfo } from '../../system/service/models.js';
import { SysSettingsService } from '@certd/lib-server';
import { SysInstallInfo, SysLicenseInfo } from '@certd/lib-server';
import { AppKey, http, PlusRequestService, verify } from '@certd/pipeline';
import { logger } from '../../../utils/logger.js';
import { logger } from '@certd/pipeline';
@Provide()
@Scope(ScopeEnum.Singleton)
@@ -1,14 +1,7 @@
import {
Body,
Controller,
Inject,
Post,
Provide,
ALL,
} from '@midwayjs/core';
import { Body, Controller, Inject, Post, Provide, ALL } from '@midwayjs/core';
import { LoginService } from '../service/login-service.js';
import { BaseController } from '../../../basic/base-controller.js';
import { Constants } from '../../../basic/constants.js';
import { BaseController } from '@certd/lib-server';
import { Constants } from '@certd/lib-server';
/**
*/
@@ -20,7 +13,7 @@ export class LoginController extends BaseController {
@Post('/login', { summary: Constants.per.guest })
public async login(
@Body(ALL)
user
user: any
) {
const token = await this.loginService.login(user);
@@ -1,16 +1,9 @@
import {
ALL,
Body,
Controller,
Inject,
Post,
Provide,
} from '@midwayjs/core';
import { BaseController } from '../../../basic/base-controller.js';
import { Constants } from '../../../basic/constants.js';
import { ALL, Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
import { BaseController } from '@certd/lib-server';
import { Constants } from '@certd/lib-server';
import { UserService } from '../../authority/service/user-service.js';
import { UserEntity } from '../../authority/entity/user.js';
import { SysSettingsService } from '../../system/service/sys-settings-service.js';
import { SysSettingsService } from '@certd/lib-server';
/**
*/
@@ -1,11 +1,11 @@
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 { CommonException } from '@certd/lib-server';
import { RoleService } from '../../authority/service/role-service.js';
import { UserEntity } from '../../authority/entity/user.js';
import { SysSettingsService } from '../../system/service/sys-settings-service.js';
import { SysPrivateSettings } from '../../system/service/models.js';
import { SysSettingsService } from '@certd/lib-server';
import { SysPrivateSettings } from '@certd/lib-server';
/**
* 系统用户
@@ -1,6 +1,6 @@
import { ALL, Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
import { BaseController } from '../../../basic/base-controller.js';
import { Constants } from '../../../basic/constants.js';
import { BaseController } from '@certd/lib-server';
import { Constants } from '@certd/lib-server';
import { UserService } from '../../authority/service/user-service.js';
import { getPlusInfo } from '@certd/pipeline';
import { RoleService } from '../../authority/service/role-service.js';
@@ -7,8 +7,8 @@ import {
Provide,
Query,
} from '@midwayjs/core';
import { CrudController } from '../../../basic/crud-controller.js';
import { Constants } from '../../../basic/constants.js';
import { CrudController } from '@certd/lib-server';
import { Constants } from '@certd/lib-server';
import { UserSettingsService } from '../service/user-settings-service.js';
import { UserSettingsEntity } from '../entity/user-settings.js';
@@ -1,7 +1,7 @@
import { Provide, Scope, ScopeEnum } from '@midwayjs/core';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { Repository } from 'typeorm';
import { BaseService } from '../../../basic/base-service.js';
import { BaseService } from '@certd/lib-server';
import { UserSettingsEntity } from '../entity/user-settings.js';
/**
@@ -1,7 +1,7 @@
import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
import { CrudController } from '../../../basic/crud-controller.js';
import { CrudController } from '@certd/lib-server';
import { AccessService } from '../service/access-service.js';
import { Constants } from '../../../basic/constants.js';
import { Constants } from '@certd/lib-server';
/**
* 授权
@@ -12,7 +12,7 @@ export class AccessController extends CrudController<AccessService> {
@Inject()
service: AccessService;
getService() {
getService(): AccessService {
return this.service;
}
@@ -1,7 +1,7 @@
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';
import { BaseController } from '@certd/lib-server';
import { Constants } from '@certd/lib-server';
/**
* 插件
@@ -1,5 +1,5 @@
import { ALL, Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
import { Constants } from '../../../basic/constants.js';
import { Constants } from '@certd/lib-server';
import {
AccessRequestHandleReq,
http,
@@ -12,7 +12,7 @@ import {
TaskInstanceContext,
utils,
} from '@certd/pipeline';
import { BaseController } from '../../../basic/base-controller.js';
import { BaseController } from '@certd/lib-server';
import { AccessService } from '../service/access-service.js';
import { EmailService } from '../../basic/service/email-service.js';
@@ -1,18 +1,15 @@
import { ALL, Body, Controller, Get, Inject, Post, Provide, Query } from '@midwayjs/core';
import { CrudController } from '../../../basic/crud-controller.js';
import { CommonException, Constants, CrudController, PermissionException } from '@certd/lib-server';
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.js';
import { logger } from '@certd/pipeline';
import { AuthService } from '../../authority/service/auth-service.js';
import { SysSettingsService } from '../../system/service/sys-settings-service.js';
import { SysSettingsService } from '@certd/lib-server';
/**
* 证书
@@ -33,7 +30,7 @@ export class HistoryController extends CrudController<HistoryService> {
@Inject()
sysSettingsService: SysSettingsService;
getService() {
getService(): HistoryService {
return this.service;
}
@@ -1,11 +1,11 @@
import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
import { CrudController } from '../../../basic/crud-controller.js';
import { CrudController } from '@certd/lib-server';
import { PipelineService } from '../service/pipeline-service.js';
import { PipelineEntity } from '../entity/pipeline.js';
import { Constants } from '../../../basic/constants.js';
import { Constants } from '@certd/lib-server';
import { HistoryService } from '../service/history-service.js';
import { AuthService } from '../../authority/service/auth-service.js';
import { SysSettingsService } from '../../system/service/sys-settings-service.js';
import { SysSettingsService } from '@certd/lib-server';
/**
* 证书
@@ -1,7 +1,7 @@
import { ALL, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
import { BaseController } from '../../../basic/base-controller.js';
import { BaseController } from '@certd/lib-server';
import { PluginService } from '../service/plugin-service.js';
import { Constants } from '../../../basic/constants.js';
import { Constants } from '@certd/lib-server';
/**
* 插件
@@ -1,11 +1,11 @@
import { Inject, Provide, Scope, ScopeEnum } from '@midwayjs/core';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { Repository } from 'typeorm';
import { BaseService } from '../../../basic/base-service.js';
import { BaseService } from '@certd/lib-server';
import { AccessEntity } from '../entity/access.js';
import { AccessDefine, accessRegistry, IAccessService, newAccess } from '@certd/pipeline';
import { EncryptService } from './encrypt-service.js';
import { ValidateException } from '../../../basic/exception/validation-exception.js';
import { ValidateException } from '@certd/lib-server';
/**
* 授权
@@ -1,7 +1,7 @@
import { Init, Inject, Provide, Scope, ScopeEnum } from '@midwayjs/core';
import crypto from 'crypto';
import { SysSettingsService } from '../../system/service/sys-settings-service.js';
import { SysPrivateSettings } from '../../system/service/models.js';
import { SysSettingsService } from '@certd/lib-server';
import { SysPrivateSettings } from '@certd/lib-server';
/**
* 授权
@@ -1,7 +1,7 @@
import { Provide, Scope, ScopeEnum } from '@midwayjs/core';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { In, Repository } from 'typeorm';
import { BaseService } from '../../../basic/base-service.js';
import { BaseService } from '@certd/lib-server';
import { HistoryLogEntity } from '../entity/history-log.js';
/**
@@ -1,14 +1,14 @@
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.js';
import { BaseService } from '@certd/lib-server';
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.js';
import { logger } from '@certd/pipeline';
/**
* 证书申请
@@ -1,7 +1,7 @@
import { Config, Inject, Provide, Scope, ScopeEnum, sleep } from '@midwayjs/core';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { In, Repository } from 'typeorm';
import { BaseService } from '../../../basic/base-service.js';
import { BaseService } from '@certd/lib-server';
import { PipelineEntity } from '../entity/pipeline.js';
import { PipelineDetail } from '../entity/vo/pipeline-detail.js';
import { Executor, isPlus, Pipeline, ResultType, RunHistory, UserInfo } from '@certd/pipeline';
@@ -13,9 +13,9 @@ 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 { logger } from '@certd/pipeline';
import { EmailService } from '../../basic/service/email-service.js';
import { NeedVIPException } from '../../../basic/exception/vip-exception.js';
import { NeedVIPException } from '@certd/lib-server';
import { UserService } from '../../authority/service/user-service.js';
const runningTasks: Map<string | number, Executor> = new Map();
@@ -1,7 +1,7 @@
import { Provide, Scope, ScopeEnum } from '@midwayjs/core';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { In, Repository } from 'typeorm';
import { BaseService } from '../../../basic/base-service.js';
import { BaseService } from '@certd/lib-server';
import { StorageEntity } from '../entity/storage.js';
/**
@@ -1,9 +1,9 @@
import { ALL, Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
import { SysSettingsService } from '../service/sys-settings-service.js';
import { BaseController } from '../../../basic/base-controller.js';
import { SysSettingsService } from '@certd/lib-server';
import { BaseController } from '@certd/lib-server';
import { AppKey } from '@certd/pipeline';
import { SysInstallInfo } from '../service/models.js';
import { logger } from '../../../utils/logger.js';
import { SysInstallInfo } from '@certd/lib-server';
import { logger } from '@certd/pipeline';
import { PlusService } from '../../basic/service/plus-service.js';
/**
@@ -0,0 +1,55 @@
import { ALL, Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
import { SysSettingsService } from '@certd/lib-server';
import { BaseController } from '@certd/lib-server';
import { AppKey } from '@certd/pipeline';
import { SysInstallInfo } from '@certd/lib-server';
import { logger } from '@certd/pipeline';
import { PlusService } from '../../basic/service/plus-service.js';
/**
*/
@Provide()
@Controller('/api/sys/site')
export class SysPlusController extends BaseController {
@Inject()
sysSettingsService: SysSettingsService;
@Inject()
plusService: PlusService;
@Post('/active', { summary: 'sys:settings:edit' })
async active(@Body(ALL) body) {
const { code } = body;
const installInfo: SysInstallInfo = await this.sysSettingsService.getSetting(SysInstallInfo);
const siteId = installInfo.siteId;
const formData = {
appKey: AppKey,
code,
subjectId: siteId,
};
const res: any = await this.plusService.active(formData);
if (res.code > 0) {
logger.error('激活失败', res.message);
return this.fail(res.message, 1);
}
const license = res.data.license;
await this.plusService.updateLicense(license);
return this.ok(true);
}
@Post('/bindUrl', { summary: 'sys:settings:edit' })
async bindUrl(@Body(ALL) body: { url: string }) {
const { url } = body;
const installInfo: SysInstallInfo = await this.sysSettingsService.getSetting(SysInstallInfo);
await this.plusService.bindUrl(installInfo.siteId, url);
installInfo.bindUrl = url;
await this.sysSettingsService.saveSetting(installInfo);
return this.ok(true);
}
}
@@ -1,8 +1,8 @@
import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
import { CrudController } from '../../../basic/crud-controller.js';
import { SysSettingsService } from '../service/sys-settings-service.js';
import { CrudController } from '@certd/lib-server';
import { SysSettingsService } from '@certd/lib-server';
import { SysSettingsEntity } from '../entity/sys-settings.js';
import { SysPublicSettings } from '../service/models.js';
import { SysPublicSettings } from '@certd/lib-server';
import * as _ from 'lodash-es';
import { PipelineService } from '../../pipeline/service/pipeline-service.js';
@@ -1,54 +0,0 @@
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;
managerOtherUserPipeline = false;
// triggerOnStartup = false;
}
export class SysPrivateSettings extends BaseSettings {
static __title__ = '系统私有设置';
static __access__ = 'private';
static __key__ = 'sys.private';
jwtKey?: string;
encryptSecret?: string;
}
export class SysInstallInfo extends BaseSettings {
static __title__ = '系统安装信息';
static __key__ = 'sys.install';
static __access__ = 'private';
installTime: number;
siteId?: string;
bindUserId?: number;
bindUrl?: string;
accountServerBaseUrl?: string;
appKey?: string;
}
export class SysLicenseInfo extends BaseSettings {
static __title__ = '授权许可信息';
static __key__ = 'sys.license';
static __access__ = 'private';
license?: string;
}
export class SysSiteInfo extends BaseSettings {
static __title__ = '站点信息';
static __key__ = 'sys.site';
static __access__ = 'public';
TITLE?: string;
SLOGAN?: string;
LOGO?: string;
ICP_NO?: string;
}
@@ -1,131 +0,0 @@
import { Inject, Provide, Scope, ScopeEnum } from '@midwayjs/core';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { Repository } from 'typeorm';
import { BaseService } from '../../../basic/base-service.js';
import { SysSettingsEntity } from '../entity/sys-settings.js';
import { CacheManager } from '@midwayjs/cache';
import { BaseSettings, SysPublicSettings } from './models.js';
import * as _ from 'lodash-es';
export type SysPrivateSettings = NonNullable<unknown>;
/**
* 设置
*/
@Provide()
@Scope(ScopeEnum.Singleton)
export class SysSettingsService extends BaseService<SysSettingsEntity> {
@InjectEntityModel(SysSettingsEntity)
repository: Repository<SysSettingsEntity>;
@Inject()
cache: CacheManager; // 依赖注入CacheManager
getRepository() {
return this.repository;
}
async getById(id: any): Promise<SysSettingsEntity | null> {
const entity = await this.info(id);
if (!entity) {
return null;
}
const setting = JSON.parse(entity.setting);
return {
id: entity.id,
...setting,
};
}
async getByKey(key: string): Promise<SysSettingsEntity | null> {
if (!key) {
return null;
}
return await this.repository.findOne({
where: {
key,
},
});
}
async getSettingByKey(key: string): Promise<any | null> {
const entity = await this.getByKey(key);
if (!entity) {
return null;
}
return JSON.parse(entity.setting);
}
async save(bean: SysSettingsEntity) {
const entity = await this.repository.findOne({
where: {
key: bean.key,
},
});
if (entity) {
entity.setting = bean.setting;
await this.repository.save(entity);
} else {
bean.title = bean.key;
await this.repository.save(bean);
}
}
async getSetting<T>(type: any): Promise<T> {
const key = type.__key__;
const cacheKey = type.getCacheKey();
const settings: T = await this.cache.get(cacheKey);
if (settings) {
return settings;
}
let newSetting: T = new type();
const savedSettings = await this.getSettingByKey(key);
newSetting = _.merge(newSetting, savedSettings);
await this.cache.set(cacheKey, newSetting);
return newSetting;
}
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) {
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);
}
await this.cache.set(cacheKey, bean);
}
async getPublicSettings(): Promise<SysPublicSettings> {
return await this.getSetting(SysPublicSettings);
}
async savePublicSettings(bean: SysPublicSettings) {
await this.saveSetting(bean);
}
async savePrivateSettings(bean: SysPrivateSettings) {
this.saveSetting(bean);
}
async updateByKey(key: string, setting: any) {
const entity = await this.getByKey(key);
if (entity) {
entity.setting = JSON.stringify(setting);
await this.repository.save(entity);
} else {
throw new Error('该设置不存在');
}
await this.cache.del(`settings.${key}`);
}
}
@@ -1,7 +1,7 @@
import { AbstractTaskPlugin, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput, TaskOutput } from '@certd/pipeline';
import { CertInfo, CertReader } from '@certd/plugin-cert';
import * as fs from 'fs';
import { Constants } from '../../../../basic/constants.js';
import { Constants } from '@certd/lib-server';
import path from 'path';
@IsTaskPlugin({
@@ -39,7 +39,7 @@ export class CustomScriptPlugin extends AbstractTaskPlugin {
name: 'pi-output-selector',
from: ['CertApply', 'CertApplyLego'],
},
required: true,
required: false,
})
cert!: CertInfo;
@@ -1,12 +0,0 @@
import log4js from 'log4js';
import path from 'path';
const level = process.env.NODE_ENV === 'development' ? 'debug' : 'info';
const filename = path.join('/logs/server.log');
log4js.configure({
appenders: {
std: { type: 'stdout', level: 'debug' },
file: { type: 'file', pattern: 'yyyy-MM-dd', daysToKeep: 3, filename },
},
categories: { default: { appenders: ['std'], level } },
});
export const logger = log4js.getLogger('server');
+9 -9
View File
@@ -1,6 +1,6 @@
const numbers = '0123456789';
const letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
const specials = '~!@#$%^*()_+-=[]{}|;:,./<>?';
const numbers = "0123456789";
const letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
const specials = "~!@#$%^*()_+-=[]{}|;:,./<>?";
/**
* Generate random string
@@ -11,24 +11,24 @@ function randomStr(length, options?) {
length || (length = 8);
options || (options = {});
let chars = '';
let result = '';
let chars = "";
let result = "";
if (options === true) {
chars = numbers + letters;
} else if (typeof options === 'string') {
} else if (typeof options === "string") {
chars = options;
} else {
if (options.numbers !== false) {
chars += typeof options.numbers === 'string' ? options.numbers : numbers;
chars += typeof options.numbers === "string" ? options.numbers : numbers;
}
if (options.letters !== false) {
chars += typeof options.letters === 'string' ? options.letters : letters;
chars += typeof options.letters === "string" ? options.letters : letters;
}
if (options.specials) {
chars += typeof options.specials === 'string' ? options.specials : specials;
chars += typeof options.specials === "string" ? options.specials : specials;
}
}