File size: 1,330 Bytes
9f0826d
 
 
 
 
 
 
 
3b3ab98
9f0826d
 
d201b18
9f0826d
1d6d4ff
9f0826d
d201b18
9f0826d
 
 
3b3ab98
 
 
 
9f0826d
 
 
3b3ab98
 
 
9f0826d
 
 
 
 
3b3ab98
9f0826d
 
 
 
 
 
 
 
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
import {
  Controller,
  Get,
  Delete,
  Query,
  HttpCode,
  HttpStatus,
} from '@nestjs/common';
import { ApiTags, ApiOperation, ApiQuery } from '@nestjs/swagger';
import { ImagekitioService } from './imagekitio.service';
import { FileType } from './enums/file-type.enum';
import { LogToDiscord } from 'src/shared/decorators/log-to-discord.decorator';

@ApiTags('Upload: ImageKit.io Storage')
@Controller('imagekit')
@LogToDiscord()
export class ImagekitioController {
  constructor(private readonly imagekitioService: ImagekitioService) {}

  @Get('signed-upload')
  @ApiOperation({ summary: 'Get signed upload parameters' })
  @ApiQuery({ name: 'type', enum: FileType, required: false })
  getSignedUploadParams(@Query('type') type?: FileType) {
    return this.imagekitioService.getAuthenticationParameters(type);
  }

  @Get('by-url')
  @ApiOperation({ summary: 'Get file details by URL' })
  async getFileByUrl(@Query('url') url: string): Promise<any> {
    return this.imagekitioService.getFileIdByUrl(url);
  }

  @Delete('by-url')
  @HttpCode(HttpStatus.OK)
  @ApiOperation({ summary: 'Delete file by URL' })
  async deleteFileByUrl(@Query('url') url: string) {
    const result = await this.imagekitioService.deleteFileByUrl(url);
    return {
      message: 'File deleted successfully',
      ...result,
    };
  }
}