Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
type: LoginPayloadDto,
description: 'User info with access token',
})
async userLogin(
@Body() userLoginDto: UserLoginDto,
): Promise {
const userEntity = await this.authService.validateUser(userLoginDto);
const token = await this.authService.createToken(userEntity);
return new LoginPayloadDto(userEntity.toDto(), token);
}
@Post('register')
@HttpCode(HttpStatus.OK)
@ApiOkResponse({ type: UserDto, description: 'Successfully Registered' })
@ApiImplicitFile({ name: 'avatar', required: true })
@UseInterceptors(FileInterceptor('avatar'))
async userRegister(
@Body() userRegisterDto: UserRegisterDto,
@UploadedFile() file: IFile,
): Promise {
const createdUser = await this.userService.createUser(
userRegisterDto,
file,
);
return createdUser.toDto();
}
@Get('me')
@HttpCode(HttpStatus.OK)
@UseGuards(AuthGuard)
import {MediaUploadDto} from './dto/media-upload.dto';
@ApiUseTags('media')
@ApiBearerAuth()
@UseGuards(AuthGuard('jwt'))
@Controller('media')
export class MediaController {
private logger = new AppLogger(MediaController.name);
constructor(@Inject(AWS_CON_TOKEN) private readonly awsConnection) {}
@Post('upload')
@UseInterceptors(FileInterceptor('media'))
@ApiConsumes('multipart/form-data')
@ApiImplicitFile({ name: 'media', required: true, description: 'Any media file' })
@ApiResponse({ status: 200, description: 'OK', type: MediaUploadDto })
public uploadFile(@UploadedFile() file) {
return file;
}
@MessagePattern({ cmd: MEDIA_CMD_DELETE })
public async onMediaDelete(homeMedia: HomeMediaEntity): Promise {
const key = new URL(homeMedia.url).pathname.substring(1);
this.logger.debug(`[onMediaDelete] Going to remove key ${key} from bucket ${config.aws.s3.bucket_name}`);
const s3 = new S3();
s3.deleteObject({
Bucket: config.aws.s3.bucket_name,
Key: key
}).promise().then(() => {
this.logger.debug(`[onMediaDelete] item with key: ${key} removed from bucket`);
}).catch(() => {
import { resolve } from 'path';
import { UploadActionType, StorageType } from '../../common/aspects/enum';
import { ImportService } from '../../common/services/import.service';
import { Logger } from '../../common/lib/logger';
import { Qiniu } from '../../common/lib/qiniu';
@Api('storage')
@ApiUseTags('storage')
@ApiBearerAuth()
@UseGuards(AuthGuard())
export class StorageController {
constructor(private readonly importService: ImportService) { }
@Post()
@ApiConsumes('multipart/form-data')
@ApiImplicitFile({ name: 'file', required: true })
async upload(@Req() req, @Res() res) {
const files = req.raw.files;
if (Object.keys(files).length == 0) {
throw new BadRequestException('没有上传任何文件');
}
const file = files.file;
const action = req.raw.body.action || UploadActionType.UPLOAD;
switch (action) {
case UploadActionType.IMPORT:
const target = req.raw.body.target;
if (!target) throw new BadRequestException('参数 target 缺失');
Logger.log(target, 'StorageController::import');