import { Controller, Get, Delete, Query, HttpCode, HttpStatus, } from '@nestjs/common'; import { ApiTags, ApiOperation, ApiQuery } from '@nestjs/swagger'; import { CloudinaryService } from './cloudinary.service'; import { FileType } from './enums/file-type.enum'; import { LogToDiscord } from 'src/shared/decorators/log-to-discord.decorator'; @ApiTags('Upload: Cloudinary Storage') @Controller('cloudinary') @LogToDiscord() export class CloudinaryController { constructor(private readonly cloudinaryService: CloudinaryService) {} @Get('signed-upload') @ApiOperation({ summary: 'Get signed upload parameters' }) @ApiQuery({ name: 'type', enum: FileType, required: false }) @ApiQuery({ name: 'publicId', required: false }) getSignedUploadParams( @Query('type') type?: FileType, @Query('publicId') publicId?: string, ) { return this.cloudinaryService.getSignedUploadParams(type, publicId); } @Get('by-url') @ApiOperation({ summary: 'Get file details by URL' }) async getFileByUrl(@Query('url') url: string) { return this.cloudinaryService.getFileDetailsByUrl(url); } @Delete('by-url') @HttpCode(HttpStatus.OK) @ApiOperation({ summary: 'Delete file by URL' }) async deleteFileByUrl(@Query('url') url: string) { const result = await this.cloudinaryService.deleteFileByUrl(url); return { message: 'File deleted successfully', ...result, }; } }