first commit
This commit is contained in:
55
src/modules/media/media.controller.ts
Normal file
55
src/modules/media/media.controller.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import {
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
Param,
|
||||
Post,
|
||||
Query,
|
||||
Req,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiConsumes, ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||
import { FastifyRequest } from 'fastify';
|
||||
import { CurrentUser } from '../../common/decorators/current-user.decorator';
|
||||
import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard';
|
||||
import { MediaService } from './media.service';
|
||||
|
||||
@ApiTags('media')
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Controller('media')
|
||||
export class MediaController {
|
||||
constructor(private readonly mediaService: MediaService) {}
|
||||
|
||||
@Post('upload')
|
||||
@ApiOperation({ summary: 'Upload photo or video' })
|
||||
@ApiConsumes('multipart/form-data')
|
||||
async upload(
|
||||
@CurrentUser('id') userId: string,
|
||||
@Req() req: FastifyRequest,
|
||||
@Query('type') type: 'photo' | 'video' = 'photo',
|
||||
) {
|
||||
const data = await (req as any).file();
|
||||
if (!data) {
|
||||
throw new Error('No file provided');
|
||||
}
|
||||
const buffer = await data.toBuffer();
|
||||
return this.mediaService.uploadMedia(
|
||||
userId,
|
||||
{ buffer, originalname: data.filename, mimetype: data.mimetype },
|
||||
type,
|
||||
);
|
||||
}
|
||||
|
||||
@Get()
|
||||
@ApiOperation({ summary: 'Get my media' })
|
||||
getMyMedia(@CurrentUser('id') userId: string) {
|
||||
return this.mediaService.getByUserId(userId);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@ApiOperation({ summary: 'Delete media' })
|
||||
deleteMedia(@CurrentUser('id') userId: string, @Param('id') id: string) {
|
||||
return this.mediaService.deleteMedia(userId, id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user