upd
This commit is contained in:
@@ -1,13 +1,4 @@
|
||||
import {
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
Param,
|
||||
Post,
|
||||
Query,
|
||||
Req,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
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';
|
||||
@@ -17,39 +8,42 @@ import { MediaService } from './media.service';
|
||||
@ApiTags('media')
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Controller('media')
|
||||
@Controller('profiles/:profileId/media')
|
||||
export class MediaController {
|
||||
constructor(private readonly mediaService: MediaService) {}
|
||||
|
||||
@Post('upload')
|
||||
@ApiOperation({ summary: 'Upload photo or video' })
|
||||
@ApiOperation({ summary: 'Upload photo / video / audio to profile' })
|
||||
@ApiConsumes('multipart/form-data')
|
||||
async upload(
|
||||
@CurrentUser('id') userId: string,
|
||||
@Param('profileId') profileId: string,
|
||||
@Req() req: FastifyRequest,
|
||||
@Query('type') type: 'photo' | 'video' = 'photo',
|
||||
@Query('type') type: 'photo' | 'video' | 'audio' = 'photo',
|
||||
) {
|
||||
const data = await (req as any).file();
|
||||
if (!data) {
|
||||
throw new Error('No file provided');
|
||||
}
|
||||
if (!data) throw new Error('No file provided');
|
||||
const buffer = await data.toBuffer();
|
||||
return this.mediaService.uploadMedia(
|
||||
return this.mediaService.upload(
|
||||
userId,
|
||||
profileId,
|
||||
{ buffer, originalname: data.filename, mimetype: data.mimetype },
|
||||
type,
|
||||
);
|
||||
}
|
||||
|
||||
@Get()
|
||||
@ApiOperation({ summary: 'Get my media' })
|
||||
getMyMedia(@CurrentUser('id') userId: string) {
|
||||
return this.mediaService.getByUserId(userId);
|
||||
@ApiOperation({ summary: 'Get all media for a profile' })
|
||||
getMedia(@Param('profileId') profileId: string) {
|
||||
return this.mediaService.getByProfileId(profileId);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@ApiOperation({ summary: 'Delete media' })
|
||||
deleteMedia(@CurrentUser('id') userId: string, @Param('id') id: string) {
|
||||
return this.mediaService.deleteMedia(userId, id);
|
||||
@Delete(':mediaId')
|
||||
@ApiOperation({ summary: 'Delete media item' })
|
||||
deleteMedia(
|
||||
@CurrentUser('id') userId: string,
|
||||
@Param('mediaId') mediaId: string,
|
||||
) {
|
||||
return this.mediaService.delete(userId, mediaId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user