feat: 很奇怪,请求会挂

This commit is contained in:
mozzie 2023-10-10 22:10:22 +08:00
parent 3ba9704741
commit ac998b9cc7
16 changed files with 46 additions and 38 deletions

View File

@ -1,12 +1,12 @@
import { Controller } from '@nestjs/common';
import { EventPattern } from '@nestjs/microservices';
import { EventPattern, MessagePattern } from '@nestjs/microservices';
import { getFileExt } from './app.util';
import { clientConfig } from './app.config';
import { MinioOSS } from '@tavi/oss';
@Controller()
export class AppController {
@EventPattern('report-upload-image')
@MessagePattern('report-upload-image')
async uploadImageHandler({ buffer, originalName }) {
const objectName = Date.now() + '.' + getFileExt(originalName);
const { bucketName, ...config } = clientConfig;

View File

@ -13,6 +13,7 @@ async function bootstrap() {
queueOptions: {
durable: false,
},
maxConnectionAttempts: 10,
},
},
);

View File

@ -1,4 +1,4 @@
import { EventPattern } from '@nestjs/microservices';
import { EventPattern, MessagePattern } from '@nestjs/microservices';
import { RedisService } from './redis/redis.service';
import { ConfigService } from '@nestjs/config';
import { Controller } from '@nestjs/common';
@ -16,7 +16,7 @@ export class AppController {
* token签发,
* @description redis的EXcookie的maxAge(ms)jwt的expiresIn
*/
@EventPattern('cert.token.create')
@MessagePattern('cert.token.create')
async createToken(payload) {
const { username } = payload;
const token = await this.jwtService.sign(payload);
@ -28,7 +28,7 @@ export class AppController {
* token有效性 && token
* @description guard对请求token进行拦截token是否合法&redis中
*/
@EventPattern('cert.token.decode')
@MessagePattern('cert.token.decode')
async decodeToken(
token: string,
): Promise<{ tokenValid: boolean; payload: unknown; error?: unknown }> {
@ -47,7 +47,7 @@ export class AppController {
* token在cookie中存储的key
* @description cookie的maxAge单位是毫秒cookie使用expires需要 x1000
*/
@EventPattern('cert.token.config')
@MessagePattern('cert.token.config')
async tokenConfig() {
return {
tokenResignIn: this.configService.get('TOKEN_RESIGN_IN'),
@ -56,7 +56,7 @@ export class AppController {
};
}
@EventPattern('cert.token.deprecated')
@MessagePattern('cert.token.deprecated')
async removeToken(payload) {
const { username } = payload;
console.log('username', username);

View File

@ -13,6 +13,7 @@ async function bootstrap() {
queueOptions: {
durable: false,
},
maxConnectionAttempts: 10,
},
},
);

View File

@ -1,6 +1,6 @@
import { Controller } from '@nestjs/common';
import { AppService } from './app.service';
import { EventPattern } from '@nestjs/microservices';
import { EventPattern, MessagePattern } from '@nestjs/microservices';
import { RbacService } from './rbac/rbac.service';
@Controller()
@ -10,59 +10,59 @@ export class AppController {
private readonly rbacService: RbacService,
) {}
@EventPattern('cert.authorize')
@MessagePattern('cert.authorize')
async authorize(payload) {
console.log('获取user的token进行payload权限的验证', payload);
return false;
}
@EventPattern('cert.init.role.admin')
@MessagePattern('cert.init.role.admin')
async initRole() {
await this.rbacService.initSuperAdminRole();
await this.rbacService.initSuperAdminAccount();
}
@EventPattern('cert.create.role')
@MessagePattern('cert.create.role')
async createRole(payload) {
return await this.rbacService.createRole(payload);
}
@EventPattern('cert.remove.role')
@MessagePattern('cert.remove.role')
async removeRole(payload) {
return await this.rbacService.removeRole(payload);
}
@EventPattern('cert.find.role.all')
@MessagePattern('cert.find.role.all')
async findAllRole() {
return await this.rbacService.findAllRole();
}
@EventPattern('cert.init.permission.resource')
@MessagePattern('cert.init.permission.resource')
async initPermission(payload) {
await this.rbacService.initPermission(payload);
}
@EventPattern('cert.find.role.permission')
@MessagePattern('cert.find.role.permission')
async findRolePermission(payload) {
return await this.rbacService.findRolePermission(payload);
}
@EventPattern('cert.update.role.permissions')
@MessagePattern('cert.update.role.permissions')
async updateRolePermissions(payload) {
return await this.rbacService.updateRolePermissions(payload);
}
@EventPattern('cert.update.role')
@MessagePattern('cert.update.role')
async updateRole(payload) {
return await this.rbacService.updateRole(payload);
}
@EventPattern('cert.find.all.user')
@MessagePattern('cert.find.all.user')
async findAllUser() {
return await this.rbacService.findAllUser();
}
@EventPattern('cert.role.authorize')
@MessagePattern('cert.role.authorize')
async roleAuthorize({ user, url }) {
const allow = await this.rbacService.roleAuthorize(user, url);
return { allow };

View File

@ -13,6 +13,7 @@ async function bootstrap() {
queueOptions: {
durable: false,
},
maxConnectionAttempts: 10,
},
},
);

View File

@ -1,5 +1,5 @@
import { Controller } from '@nestjs/common';
import { EventPattern } from '@nestjs/microservices';
import { EventPattern, MessagePattern } from '@nestjs/microservices';
import { UserService } from './user.service';
import { BcryptService } from '../bcrypt/bcrypt.service';
@ -12,7 +12,7 @@ export class UserController {
/**
*
*/
@EventPattern('cert.user.account')
@MessagePattern('cert.user.account')
async findUser(
payload,
): Promise<{ isLegal: boolean; msg?: string; data?: any }> {
@ -28,22 +28,22 @@ export class UserController {
return { isLegal: true, data: user };
}
@EventPattern('cert.user.encrypt')
@MessagePattern('cert.user.encrypt')
async encrypt(plainText: string) {
return await this.bcryptService.hashPassword(plainText);
}
@EventPattern('cert.encrypt.compare')
@MessagePattern('cert.encrypt.compare')
async compare(plainText: string, hash: string) {
return await this.bcryptService.comparePassword(plainText, hash);
}
@EventPattern('cert.user.create')
@MessagePattern('cert.user.create')
async createUser(payload) {
return await this.userService.create(payload);
}
@EventPattern('cert.user.update')
@MessagePattern('cert.user.update')
async updateUser(payload) {
const { password, ...rest } = payload;
const updateFields = password
@ -52,12 +52,12 @@ export class UserController {
return await this.userService.update(updateFields);
}
@EventPattern('cert.user.delete')
@MessagePattern('cert.user.delete')
async deleteUser(userIds: number[]) {
return await this.userService.delete(userIds);
}
@EventPattern('cert.user.find.annotator')
@MessagePattern('cert.user.find.annotator')
async findAnnotators() {
const annotators = await this.userService.findAnnotators();
return { data: annotators };

View File

@ -28,6 +28,7 @@ import { AdminModule } from './admin/admin.module';
queueOptions: {
durable: false,
},
maxConnectionAttempts: 10,
},
},
]),

View File

@ -1,6 +1,6 @@
import { Controller } from '@nestjs/common';
import { AppService } from './app.service';
import { EventPattern } from '@nestjs/microservices';
import { EventPattern, MessagePattern } from '@nestjs/microservices';
import { ConfigService } from '@nestjs/config';
import axios from 'axios';
@ -75,7 +75,7 @@ export class AppController {
private readonly configService: ConfigService,
) {}
@EventPattern('dicom.find')
@MessagePattern('dicom.find')
async findDicoms() {
const pacsUrl = this.configService.get('PACS_URL');
try {
@ -118,7 +118,7 @@ export class AppController {
}
}
@EventPattern('dicom.archive.url')
@MessagePattern('dicom.archive.url')
async archiveUrl({ ID, Type }: { ID: string; Type: string }) {
const pacsUrl = this.configService.get('PACS_URL');
const mapping = {

View File

@ -13,6 +13,7 @@ async function bootstrap() {
queueOptions: {
durable: false,
},
maxConnectionAttempts: 10,
},
},
);

View File

@ -1,17 +1,17 @@
import { Controller } from '@nestjs/common';
import { AppService } from './app.service';
import { EventPattern } from '@nestjs/microservices';
import { EventPattern, MessagePattern } from '@nestjs/microservices';
@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}
@EventPattern('archive.task.create')
@MessagePattern('archive.task.create')
async createArchiveTask(payload) {
return await this.appService.createArchiveTask(payload);
}
@EventPattern('archive.task.find')
@MessagePattern('archive.task.find')
async findArchiveTask(payload) {
return await this.appService.findArchiveTask(payload);
}

View File

@ -13,6 +13,7 @@ async function bootstrap() {
queueOptions: {
durable: false,
},
maxConnectionAttempts: 10,
},
},
);

View File

@ -1,6 +1,6 @@
import { Controller } from '@nestjs/common';
import { AppService } from './app.service';
import { EventPattern } from '@nestjs/microservices';
import { EventPattern, MessagePattern } from '@nestjs/microservices';
import * as dayjs from 'dayjs';
import { SymmetricCrypto } from '@tavi/util';
@ -16,7 +16,7 @@ interface UserSignLoggerDto {
export class AppController {
constructor(private readonly appService: AppService) {}
@EventPattern('logger.user.signIn')
@MessagePattern('logger.user.signIn')
async userSignIn(payload: UserSignLoggerDto) {
const dateTime = dayjs().format('YYYY-MM-DD HH:mm:ss');
const { finger2, ...rest } = payload;
@ -25,12 +25,12 @@ export class AppController {
return 1;
}
@EventPattern('logger.save')
@MessagePattern('logger.save')
async saveLogger(payload: UserSignLoggerDto) {
return 'ok';
}
@EventPattern('alg.test')
@MessagePattern('alg.test')
async algTest(payload) {
console.log('来自: alg.test', payload);
return payload;

View File

@ -13,6 +13,7 @@ async function bootstrap() {
queueOptions: {
durable: false,
},
maxConnectionAttempts: 10,
},
},
);

View File

@ -14,7 +14,7 @@ async getHello(): Promise<any> {
}
// 服务
@EventPattern('sum')
@MessagePattern('sum')
sum(data: number[]): number {
return (data || []).reduce((a, b) => a + b);
}

View File

@ -11,6 +11,7 @@ services:
environment:
- RABBITMQ_DEFAULT_USER=guest
- RABBITMQ_DEFAULT_PASS=guest
- TZ=Asia/Shanghai # 将此值设置为您所在的时区
# volumes:
# - rabbitmq-data:/var/lib/rabbitmq
command: >