1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- import { All, Controller, Get, Inject, Put } from '@midwayjs/core';
- import { Context } from '@midwayjs/koa';
- import { ProxyService } from '../service/proxy.service';
- import { SingleSignOnService } from '../service/singleSignOn.service';
- import { PermissionService } from '../service/permission.service';
- import { PemService } from '../service/pem.service';
- import SensitiveWordTool from 'sensitive-word-tool';
- import { EsDictService } from '../service/esDict.service';
- @Controller('/cxyy')
- export class HomeController {
- @Inject()
- ctx: Context;
- @Inject()
- service: ProxyService;
- @Inject()
- singleSignOnService: SingleSignOnService;
- @Inject()
- permissionService: PermissionService;
- @Inject()
- pemService: PemService;
- @Inject()
- esDict: EsDictService;
- @Get('/')
- async home(): Promise<string> {
- return 'proxy starting....';
- }
- @Get('/test')
- async test(): Promise<string> {
- const sensitiveWordTool = new SensitiveWordTool({
- useDefaultWords: true,
- });
- const str = '<p>在群里,我们不能讨论有关于党,d,国家,gj,政府,zf,不能建政,jz,不能搞黄色,淫秽色情</p>';
- const res = sensitiveWordTool.filter(str);
- return res;
- }
- @Get('/initKeys')
- async makePairCrypto() {
- await this.pemService.createKeys();
- return 'makePairCrypto';
- }
- /**
- * es请求远程字典内容, 约1分钟来同步一次
- * @returns 返回扩充字典内容
- */
- @Get('/es_dict')
- async getEsDict() {
- const result = await this.esDict.getDictContent();
- const ranStr = this.esDict.randomStr();
- try {
- this.ctx.response.etag = ranStr;
- this.ctx.response.lastModified = new Date();
- } catch (error) {
- console.log(error);
- }
- return result;
- }
- @All('/**')
- async proxy() {
- // TODO:检查请求是否在白名单
- const inWhiteList = this.singleSignOnService.inWhiteList();
- if (!inWhiteList) {
- // 不在白名单上则检查登录
- await this.singleSignOnService.index();
- // 暂时不要检查权限
- // await this.permissionService.index();
- // 通过检查(不报异常中断程序)即可以发送请求
- return await this.service.index();
- }
- // 3.发送请求
- return await this.service.index();
- }
- }
|