Эх сурвалжийг харах

修复监视器,支持新建多个监视器实例

zhusiqing 3 жил өмнө
parent
commit
3ea62df57f

+ 5 - 1
src/app.ts

@@ -3,7 +3,8 @@ import Koa, { Context, DefaultState } from 'koa';
 // 路由
 import router from './router';
 // 美化控制台
-import consola from 'consola/dist/consola';
+// import consola from 'consola/dist/consola';
+import consola from 'consola';
 // 解析post的body体
 import bodyParser from 'koa-bodyparser';
 // 部分安全相关
@@ -12,7 +13,9 @@ import helmet from 'koa-helmet';
 import koaStatic from 'koa-static';
 // 请求转发
 import koaProxy from 'koa-proxies';
+// 导入配置文件
 import config from '@config';
+// 导入中间件
 import redisMiddleware from './middlewares/redis';
 import limitMiddleware from './middlewares/limit';
 import logsMiddleware from './middlewares/logs';
@@ -50,6 +53,7 @@ app.use(limitMiddleware());
 app.use(sessionMiddleware(app))
 // auth
 // app.use(authMiddleware())
+
 // 请求转发
 app.use(koaProxy('/proxy', {
   target: 'https://demo.com',

+ 2 - 2
src/utils/cipher.ts

@@ -5,14 +5,14 @@ const algorithm = 'aes-192-cbc';
 const salt = '123';
 const key = scryptSync(config.secrestKey, salt, 24);
 const iv = Buffer.alloc(16, '11');
-
+// 加密
 export const cipher = (data: string) => {
   const cipher = createCipheriv(algorithm, key, iv);
   let enc = cipher.update(data, 'utf8', 'hex');
   enc += cipher.final('hex');
   return enc;
 };
-
+// 解密
 export const decipher = (data: string) => {
   const decipher = createDecipheriv(algorithm, key, iv);
   let dec = decipher.update(data, 'hex', 'utf8');

+ 2 - 2
src/utils/observer.ts

@@ -1,6 +1,6 @@
 const objToString = (param: any) => Object.prototype.toString.call(param);
 
-class Observer {
+export class Observer {
   private handle: Map<string, [Function?]>
   constructor() {
     this.handle = new Map()
@@ -23,7 +23,7 @@ class Observer {
     this.handle.get(type)?.push(callback);
   };
   // 触发
-  emit (type = '', ...params: []) {
+  emit (type = '', ...params) {
     if (typeof type !== 'string') {
       const msg = `emit type must is string, now is ${objToString(type)}`;
       throw new Error(msg);