22 lines
657 B
TypeScript
22 lines
657 B
TypeScript
import { Controller } from '@nestjs/common';
|
|
import { EventPattern } 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')
|
|
async uploadImageHandler({ buffer, originalName }) {
|
|
const objectName = Date.now() + '.' + getFileExt(originalName);
|
|
const { bucketName, ...config } = clientConfig;
|
|
const minio = new MinioOSS(config);
|
|
const res = await minio.put({
|
|
file: buffer,
|
|
objectName,
|
|
bucketName,
|
|
});
|
|
return { res, objectName };
|
|
}
|
|
}
|