Spaces:
Runtime error
Runtime error
| import { | |
| Controller, | |
| Post, | |
| Delete, | |
| Get, | |
| Query, | |
| Body, | |
| UseInterceptors, | |
| UploadedFile, | |
| HttpCode, | |
| HttpStatus, | |
| } from '@nestjs/common'; | |
| import { FileInterceptor } from '@nestjs/platform-express'; | |
| import { | |
| ApiTags, | |
| ApiOperation, | |
| ApiConsumes, | |
| ApiQuery, | |
| ApiBody, | |
| } from '@nestjs/swagger'; | |
| import { DropboxStorageService } from './dropbox-storage.service'; | |
| import { FileType } from './enums/file-type.enum'; | |
| import { LogToDiscord } from 'src/shared/decorators/log-to-discord.decorator'; | |
| ('Dropbox Storage') | |
| ('dropbox') | |
| () | |
| export class DropboxStorageController { | |
| constructor(private readonly dropboxStorageService: DropboxStorageService) {} | |
| ('upload') | |
| ({ summary: 'Upload file to Dropbox' }) | |
| ('multipart/form-data') | |
| ({ name: 'fileType', enum: FileType, required: false }) | |
| ({ | |
| name: 'customFilename', | |
| required: false, | |
| description: 'Custom filename (optional)', | |
| }) | |
| ({ | |
| schema: { | |
| type: 'object', | |
| properties: { | |
| file: { | |
| type: 'string', | |
| format: 'binary', | |
| }, | |
| }, | |
| }, | |
| }) | |
| (FileInterceptor('file')) | |
| async uploadFile( | |
| () file: any, | |
| ('fileType') fileType?: FileType, | |
| ('customFilename') customFilename?: string, | |
| ) { | |
| return this.dropboxStorageService.uploadFile({ | |
| fileBuffer: file.buffer, | |
| filename: file.originalname, | |
| fileType: fileType || 'IMAGE', | |
| customFilename: customFilename, | |
| }); | |
| } | |
| ('file-info') | |
| ({ summary: 'Get file info and shareable link by path' }) | |
| ({ name: 'path', required: true }) | |
| async getFileInfo(('path') path: string) { | |
| return this.dropboxStorageService.getFileInfo(path); | |
| } | |
| ('list') | |
| ({ summary: 'List files in folder' }) | |
| ({ name: 'folderPath', required: false }) | |
| async listFiles(('folderPath') folderPath?: string) { | |
| return this.dropboxStorageService.listFiles(folderPath); | |
| } | |
| ('by-path') | |
| (HttpStatus.OK) | |
| ({ summary: 'Delete file by Dropbox path' }) | |
| async deleteFileByPath(('path') path: string) { | |
| const result = await this.dropboxStorageService.deleteFile(path); | |
| return { | |
| message: 'File deleted successfully', | |
| ...result, | |
| }; | |
| } | |
| ('by-url') | |
| (HttpStatus.OK) | |
| ({ summary: 'Delete file by public URL' }) | |
| async deleteFileByUrl(('url') url: string) { | |
| const result = await this.dropboxStorageService.deleteFileByUrl(url); | |
| return { | |
| message: 'File deleted successfully', | |
| ...result, | |
| }; | |
| } | |
| } | |