import { Controller, Post, UseInterceptors, UploadedFile, Body, Param, Get, } from '@nestjs/common'; import { FileInterceptor } from '@nestjs/platform-express'; import { UploadService } from './upload.service'; import { ChunkDto } from '@nice/common'; @Controller('upload') export class UploadController { constructor(private readonly uploadService: UploadService) { } @Post('chunk') @UseInterceptors(FileInterceptor('file')) async uploadChunk( @Body('chunk') chunkString: string, // 改为接收字符串 @UploadedFile() file: Express.Multer.File, @Body('clientId') clientId: string ) { const chunk = JSON.parse(chunkString); // 解析字符串为对象 await this.uploadService.uploadChunk(chunk, file, clientId); return { message: 'Chunk uploaded successfully' }; } @Get('status/:identifier') checkUploadStatusInfo(@Param('identifier') identifier: string) { const status = this.uploadService.checkUploadStatusInfo(identifier); return status || { message: 'No upload status found' }; } @Post('pause/:identifier') pauseUpload( @Param('identifier') identifier: string, @Body('clientId') clientId: string ) { this.uploadService.pauseUpload(identifier, clientId); return { message: 'Upload paused successfully' }; } @Post('resume/:identifier') async resumeUpload( @Param('identifier') identifier: string, @Body('clientId') clientId: string ) { const resumed = this.uploadService.resumeUpload(identifier, clientId); if (!resumed) { throw new Error('Unable to resume upload'); } return { message: 'Upload resumed successfully' }; } }