@@ -23,14 +23,20 @@ import {
2323 ApiParam ,
2424 ApiQuery ,
2525} from '@nestjs/swagger' ;
26+ import { UploadedFile as FileUpload } from '../common/types/file.types' ;
2627import { CdnService } from './cdn.service' ;
2728import { UploadContentDto } from './dto/upload-content.dto' ;
2829import { ContentMetadata } from './entities/content-metadata.entity' ;
29- import { FileValidationService } from '../media/validation/file-validation.service' ;
30+ import {
31+ FileValidationService ,
32+ FileValidationResult ,
33+ } from '../media/validation/file-validation.service' ;
3034import { MalwareScanningService } from '../media/validation/malware-scanning.service' ;
3135import { ImageProcessingService } from '../media/processing/image-processing.service' ;
32- import { FileValidationResult } from '../media/validation/file-validation.service' ;
33- import { ALLOWED_FILE_TYPES , FILE_SIZE_LIMITS } from '../media/validation/file-validation.constants' ;
36+ import {
37+ ALLOWED_FILE_TYPES ,
38+ FILE_SIZE_LIMITS ,
39+ } from '../media/validation/file-validation.constants' ;
3440
3541@ApiTags ( 'CDN' )
3642@Controller ( 'cdn' )
@@ -63,7 +69,7 @@ export class CdnController {
6369 @ApiResponse ( { status : 415 , description : 'Unsupported media type' } )
6470 @ApiResponse ( { status : 500 , description : 'Internal server error' } )
6571 async uploadContent (
66- @UploadedFile ( ) file : Express . Multer . File ,
72+ @UploadedFile ( ) file : FileUpload ,
6773 @Body ( ) options : UploadContentDto ,
6874 ) : Promise < ContentMetadata > {
6975 try {
@@ -76,7 +82,10 @@ export class CdnController {
7682 // Step 1: Validate file
7783 const validationResult = await this . fileValidation . validateFile ( file ) ;
7884 if ( ! validationResult . valid ) {
79- this . logger . warn ( `File validation failed for ${ file . originalname } :` , validationResult . errors ) ;
85+ this . logger . warn (
86+ `File validation failed for ${ file . originalname } :` ,
87+ validationResult . errors ,
88+ ) ;
8089 throw new BadRequestException ( {
8190 message : 'File validation failed' ,
8291 errors : validationResult . errors ,
@@ -92,9 +101,10 @@ export class CdnController {
92101 const scanResult = await this . malwareScanning . scanFile ( file ) ;
93102
94103 if ( ! scanResult . clean ) {
95- const errorMsg = scanResult . threats . length > 0
96- ? `Malware detected: ${ scanResult . threats . join ( ', ' ) } `
97- : 'File failed security scan' ;
104+ const errorMsg =
105+ scanResult . threats . length > 0
106+ ? `Malware detected: ${ scanResult . threats . join ( ', ' ) } `
107+ : 'File failed security scan' ;
98108 this . logger . error ( `Malware detected in ${ file . originalname } :` , scanResult . threats ) ;
99109 throw new HttpException ( errorMsg , HttpStatus . FORBIDDEN ) ;
100110 }
@@ -149,9 +159,7 @@ export class CdnController {
149159 } ,
150160 } )
151161 @ApiResponse ( { status : 400 , description : 'No file provided' } )
152- async validateFile (
153- @UploadedFile ( ) file : Express . Multer . File ,
154- ) : Promise < FileValidationResult > {
162+ async validateFile ( @UploadedFile ( ) file : FileUpload ) : Promise < FileValidationResult > {
155163 if ( ! file ) {
156164 throw new BadRequestException ( 'No file provided' ) ;
157165 }
@@ -180,7 +188,7 @@ export class CdnController {
180188 } )
181189 @ApiResponse ( { status : 400 , description : 'No file provided' } )
182190 @ApiResponse ( { status : 503 , description : 'Scanning service not available' } )
183- async scanFile ( @UploadedFile ( ) file : Express . Multer . File ) {
191+ async scanFile ( @UploadedFile ( ) file : FileUpload ) {
184192 if ( ! file ) {
185193 throw new BadRequestException ( 'No file provided' ) ;
186194 }
@@ -251,7 +259,7 @@ export class CdnController {
251259 } ,
252260 } )
253261 @ApiResponse ( { status : 400 , description : 'Invalid file or not an image' } )
254- async compressPreview ( @UploadedFile ( ) file : Express . Multer . File ) {
262+ async compressPreview ( @UploadedFile ( ) file : FileUpload ) {
255263 if ( ! file ) {
256264 throw new BadRequestException ( 'No file provided' ) ;
257265 }
@@ -403,6 +411,6 @@ export class CdnController {
403411 const k = 1024 ;
404412 const sizes = [ 'Bytes' , 'KB' , 'MB' , 'GB' ] ;
405413 const i = Math . floor ( Math . log ( bytes ) / Math . log ( k ) ) ;
406- return parseFloat ( ( bytes / Math . pow ( k , i ) ) . toFixed ( 2 ) ) + ' ' + sizes [ i ] ;
414+ return ` ${ parseFloat ( ( bytes / Math . pow ( k , i ) ) . toFixed ( 2 ) ) } ${ sizes [ i ] } ` ;
407415 }
408416}
0 commit comments