@@ -2,6 +2,8 @@ import { Injectable, NestInterceptor, ExecutionContext, CallHandler } from '@nes
22import { Observable } from 'rxjs' ;
33import { map } from 'rxjs/operators' ;
44import { MinioService } from '../minio.service' ;
5+ import { Socket } from 'net' ;
6+ import { IncomingMessage , ServerResponse } from 'http' ;
57
68@Injectable ( )
79export class FileUrlTransformInterceptor implements NestInterceptor {
@@ -26,9 +28,24 @@ export class FileUrlTransformInterceptor implements NestInterceptor {
2628 private async transformUrls ( data : any ) : Promise < any > {
2729 if ( ! data ) return data ;
2830
31+ // Skip processing for Node.js internal objects (HTTP, Socket, etc.)
32+ if (
33+ data instanceof Socket ||
34+ data instanceof IncomingMessage ||
35+ data instanceof ServerResponse ||
36+ data . constructor ?. name === 'HTTPParser'
37+ ) {
38+ return data ;
39+ }
40+
2941 // If it's a mongoose document, convert to plain object
3042 const obj = data . toJSON ? data . toJSON ( ) : data ;
3143
44+ // Skip processing non-object data
45+ if ( typeof obj !== 'object' || obj === null ) {
46+ return obj ;
47+ }
48+
3249 // Get the schema if it's a Mongoose document
3350 const schema = data . schema || ( data . constructor && data . constructor . schema ) ;
3451
@@ -47,14 +64,21 @@ export class FileUrlTransformInterceptor implements NestInterceptor {
4764 }
4865 }
4966 }
50- // Handle nested objects recursively
51- else if ( value && typeof value === 'object' && ! Array . isArray ( value ) ) {
67+ // Handle nested objects recursively, but only if they're plain objects
68+ else if (
69+ value &&
70+ typeof value === 'object' &&
71+ ! Array . isArray ( value ) &&
72+ Object . getPrototypeOf ( value ) === Object . prototype
73+ ) {
5274 obj [ key ] = await this . transformUrls ( value ) ;
5375 }
5476 // Handle arrays of objects recursively
5577 else if ( Array . isArray ( value ) ) {
5678 obj [ key ] = await Promise . all (
57- value . map ( ( item ) => ( typeof item === 'object' ? this . transformUrls ( item ) : item ) ) ,
79+ value . map ( ( item ) =>
80+ typeof item === 'object' && item !== null ? this . transformUrls ( item ) : item ,
81+ ) ,
5882 ) ;
5983 }
6084 }
0 commit comments