@@ -2,6 +2,7 @@ const { AttachmentProcessor } = require('@elastic.io/component-commons-library')
22const { messages } = require ( 'elasticio-node' ) ;
33const xml2js = require ( 'xml2js' ) ;
44const _ = require ( 'lodash' ) ;
5+ const { getUserAgent } = require ( '../utils' ) ;
56
67const MB_TO_BYTES = 1024 * 1024 ;
78const MAX_FILE_SIZE = process . env . MAX_FILE_SIZE * MB_TO_BYTES || 10 * MB_TO_BYTES ;
@@ -33,7 +34,8 @@ module.exports.process = async function process(msg, cfg) {
3334 throw new Error ( 'Input must be an object with exactly one key.' ) ;
3435 }
3536
36- const xmlString = builder . buildObject ( input ) ;
37+ const xml2String = ( ) => builder . buildObject ( input ) ;
38+ const xmlString = xml2String ( ) ;
3739
3840 if ( ! uploadToAttachment ) {
3941 this . logger . info ( 'Sending XML data in message.' ) ;
@@ -49,10 +51,9 @@ module.exports.process = async function process(msg, cfg) {
4951 }
5052 this . logger . info ( `Will create XML attachment of size ${ attachmentSize } byte(s)` ) ;
5153
52- const attachmentProcessor = new AttachmentProcessor ( ) ;
53- const uploadResult = await attachmentProcessor . uploadAttachment ( xmlString , 'stream' ) ;
54- const attachmentId = uploadResult . data . objectId ;
55- const attachmentUrl = `${ uploadResult . config . url } ${ attachmentId } ?storage_type=maester` ;
54+ const attachmentProcessor = new AttachmentProcessor ( getUserAgent ( ) , msg . id ) ;
55+ const createdAttachmentId = await attachmentProcessor . uploadAttachment ( xml2String ) ;
56+ const attachmentUrl = attachmentProcessor . getMaesterAttachmentUrlById ( createdAttachmentId ) ;
5657 this . logger . info ( 'Attachment created successfully' ) ;
5758
5859 const outboundMessage = messages . newEmptyMessage ( ) ;
0 commit comments