File size: 1,512 Bytes
806651d
 
 
 
 
 
 
 
 
 
 
d201b18
806651d
1d6d4ff
806651d
d201b18
806651d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
49
50
51
52
import {
  Controller,
  Get,
  Delete,
  Query,
  HttpCode,
  HttpStatus,
} from '@nestjs/common';
import { ApiTags, ApiOperation, ApiQuery } from '@nestjs/swagger';
import { FilestackService } from './filestack.service';
import { FileType } from './enums/file-type.enum';
import { LogToDiscord } from 'src/shared/decorators/log-to-discord.decorator';

@ApiTags('Upload: Filestack Storage')
@Controller('filestack')
@LogToDiscord()
export class FilestackController {
  constructor(private readonly filestackService: FilestackService) {}

  @Get('upload-params')
  @ApiOperation({ summary: 'Get upload parameters with optional filename' })
  @ApiQuery({ name: 'type', enum: FileType, required: false })
  @ApiQuery({
    name: 'filename',
    required: false,
    description: 'Custom filename for the upload',
  })
  getUploadParams(
    @Query('type') type?: FileType,
    @Query('filename') filename?: string,
  ) {
    return this.filestackService.getUploadParams(type, filename);
  }

  @Get('by-handle')
  @ApiOperation({ summary: 'Get file details by handle' })
  async getFileByHandle(@Query('handle') handle: string): Promise<any> {
    return this.filestackService.getFileByHandle(handle);
  }

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