@@ -11,6 +11,10 @@ import nodeFs from 'fs';
1111import { BacktraceConfiguration , BacktraceSetupConfiguration } from './BacktraceConfiguration.js' ;
1212import { BacktraceNodeRequestHandler } from './BacktraceNodeRequestHandler.js' ;
1313import { AGENT } from './agentDefinition.js' ;
14+ import {
15+ BacktraceFileAttachmentFactory ,
16+ NodeFsBacktraceFileAttachmentFactory ,
17+ } from './attachment/BacktraceFileAttachment.js' ;
1418import { FileAttachmentsManager } from './attachment/FileAttachmentsManager.js' ;
1519import { transformAttachment } from './attachment/transformAttachments.js' ;
1620import { FileBreadcrumbsStorage } from './breadcrumbs/FileBreadcrumbsStorage.js' ;
@@ -37,6 +41,7 @@ export class BacktraceClient extends BacktraceCoreClient<BacktraceConfiguration>
3741 private _listeners : Record < string , NodeJS . UnhandledRejectionListener | NodeJS . UncaughtExceptionListener > = { } ;
3842
3943 protected readonly storageFactory : BacktraceStorageModuleFactory ;
44+ protected readonly fileAttachmentFactory : BacktraceFileAttachmentFactory ;
4045 protected readonly fs : typeof nodeFs ;
4146
4247 protected get databaseNodeFsStorage ( ) {
@@ -46,6 +51,7 @@ export class BacktraceClient extends BacktraceCoreClient<BacktraceConfiguration>
4651 constructor ( clientSetup : BacktraceNodeClientSetup ) {
4752 const storageFactory = clientSetup . storageFactory ?? new NodeFsBacktraceStorageModuleFactory ( ) ;
4853 const fs = clientSetup . fs ?? nodeFs ;
54+ const fileAttachmentFactory = new NodeFsBacktraceFileAttachmentFactory ( fs ) ;
4955 const storage =
5056 clientSetup . database ?. storage ??
5157 ( clientSetup . options . database ?. enable
@@ -72,30 +78,33 @@ export class BacktraceClient extends BacktraceCoreClient<BacktraceConfiguration>
7278 ...clientSetup . database ?. recordSenders ?.( submission ) ,
7379 } ) ,
7480 recordSerializers : {
75- report : new ReportBacktraceDatabaseRecordWithAttachmentsSerializer ( storage ) ,
76- attachment : new AttachmentBacktraceDatabaseRecordSerializer ( fs ) ,
81+ report : new ReportBacktraceDatabaseRecordWithAttachmentsSerializer ( fileAttachmentFactory ) ,
82+ attachment : new AttachmentBacktraceDatabaseRecordSerializer ( fileAttachmentFactory ) ,
7783 ...clientSetup . database ?. recordSerializers ,
7884 } ,
7985 }
8086 : undefined ,
8187 ...clientSetup ,
8288 options : {
8389 ...clientSetup . options ,
84- attachments : clientSetup . options . attachments ?. map ( transformAttachment ) ,
90+ attachments : clientSetup . options . attachments ?. map ( transformAttachment ( fileAttachmentFactory ) ) ,
8591 } ,
8692 } ) ;
8793
8894 this . storageFactory = storageFactory ;
95+ this . fileAttachmentFactory = fileAttachmentFactory ;
8996 this . fs = fs ;
9097
9198 const breadcrumbsManager = this . modules . get ( BreadcrumbsManager ) ;
9299 if ( breadcrumbsManager && this . sessionFiles && storage ) {
93- breadcrumbsManager . setStorage ( FileBreadcrumbsStorage . factory ( this . sessionFiles , storage ) ) ;
100+ breadcrumbsManager . setStorage (
101+ FileBreadcrumbsStorage . factory ( this . sessionFiles , storage , this . fileAttachmentFactory ) ,
102+ ) ;
94103 }
95104
96105 if ( this . sessionFiles && storage && clientSetup . options . database ?. captureNativeCrashes ) {
97106 this . addModule ( FileAttributeManager , FileAttributeManager . create ( storage ) ) ;
98- this . addModule ( FileAttachmentsManager , FileAttachmentsManager . create ( storage ) ) ;
107+ this . addModule ( FileAttachmentsManager , FileAttachmentsManager . create ( storage , fileAttachmentFactory ) ) ;
99108 }
100109 }
101110
@@ -346,12 +355,18 @@ export class BacktraceClient extends BacktraceCoreClient<BacktraceConfiguration>
346355 for ( const [ recordName , report , session ] of reports ) {
347356 try {
348357 if ( session ) {
349- report . attachments . push ( ...FileBreadcrumbsStorage . getSessionAttachments ( session , storage ) ) ;
358+ report . attachments . push (
359+ ...FileBreadcrumbsStorage . getSessionAttachments ( session , this . fileAttachmentFactory ) ,
360+ ) ;
350361
351362 const fileAttributes = FileAttributeManager . createFromSession ( session , storage ) ;
352363 Object . assign ( report . attributes , await fileAttributes . get ( ) ) ;
353364
354- const fileAttachments = FileAttachmentsManager . createFromSession ( session , storage ) ;
365+ const fileAttachments = FileAttachmentsManager . createFromSession (
366+ session ,
367+ storage ,
368+ this . fileAttachmentFactory ,
369+ ) ;
355370 report . attachments . push ( ...( await fileAttachments . get ( ) ) ) ;
356371
357372 report . attributes [ 'application.session' ] = session . sessionId ;
0 commit comments