File size: 1,428 Bytes
606bfb2
 
 
 
 
 
 
 
 
 
 
d201b18
606bfb2
1d6d4ff
606bfb2
d201b18
606bfb2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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,
    };
  }
}